Welcome Guest Search | Active Topics | Sign In | Register

Rotate PDF Options
Tyler Miller
Posted: Saturday, January 20, 2018 5:20:14 PM
Rank: Advanced Member
Groups: Member

Joined: 1/22/2014
Posts: 38
Trying to rotate an existing PDF in 90 degree increments regardless the page size and then essentially set the page size right by switching the width/height. I am seeing a blank page despite doing the translate which should bring the content into sight. Does anyone have this working correctly or know a better way to do rotation of the existing PDF using Essential Objects? The code below just tries this on the first page of a doc and ends up blank.

Code: C#
PdfDocument document = new PdfDocument("input.pdf");
PdfMatrix matrix = new PdfMatrix();
matrix.Rotate(90);
matrix.Translate(document.Pages[0].Size.Height * 72, document.Pages[0].Size.Width * 72);
document.Pages[0].Transform(matrix);
document.Pages[0].Size = new EO.Pdf.Drawing.PdfSize(document.Pages[0].Size.Height, document.Pages[0].Size.Width);
document.Save("output.pdf");
Tyler Miller
Posted: Sunday, January 21, 2018 1:35:28 AM
Rank: Advanced Member
Groups: Member

Joined: 1/22/2014
Posts: 38
The solution was to rotate as follows (showing just counter-clockwise on the first page for demo purposes you can adapt to clockwise easily):

Code: C#
PdfDocument document = new PdfDocument(@"input.pdf");
PdfMatrix matrix = new PdfMatrix();
matrix.Rotate(90);
if (document.Pages[0].Size.Height > document.Pages[0].Size.Width)
{
     matrix.Translate(0, ( document.Pages[0].Size.Height * 72 * -1 ));
}
else
{
     matrix.Translate(0, ( document.Pages[0].Size.Height * 72 * -1));
}
document.Pages[0].Transform(matrix);
document.Pages[0].Size = new EO.Pdf.Drawing.PdfSize(document.Pages[0].Size.Height, document.Pages[0].Size.Width);
document.Save(@"output.pdf");
eo_support
Posted: Monday, January 22, 2018 12:58:52 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,071
Thanks for sharing. The key to figuring out the correct translate value is to understand the origin of the rotate is always at the bottom left corner of the page. In another word, the bottom right corner (w, 0) would become (0, -w) after the rotation. So your translate must move (0, -w) to (0, 0).


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.