We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Rotate pages in an existing PDF

How do I rotate a page in an existing PDF without having to recreate the PDF? I would just like to load it using PdfLoadedDocument, rotate and page and resave the document.
Thanks,
Karlie

3 Replies

SR Sundaram R Syncfusion Team May 4, 2010 07:18 AM UTC

Hi Karlie,

Thanks for using Syncfusion products.

Syncfusion.PDF.base assembly’s Type PdfLoadedDocument does not have any Page Rotation related properties.

However, there exist a workaround for your rotate feature, which is as follows, Please find whether this is helpful for your need,

Load the PDF file into object of type PdfLoadedDocument and then create an object of type PdfDocument from it. Here, every PdfPage in the PdfPages collection of PdfDocument resides with in the object of type PdfSection.
Here in type PdfSection, the PdfPages collection within them can be subjected for rotation, with its PageSettings property. The file with the changes can be saved back to the same location.

Please find the code snippet for your help,


//The File location
public const string saveUrl = "E:/Resources/Sample.pdf";

//The Page number, which has to be rotated
public const int pageNumber = 10;

//Load the existing PDF document from the drive
PdfLoadedDocument loadedPdf = new PdfLoadedDocument(openUrl);

//Convert PdfLoadedDocument to PdfDocument object
PdfDocument pdfDoc = PdfDocument.Merge(null, loadedPdf) as PdfDocument;

//Apply necessary rotation operation to required page(s).
pdfDoc.Sections[pageNumber].PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90;

//Resave the document
pdfDoc.Save(openUrl);

If you have any further queries, please contact us.

Thanks,
Sundaram R.


ER Eric Rosenblum replied to Sundaram R March 20, 2015 10:52 PM UTC

Hi Karlie,

Thanks for using Syncfusion products.

Syncfusion.PDF.base assembly’s Type PdfLoadedDocument does not have any Page Rotation related properties.

However, there exist a workaround for your rotate feature, which is as follows, Please find whether this is helpful for your need,

Load the PDF file into object of type PdfLoadedDocument and then create an object of type PdfDocument from it. Here, every PdfPage in the PdfPages collection of PdfDocument resides with in the object of type PdfSection.
Here in type PdfSection, the PdfPages collection within them can be subjected for rotation, with its PageSettings property. The file with the changes can be saved back to the same location.

Please find the code snippet for your help,


//The File location
public const string saveUrl = "E:/Resources/Sample.pdf";

//The Page number, which has to be rotated
public const int pageNumber = 10;

//Load the existing PDF document from the drive
PdfLoadedDocument loadedPdf = new PdfLoadedDocument(openUrl);

//Convert PdfLoadedDocument to PdfDocument object
PdfDocument pdfDoc = PdfDocument.Merge(null, loadedPdf) as PdfDocument;

//Apply necessary rotation operation to required page(s).
pdfDoc.Sections[pageNumber].PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90;

//Resave the document
pdfDoc.Save(openUrl);

If you have any further queries, please contact us.

Thanks,
Sundaram R.

PdfDocument pdfDoc = PdfDocument.Merge(null, loadedPdf) as PdfDocument;

System.ArgumentNullException: Value cannot be null.
Parameter name: key




KK Karthik Krishnaraj Syncfusion Team March 23, 2015 08:31 AM UTC

Hi Karlie,

Thank you for your patience,

I am afraid that I couldn’t able to reproduce the issue, I have attached a simple sample and the output pdf file in the below link. Can you please check with this and let me know your current product version, this will help us to find the actual root cause for the issue.

Sample Link:

http://www.syncfusion.com/downloads/support/directtrac/135426/WindowsFormsApplication19551566329.zip

Output File:

http://www.syncfusion.com/downloads/support/directtrac/135426/Output1714935674.zip

Thanks,

Karthik.


Loader.
Live Chat Icon For mobile
Up arrow icon