PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Dec 04, 2021 4:17 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri Nov 05, 2021 1:27 am 
Offline

Joined: Fri Nov 05, 2021 1:14 am
Posts: 1
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?


Top
 Profile  
Reply with quote  
PostPosted: Fri Nov 05, 2021 10:42 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 683
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 21 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