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

Split large single page pdf into A4 size pages
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2874
Page 1 of 1

Author:  thepo [ Mon Jul 28, 2014 12:55 pm ]
Post subject:  Split large single page pdf into A4 size pages

Hi there

I have a pdf that is generated from visio.
It stretches several A4 pages widths to the right and down.
The document when opened in pdf viewer shows a single page.

I am looking for a way to import the pdf in PDFSharp and MigraDoc and then render the result with page breaks in A4 size, thus breaking the single doc into several A4 pages.

1. Can this be done?
2. Any example code?

I have tried but failed to achieve this so any help would be greatly appreciated.

Thank you
Theo

Author:  thepo [ Mon Aug 04, 2014 4:41 am ]
Post subject:  Re: Split large single page pdf into A4 size pages

Anyone?

Any leads or suggestions?

Thank you

Author:  Thomas Hoevel [ Mon Aug 04, 2014 8:41 am ]
Post subject:  Re: Split large single page pdf into A4 size pages

You can draw PDF pages larger than A4 on PDF pages of A4 size (or Letter or whatever). Do this in a loop and change the Top and Left position.

AFAIK PDFsharp does not currently support clipping. Draw white rectangles to simulate a white border (if needed).

The original single page PDF will be included only once in the new PDF file, so filesize should not grow excessively.

Author:  thepo [ Mon Aug 04, 2014 9:06 am ]
Post subject:  Re: Split large single page pdf into A4 size pages

Thank you for the response Thomas

What I am trying to achieve is so that when the document is opened in PDF viewer (or similar) it actually only shows a standard A4 page and you have x-y pages that you can navigate over.

Would it be possible to "create" pages from the src file so that it can be merged into a single file in another step? (i.e. export A4 page sizes and merge later)
Do you have a code snippet on how to import an existing PDF into MigraDoc?

Thank you
Theo

Author:  Thomas Hoevel [ Wed Aug 06, 2014 9:52 am ]
Post subject:  Re: Split large single page pdf into A4 size pages

Sounds like a job for PDFsharp, not MigraDoc.

I'd create one document with x-y pages in a single task. Creating individual A4 pages and merging them later will probably lead to a much bigger file.

Look at this sample:
http://www.pdfsharp.net/wiki/CombineDoc ... ample.ashx

You basically need these lines from variant 2:
Code:
// Get a graphics object for page1
gfx = XGraphics.FromPdfPage(page1);

// Set page number (which is one-based)
form1.PageNumber = idx + 1;

// Draw the page identified by the page number like an image
gfx.DrawImage(form1, new XRect(0, 0, form1.PointWidth, form1.PointHeight));
But your XRect will start at (0,0) only for the first page - at least one of the values will be negative for consecutive pages.

This way you will draw a big image onto a small page, so each page will show you a DIN A4 "viewport" of the big image.

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