We receive PDFs (mostly medical records) from multiple sources and put them through a PDF printing process in an effort to set all page sizes to letter and align pages vertically. We use the code snippet below and it works well the majority of the time, but occasionally we get PDFs where the zoom setting on some of the pages is scaled down because the original page was scanned in at a horizontal orientation. For example, using the code below, the value of scale is typically 1 for a page that was scanned in with a portrait orientation. However, the value of scale for a page that was scanned in horizontally is .77, which shrinks the page contents to the lower left corner of the page. I have examples I can send.
Is there a way to set all page orientations the same so the zoom value does not shrink the page contents?
Code:
using (var existingPdf = new Document(fullSourcePath))
{
using (var pEdit = new PdfPageEditor(existingPdf))
{
for (int i = 1; i <= existingPdf.Pages.Count; i++)
{
var page = existingPdf.Pages[i];
var pageWidth = (float)page.Rect.Width;
var pageHeight = (float)page.Rect.Height;
var pageLetter = Aspose.Pdf.PageSize.PageLetter;
if (pageWidth == pageLetter.Width && pageHeight == pageLetter.Height)
continue;
var wScale = pageLetter.Width / pageWidth;
var hScale = pageLetter.Height / pageHeight;
var scale = new[] { 1f, wScale, hScale }.Min();
pEdit.ProcessPages = new[] { i };
pEdit.PageSize = Aspose.Pdf.PageSize.PageLetter;
pEdit.VerticalAlignmentType = VerticalAlignment.Top;
pEdit.HorizontalAlignment = HorizontalAlignment.Left;
pEdit.Zoom = scale;
pEdit.ApplyChanges();
}
pEdit.Save(fullDestinationPath);
return true;
}
}