Rotate Particular Page of PDF and Save PDF File

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Viewer for .NET (v2)  /  Re: Rotate Particular Page of PDF and Save PDF File

DynamicPDF Viewer for .NET (v2) Forum

Hi,

We have a requirement to show user a PDF file in viewer and ,user can change orientation (Rotation) of particular page and after that user can save this file with updated orientation.

For this we have used PdfViewer product library as below

ceTe.DynamicPDF.Viewer.PdfViewer pdfViewer1 = new ceTe.DynamicPDF.Viewer.PdfViewer();
pdfViewer1.Open(@"D:\PDF\Abc.pdf");
            pdfViewer1.PageOrientation = ceTe.DynamicPDF.Viewer.Orientation.RotatedClockwise90d;


Queries : -

1.After this we want to save this file (Abc.pdf) in physical folder (same as source path), which API method we can use to save this file (after update)
2.Above mention code is rotating all pages of PDF file, but we want to rotate a particular page (current page in viewer) , Is there any way to do this.

Please help.
Posted by a ceTe Software moderator
Hello,

DynamicPDF Viewer for .NET can only display the PDF and it is not capable of modifying and saving the PDF. It is not possible to achieve your requirements with DynamicPDF Viewer for .NET alone.

Along with DynamicPDF Viewer for .NET you would need to use DynamicPDF Merger for .NET to rotate the PDF pages and save the modified PDF back to the source path. Here is the sample code that shows how to programmatically rotate a PDF page.

            //Loading the input PDF.
            string filepath = @"E:\Temp\DocumentA.pdf";
            byte[] pdfByteData = File.ReadAllBytes(filepath);
            PdfDocument pdf = new PdfDocument(pdfByteData);
            MergeDocument mergeDocument = new MergeDocument(pdf);
            //Access the page using index.
            Page page = mergeDocument.Pages[1];//this will access the second page.
            //Setting rotation.
            page.Rotate = 90;
            //Saving the modified PDF back to the same location.
            mergeDocument.Draw(filepath);

Evaluation edition of DynamicPDF Merger is available for download here.

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 12:37 AM.