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");
|
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");
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,221
|
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).
|