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

Positioning an image over text
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4295
Page 1 of 1

Author:  viraptor [ Fri Nov 05, 2021 1:27 am ]
Post subject:  Positioning an image over text

I've got an app which finds text in a PDF document, then tries to put an image over it.
While looking for the text, I'm finding the relevant operators/matrices. For an example document, I get:

Code:
0.75 0 0 -0.75 0 841.920044 cm
1 0 0 -1 49.119999 304.799988 Tm


But I've got issues positioning the image correctly from that.
From the calculation, it looks like I should be putting the image at {36.83999925,613.320053}

But PdfSharp does the positioning differently, so I'm not sure how to translate that.
I tried to apply the scale, translate, scale and use the original Tm numbers:
Code:
gfx.ScaleTransform(0.75, -0.75);
gfx.TranslateTransform(0, 841.920044);
gfx.ScaleTransform(1, -1);
gfx.DrawImage(
  signatureImg,
  signatureLocation.Value.X, signatureLocation.Value.Y,
  90, 90 / signatureImg.PointWidth * signatureImg.PointHeight);

But that doesn't work quite the way I expected :(

How do I translate the cm/Tm numbers to DrawImage at the exact point?

Author:  TH-Soft [ Fri Nov 05, 2021 10:42 am ]
Post subject:  Re: Positioning an image over text

Already discussed here:
https://stackoverflow.com/q/69837418/162529

Not much we can do without having the PDF files.

Maybe you have to call "WorldToDefaultPage" or some other conversion method.
Code:
var pdfPosition = _gfx.Transformer.WorldToDefaultPage(destinationPosition);


With Adobe Reader you can measure the position of the text on the page and then use PDFsharp to draw at the location you measured.
Comparing the measured position from Adobe Reader with the numbers given in the PDF should allow you to determine a formula when you do it for several documents.

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