View previous topic :: View next topic |
Author |
Message |
Sai Alluru
Joined: 02 Jan 2009 Posts: 4
|
Posted: 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. |
|
Back to top |
|
|
billy anachronism
Joined: 08 Jan 2009 Posts: 8
|
Posted: 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. |
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: 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? _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
|
|