Hard rotating a PDF

Posted by: morten on 11 January 2021, 2:37 am EST

  • Posted 11 January 2021, 2:37 am EST

    Hi there,

    I was wondering if it is possible to rotate the contents of a PDF into landscape mode without using the Rotate property. The reason for this question is because we need to normalize all incoming PDFs for our applications, as sometimes landscape pdfs come in with rotation set to 90, which messes up some of our rendering steps (as they do not respect the rotation property).

    My idea was to set the Rotation property back to 0 and then 'hard' rotating all content in the pdf back to 90 degrees, so the pdf appears visually unchanged (still in landscape), but the coordinate system actually starts in the bottom left, instead of top left.
  • Replied 11 January 2021, 10:03 pm EST

    Hello Morten,

    You can go through the following demo demonstrating about how you can rotate the content of pdf.

    If this does not help, can you please share your PDF file with which you are facing the issue and also let us know your requirement in brief with the use-case so that we can assist your accordingly.

    Prabhat Sharma.
  • Replied 11 January 2021, 10:21 pm EST

    Hi Prabhat,

    Thanks for your reply. In the example you posted a transformation is applied to the GcGraphics object in order to draw transformed shapes. My question however is how I can transform existing pages and save that to a new PDF.

    I've included an example landscape pdf. What I would like to do here is set the Rotation property to 0 degrees (so it's portrait again), but then transform all pages back into landscape using some matrix. The reason for this is because processes in our pipeline do not respect the Rotation property, so we must save a new pdf where the Rotation is set to 0, but the pdf is still in landscape.

    example (1).zip
  • Replied 11 January 2021, 10:32 pm EST

    Another thing, I've noticed that when a pdf is converted to PDF/A that this also solves the problem. Alternatively, if there is a way in Documents API to convert an existing PDF to PDF/A, then that would also be great (but not by simply changing the ConformanceLevel property)
  • Replied 13 January 2021, 10:15 pm EST


    We have forwarded this issue to the developers and will let you know once we get any update on this from their end.
    [Internal Tracking ID: 2693]

    Prabhat Sharma.
  • Replied 17 January 2021, 12:13 am EST

    Hello Morten,

    You can use the Rotate property of Page class to existing pages.

    You can use it like given in code snippet below:
    doc.Pages[i].Rotate = 90; // or 180, 270 etc.

    If this does not solve your issue then please let us know.

    Prabhat Sharma.
  • Replied 17 January 2021, 6:27 pm EST

    Hi Prabhat,

    As I said in the first sentence of my post, the challenge is that I cannot achieve it using the Rotate property. I've found a solution using another library. The trick was to copy each page with Rotate set to 0, then writing it as a template XObject with an affine transformation (mimicking the original rotation) to the new pdf. Not sure if GrapeCity exposes an 'AddTemplate()' method or something analogous, but that was the solution.
  • Marked as Answer

    Replied 18 January 2021, 1:28 am EST

    Hi Morten,

    GcPdf provides FormXObject that allows to render pages of one PDF into another in any way you need, check out this sample:


  • Replied 18 January 2021, 1:33 am EST

    Hi Dmitry, that was exactly what I was looking for. Thank you!
  • Replied 18 January 2021, 7:45 am EST

    Hi Morten,

    Glad I could help, thanks for the heads up!
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels