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

Wrong Coordinates for new Images on existing pages
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1839
Page 1 of 1

Author:  stolle [ Wed Nov 09, 2011 6:58 am ]
Post subject:  Wrong Coordinates for new Images on existing pages

I have to modify an existing PDF Document.
First i'm importing the PDF.
Than i Draw an Image somewhere.
Last i save it again.

Code ist simple an small.

BUT: If I do this twice (Open, Modify, Write, Open, Modify, Write), the Second Image is not drawn on the right coordinates (same code as before!).
In the second run, the Image is drawn very small somewhere on the page.

I think, the first modification left some Transformation Code on the Page, witch is not terminated correctly.
Opening that doc again, PDFSharp don't know about that transformation, and fails to place the next image correctly.

My Code for drawing is like:
gfx.ScaleTransform(fak);
gfx.DrawImage(img, destRect);

These lines seems to fix the Problem:
...
gfx.Restore(state);
gfx.DrawLine(new XPen(XColors.White), new Point(-10, -10), new Point(-11, -10));
If I append them for the First run of my code, everything seems to run well.

But i'm afraid to get an PDF witch is not build from myselfe, with the same Problem.

So my question: After Importing an PDF, before extending an exisiting Page, is there any chance to append something to that page, that will
reset all aplied koordinate transformations, so that the first gfx.DrawImage will place the image where it would place it on an newly created, empty page?

Something Like ResetTransformation, but written directly to the PDF-Content?

Thanks for your help
Andreas

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