logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
brettr  
#1 Posted : Thursday, August 11, 2016 4:01:19 PM(UTC)
Quote
brettr

Rank: Member

Groups: Registered
Joined: 8/11/2016(UTC)
Posts: 14
United States

Thanks: 1 times
I'm running the same exact code from here https://forum.patagames....t154-Add-string-in-a-pdf , minus the text part. The red image never appears.

Do you have some idea what could be wrong?

Edited by moderator Thursday, August 11, 2016 5:30:13 PM(UTC)  | Reason: Not specified

Paul Rayman  
#2 Posted : Thursday, August 11, 2016 7:36:18 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Maybe you need to call pdfViewer.ClearRenderBuffer()?
brettr  
#3 Posted : Thursday, August 11, 2016 8:44:13 PM(UTC)
Quote
brettr

Rank: Member

Groups: Registered
Joined: 8/11/2016(UTC)
Posts: 14
United States

Thanks: 1 times
I added that as the last line but still nothing. I do see e.Page.PageObjects.Count increment after my image is added to the collection.

I also added this line:

e.Page.PageObjects[0].FillColor = Color.Red;

I see one of the text objects change to red.

Any other suggestions?
Paul Rayman  
#4 Posted : Friday, August 12, 2016 3:36:09 AM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
It is difficult to say something without seeing your code. I have checked the example from the link above. Everything works perfectly.
Maybe you did not set up the transformation matrix?
Or did not subscribe to pdfViewer1.DocumentLoaded event?
Could you please create a simple msvc project with this issue and provide it to me?
brettr  
#5 Posted : Friday, August 12, 2016 9:25:03 AM(UTC)
Quote
brettr

Rank: Member

Groups: Registered
Joined: 8/11/2016(UTC)
Posts: 14
United States

Thanks: 1 times
wpf_sig.zip (848kb) downloaded 43 time(s).I've created a new WPF app. It has a pdfviewer and button on it plus the discussed code. But I can't get the project to start. When I add PdfCommon.Initialize() to the MainWindow.xaml.cs constructor, the app crashes on startup with this error:

Quote:
XamlParsedException occurred

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll

The invocation of the constructor on type 'my_project.MainWindow that matches the specified binding constraints threw an exception. Line number 4 line position 9.


Commenting out PdfCommon.Initialize() removes the error. Getting past that error is the first step then we can look at the remaining code.

Project is attached.

Edited by user Friday, August 12, 2016 9:25:41 AM(UTC)  | Reason: Not specified

Paul Rayman  
#6 Posted : Friday, August 12, 2016 6:07:28 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
Firstly you have not properly configured project.
You forgot to add the pdfium.dll files into it.
Please find detailed instructions how to configure project here: https://pdfium.patagames.com/help/

Secondly, you forgot to set the bitmap to the PdfImageObject. please look at following code

Code:

PdfBitmap bmp = new PdfBitmap(200, 100, true);
bmp.FillRect(0, 0, 200, 100, System.Drawing.Color.Red);
var img = PdfImageObject.Create(e.Page.Document);
//--------------------- you should do this--------------------------------
img.SetBitmap(bmp);
//------------------------------------------------------------------------
img.SetMatrix(1, 0, 0, 1, 0, 0);
img.Transform(bmp.Width, 0, 0, bmp.Height, 0, 0);
e.Page.PageObjects.InsertObject(img);
pdfViewer1.UpdateLayout();

Edited by user Friday, August 12, 2016 8:22:16 PM(UTC)  | Reason: Not specified

brettr  
#7 Posted : Sunday, August 14, 2016 8:27:41 AM(UTC)
Quote
brettr

Rank: Member

Groups: Registered
Joined: 8/11/2016(UTC)
Posts: 14
United States

Thanks: 1 times
Excellent! Thanks.
Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.