PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Nov 17, 2019 9:52 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Sep 04, 2019 2:23 pm 
Offline

Joined: Wed Sep 04, 2019 2:09 pm
Posts: 2
Hi guys!

I'm enjoying using PDF sharp but now I'm struggling with working with images.

On the PDF there is an Acroform field named "imgsignature". I want to get its coordinates and put an image over it.
My code works as expected except for the Y-coordinate which is always wrong (the image is higher up on the PDF than expected).

Here is the code:
Code:
PdfPage page = pdf.Pages[0];
XGraphics gfx = XGraphics.FromPdfPage(page, XPageDirection.Downwards);
PdfTextField imageField = (PdfTextField)pdf.AcroForm.Fields["imgsignature"];
var fieldRect = imageField.Elements.GetValue("/Rect") as PdfRectangle;
XRect rect = new XRect(fieldRect.X1, fieldRect.Y1, fieldRect.Width, fieldRect.Height);

gfx.DrawImage(XImage.FromFile("pdf_overlay.jpg"), rect);


I've attached an image of the result that I am currently getting.
Any advice would be appreciated!

Using PDFsharp-MigraDoc-gdi-1.51.5186-beta


Attachments:
result.JPG
result.JPG [ 22.89 KiB | Viewed 2230 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 04, 2019 3:36 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3004
Location: Cologne, Germany
Not my area of expertise.
Maybe you have to call "WorldToDefaultPage" or some other conversion method.

Code:
var pdfPosition = _gfx.Transformer.WorldToDefaultPage(destinationPosition);

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 05, 2019 6:35 am 
Offline

Joined: Wed Sep 04, 2019 2:09 pm
Posts: 2
Thomas Hoevel wrote:
Not my area of expertise.
Maybe you have to call "WorldToDefaultPage" or some other conversion method.

Code:
var pdfPosition = _gfx.Transformer.WorldToDefaultPage(destinationPosition);

I don't understand why, but that code resolves the issue for me, thanks!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group