PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Rotate PDF Page https://forum.pdfsharp.net/viewtopic.php?f=2&t=594 |
Page 1 of 1 |
Author: | Sai Alluru [ Fri Jan 02, 2009 12:18 pm ] |
Post subject: | Rotate PDF Page |
Hi, I want to know how to rotate a pdf page say by 90, 180 and 270 degrees. I tried the following code but when I rotate and transform the resulting page is blank. If not rotated the page appears in the rectangle bounding box. PdfDocument inputDocument = PdfReader.Open(filename, PdfDocumentOpenMode.Import); PdfDocument outputDocument = new PdfDocument(); for (int idx = 0; idx < inputDocument.PageCount; idx++) { PdfPage page = inputDocument.Pages[idx]; PdfDocument singlePageDocument = new PdfDocument(); singlePageDocument.AddPage(page); singlePageDocument.Save("C:\\NewTemp\\temp"+idx.ToString()+".pdf"); outputDocument.AddPage(new PdfPage()); page = outputDocument.Pages[idx]; page.Orientation = PdfSharp.PageOrientation.Landscape; XGraphics gfx = XGraphics.FromPdfPage(page); XPdfForm form = XPdfForm.FromFile("C:\\NewTemp\\temp"+idx.ToString()+".pdf"); gfx.RotateAtTransform(90, new XPoint(0, 0)); gfx.DrawImage(form,new XRect(140, 80, 50, 50 * Math.Sqrt(2))); gfx.Save(); } outputDocument.Save("C:\\NewTemp\\Rotated.pdf"); Let me know if there is a simple way to rotate a page. Thanks, Sai. |
Author: | billy anachronism [ Thu Jan 08, 2009 3:50 am ] |
Post subject: | |
Hi Sai, I just did: PdfDocument inputDocument = PdfReader.Open(filename, PdfDocumentOpenMode.Import); foreach (PdfPage page in inputDocument) { page.Rotate = 0; page.Orientation = PdfSharp.PageOrientation.Portrait; } That worked for me. However, I'm also looking to resize the page and I haven't found an easy way to do that yet. |
Author: | Thomas Hoevel [ Thu Jan 08, 2009 9:16 am ] |
Post subject: | Re: Rotate PDF Page |
Hi! Sai Alluru wrote: I tried the following code but when I rotate and transform the resulting page is blank.
The turning point is (0, 0) - I guess you rotate the whole content away from the visible part of the page (RotateAtTransform) or use co-ordinates outside the visible area (DrawImage). Try using the center of the page as turning point for the rotation. Have you checked the XForms sample? |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |