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

Concatenate two (or more) PDF files - and modify pages...
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1448
Page 1 of 1

Author:  psycik [ Mon Nov 29, 2010 8:30 pm ]
Post subject:  Concatenate two (or more) PDF files - and modify pages...

Hi, looking through this thread I saw how to add text to a PDF page.
viewtopic.php?f=2&t=373

I'm also opening up a number of PDF files and adding them to a single output PDF file (joining multiple PDF files together essentially). What I've found is the i have to open the input pdf file in PdfDocumentOpenMode.Import mode to add it to the output document, save it, then reopen the output document in PdfDocumentOpenMode.Modify to modify the pages to add text (a watermark) to the output pages.

This results in the double the IO to save the PDF file both times.

Is there was way i can import the page, and update date it in one operation?

Regards.

Author:  Thomas Hoevel [ Tue Nov 30, 2010 10:38 am ]
Post subject:  Re: Concatenate two (or more) PDF files - and modify pages...

Where's the problem?

You create a new file, add a page from the imported file, and draw the watermark on the new page.
Then save the new file.

There's no double IO involved.

Look at variants 3 and 4 from the Concatenate Documents Sample.

Author:  psycik [ Tue Nov 30, 2010 6:04 pm ]
Post subject:  Re: Concatenate two (or more) PDF files - and modify pages...

Ok, I see with variants 3 & 4you use a retired page reference to supposedly make a modification to it. I didn't think if that for this operation....but does lead mento something else I found yesterday:

I add the pAge to the output document, and have found that the added page does not take the orientation correctly if it has changed from the previous page.

So if page1 is portrait when added to the output document it's portrait.
Page2 is landscape, when added to the output document it is portrait also.
I had previously found this and used the return page from pages.add to set the orientation to that of the input page. Bit when trying this today i noticed that page2 (landscape one) was converted to a square page almost, 210mm x 210mm rather the 297mm width by 210mm that is normal for a landscape a4 page.
But the reported size is correct, just in display it looks incorrect and the right hand side is cut off.

Author:  psycik [ Tue Nov 30, 2010 9:21 pm ]
Post subject:  Re: Concatenate two (or more) PDF files - and modify pages...

Here's output from the page information after adding the page to the output document.

Page added to output document as read from input document
(PdfSharp.Pdf.PdfPage newPage = outputDocument.AddPage(page);)
Page 1 Orient:Portrait Width:595.276pt Height:841.89pt Size:Undefined
NewPage 1 Orient:Portrait Width:595.276pt Height:841.89pt Size:A4

Explicitly setting orientation
(newPage.Orientation = page.Orientation;)
Page 1 Orient:Portrait Width:595.276pt Height:841.89pt Size:Undefined
NewPage 1 Orient:Portrait Width:595.276pt Height:841.89pt Size:A4

Page added to output document as read from input document
(PdfSharp.Pdf.PdfPage newPage = outputDocument.AddPage(page);)
Page 3 Orient:Landscape Width:841.89pt Height:595.276pt Size:Undefined
NewPage 3 Orient:Portrait Width:595.276pt Height:841.89pt Size:A4

Explicitly setting orientation
(newPage.Orientation = page.Orientation;)
Page 3 Orient:Landscape Width:841.89pt Height:595.276pt Size:Undefined
NewPage 3 Orient:Landscape Width:841.89pt Height:595.276pt Size:A4

But there is something happening with the viewing of that third page. The dimensions are reported as correct, but on screen the right hand side is cut off.

DLL version 1.31.1789
Dot Net 2 framework.

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