PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon May 06, 2024 4:07 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Rotate PDF Page
PostPosted: Fri Jan 02, 2009 12:18 pm 
Offline

Joined: Fri Jan 02, 2009 12:12 pm
Posts: 4
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jan 08, 2009 3:50 am 
Offline

Joined: Thu Jan 08, 2009 1:46 am
Posts: 8
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Rotate PDF Page
PostPosted: Thu Jan 08, 2009 9:16 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3097
Location: Cologne, Germany
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 64 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group