PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Rectangle value's Y-coordiante is wrong
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4014
Page 1 of 1

Author:  3YcwA8 [ Wed Sep 04, 2019 2:23 pm ]
Post subject:  Rectangle value's Y-coordiante is wrong

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 4517 times ]

Author:  Thomas Hoevel [ Wed Sep 04, 2019 3:36 pm ]
Post subject:  Re: Rectangle value's Y-coordiante is wrong

Not my area of expertise.
Maybe you have to call "WorldToDefaultPage" or some other conversion method.

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

Author:  3YcwA8 [ Thu Sep 05, 2019 6:35 am ]
Post subject:  Re: Rectangle value's Y-coordiante is wrong

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!

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/