PDFsharp & MigraDoc Foundation http://forum.pdfsharp.com/ |
|
pdfsharp doesn't handle non-a4 page sizes correctly http://forum.pdfsharp.com/viewtopic.php?f=3&t=602 |
Page 1 of 1 |
Author: | billy anachronism [ Thu Jan 08, 2009 2:00 am ] |
Post subject: | pdfsharp doesn't handle non-a4 page sizes correctly |
Hi, has anyone noticed that pdfsharp doesn't deal very well with non-standard page sizes? I've got a pdf with strange height and width (16.54 x 11.70 in) which is in landscape. I need to add some outlines to it. When I do so (with PdfSharp) and save it, the document has been converted to portrait and subsequently almost half of the page is cut off. So, I add a routine to rotate the document to landscape before I add the outlines. PdfDocument pdf = PdfReader.Open(pdfFile, PdfDocumentOpenMode.Modify); foreach (PdfPage page in pdf.Pages) { page.Orientation = PdfSharpMod.PageOrientation.Landscape; } This yields the same result. It still is rotated to portrait, even though PdfSharp presumably knows that the contents of the page is not in portrait. |
Author: | billy anachronism [ Thu Jan 08, 2009 2:19 am ] |
Post subject: | |
I haven't fixed this issue but I managed to create the output that I wanted. The pdf was actually landscape when it should have been portrait, so I gave up trying to fit it on a landscape page and made it portrait by: page.Rotate = 0; page.Orientation = PdfSharpMod.PageOrientation.Portrait; |
Author: | billy anachronism [ Thu Jan 08, 2009 4:11 am ] |
Post subject: | |
If anyone's interested, I've worked out how to rescale the document to A4. // Open the pdf as a form XPdfForm form = XPdfForm.FromFile(pdfFile); for (int i = 1; i <= form.PageCount; i++) { // Create a new page in the new pdf PdfPage newPage = pdf.AddPage(); newPage.Size = PdfSharpMod.PageSize.A4; newPage.Rotate = 0; newPage.Orientation = PdfSharpMod.PageOrientation.Portrait; double width = newPage.Width; double height = newPage.Height; // Prepare the contents of the new page XGraphics gfx = XGraphics.FromPdfPage(newPage); // Make a new bounding box for the contents of the page XRect box = new XRect(0, 0, width, height); // Select the right page number in the current pdf form.PageNumber = i; form.Page.Rotate = 0; form.Page.Orientation = PdfSharpMod.PageOrientation.Portrait; // Add the contents of the page to the new page gfx.DrawImage(form, box); } |
Author: | ganpp [ Wed Mar 10, 2010 1:25 am ] |
Post subject: | Re: pdfsharp doesn't handle non-a4 page sizes correctly |
This is good. but I see the font size reduced. do you have any idea? |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |