Rotate a Merger.PdfPage?

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v8)  /  Re: Rotate a Merger.PdfPage?

DynamicPDF CoreSuite for .NET (v8) Forum

 Jun 07 2017 4:10 PM
How do I add a Merger.PdfPage to a TransformationGroup?
I want to rotate the Merger.PdfPage 90 degrees (transGroup.Angle = 90)

using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;
using ceTe.DynamicPDF.Merger;
using ceTe.DynamicPDF.Imaging;
using ceTe.DynamicPDF.Rasterizer;

TransformationGroup transGroup = new TransformationGroup(1, 1, 700, 800);
Merger.PdfDocument mergePdfDoc = new PdfDocument(File.ReadAllBytes(fileName));
Merger.PdfPage pp = mergePdfDoc.GetPage(1);

//transGroup.Add(pp);
//transGroup.Angle(90);
//pp.Elements.Add(transGroup);
//mergePdfDoc.Draw(fileName);

 Jun 07 2017 4:45 PM
Posted by a ceTe Software moderator
Hello,

Here is the sample code that shows how to rotate a PdfPage object and add it to a new PDF. You can use ImportedPageData to rotate and scale the PDF page and add it directly to a new page. You can use TransformationGroup if needed as shown in the commented code below.

            PdfDocument pdfDoc = new PdfDocument("documentd.pdf");

            Document document = new Document();
            document.Pages.Add(new Page(PageSize.Letter, PageOrientation.Landscape, 0));
            //document.Pages.Add(new Page(PageSize.Letter, PageOrientation.Portrait, 0));

            ImportedPageData pageData = new ImportedPageData(pdfDoc.Pages[0]);
           
            //can be scaled if needed.
            //pageData.ScaleX = 0.5f;
            //pageData.ScaleY = 0.5f;

            //set the angle
            pageData.Angle = 90;

            //add the rotated ImportedPageData directly to the page.
            document.Pages[0].Elements.Add(pageData);

            //or it can be added to TransformationGroup if needed.
            //TransformationGroup tgr = new TransformationGroup(0, 0, pageData.Height, pageData.Width);            
            //tgr.Add(pageData);
            //document.Pages[0].Elements.Add(tgr);

            document.Draw("output.pdf");

A drawback with using ImportedPageData is that it won’t retain annotations that are present on the original PDF page. If the original page has annotation that you want to retain please use the following code that lets you rotate the page as well.

            PdfDocument pdfDoc = new PdfDocument("documentd.pdf");
            MergeDocument merDoc = new MergeDocument(pdfDoc);

            Document document = new Document();
            Page importedPage = merDoc.Pages[0];
            importedPage.Rotate = 90;

            document.Pages.Add(importedPage);
          
            document.Draw("output.pdf");

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 9:20 AM.