Rotate actual pdf page without rotating the page content

Is it possible to reset pdf page rotation to 0 without changing the content?

I have a pdf file with landscape orientation but when I add some annotation with text it has vertical position. 

Is there a way to change  page rotation to 0 but keep content rotation as it.


3 Replies

JT Jeyalakshmi Thangamarippandian Syncfusion Team July 17, 2024 01:36 PM UTC

Hi Serhii,

We do not provide direct support for resetting PDF page rotation to 0 without changing the content. However, as a workaround, we can achieve this using the CreateTemplate API. We have prepared a sample and attached it for your reference. We request you to try this on your end and let us know if you need any further assistance.

Code snippet:

PdfDocument newDoc =new PdfDocument();

FileStream fileStream = new FileStream(@"../../../Input.pdf", FileMode.Open, FileAccess.Read);

PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream);

for(int i=0;i<loadedDocument.Pages.Count;i++)

{

   PdfLoadedPage loadedPage = loadedDocument.Pages[i] as PdfLoadedPage;

   PdfTemplate template= loadedPage.CreateTemplate();

  

   PdfSection pdfSection = newDoc.Sections.Add();

   pdfSection.PageSettings.Margins.All = 0;

   pdfSection.PageSettings.Size = new SizeF(loadedPage.Graphics.ClientSize);

   PdfPage newPage = pdfSection.Pages.Add();

   PdfGraphicsState state = newPage.Graphics.Save();

   if (loadedPage.Rotation == PdfPageRotateAngle.RotateAngle90)

   {

        newPage.Graphics.TranslateTransform(newPage.Graphics.ClientSize.Width, 0);

       newPage.Graphics.RotateTransform(90);

   }

  

   else if (loadedPage.Rotation == PdfPageRotateAngle.RotateAngle270)

   {

        newPage.Graphics.TranslateTransform(0, newPage.Graphics.ClientSize.Height);

        newPage.Graphics.RotateTransform(270);

   }

    newPage.Graphics.DrawPdfTemplate(template, new PointF(0, 0));

   newPage.Graphics.Restore(state);

  

}

MemoryStream ms = new MemoryStream();

newDoc.Save(ms);

File.WriteAllBytes("output.pdf", ms.ToArray());

//Close the document.

newDoc.Close(true);

loadedDocument.Close(true);

 

Sample:

https://www.syncfusion.com/downloads/support/directtrac/general/ze/F189314_F189359_Sample1203450351

Please refer to the UG documentation for further details:

Working with PDF templates | Syncfusion


Regards,

Jeyalakshmi T



SE Serhii replied to Jeyalakshmi Thangamarippandian July 17, 2024 05:26 PM UTC

That works for me, thanks!



JT Jeyalakshmi Thangamarippandian Syncfusion Team July 18, 2024 05:56 AM UTC

Hi Serhii,

We are glad to hear that the solution works, please get back to us if you need any other assistance.

Regards,

Jeyalakshmi T



Loader.
Up arrow icon