I'm using iTextSharp to merge multiple PDF files into a single Pdf. I found a code sample or two on the web as to how to accomplish this task.
They all work, with no apparent issues, as I'm able to merge multiple PDF files into a single PDF.
The issue that I do have is that I would like for all the pages to be in PORTRAIT, as some of the PDF files have pages in LANDSCAPE and I would like for them to be rotated to PORTRAIT. I do not mind that they will either be upside down or sideways, but they must all be in portrait.
Looking at the code sections in the examples listed:
page = writer.GetImportedPage(reader, i);
rotation = reader.GetPageRotation(i);
always returns the page rotation value as 0 (zero) thus the code section
if (rotation == 90 rotation == 270)
{
cb.AddTemplate(page, 0, -1f, 1f, 0, 0,
reader.GetPageSizeWithRotation(i).Height);
}
never gets executed (if that is what is supposed to do, rotating the page).
So, based on the code in the link of the 1st code sample page = writer.GetImportedPage(reader, i)
how would I go about to change the page layout of the page
from Landscape to Portrait, before I add it to the new merged PDF document with cb.AddTemplate...
?
PS. Determining whether a page is either landscape or portrait I use the following piece of code obtained from SO (adapted for the code example above):
float pageXYRatio = page.Width / page.Height;
if (XYRatio > 1f)
{
//page is landscape
}
else
{
//page is portrait
}
Any help would be appreciated.
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…