Issue:
When using Aspose.Pdf.Facades.PdfPageEditor to modify certain PDF files the output is a blank page.
Observations:
1. The code works on most PDF files (100+ tested)
2. If you take a file that it does not work on and follow these steps it will work.
a. Open the source document in Adobe Acrobat Pro DC
b. Select 'Edit PDF'
note: At this point Adobe seems to do OCR on the image contained on the PDF
c. Select 'Add Text' and insert some text.
d. Save (as)
3. Process this file in the same way and it will work (can zoom, change page size , etc.)
4. There is no security on the document
5. Simply saving as another document did not work.
6. The output files that were blank were still rather large in file size (similar to the original)
7. The simple fact of loading the subject PDFs in the PdfPageEditor will cause them to output blank.
Thank you for your help in this matter.
Jason Summers
Sample of code used
public void resize()
{
var parent = Directory.GetParent(Directory.GetCurrentDirectory()).Parent;
var directoryInfo = parent.Parent;
string inFile = directoryInfo.FullName + "\\Documents\\Test Files\\TestScale7.pdf";
string outFile = directoryInfo.FullName + "\\Documents\\Test Files\\TestScale_out7.pdf";
Document pdfDocument = new Document(inFile);
Page page = pdfDocument.Pages[1];
Debug.WriteLine(page.Rotate);
Debug.WriteLine("PageInfo Width:" + page.Rect.Width);
Debug.WriteLine("PageInfo Height:" + page.Rect.Height);
float originalPageWidth = (float)page.Rect.Width;
float originalPageHeight = (float)page.Rect.Height;
float newPageWidth;
float newPageHeight;
if (page.Rotate == Rotation.on90 || page.Rotate == Rotation.on90)
{
switch (originalPageWidth > originalPageHeight)
{
case true:
{
newPageWidth = PageSize.A4.Width;
newPageHeight = PageSize.A4.Height;
break;
}
default:
{
newPageWidth = PageSize.A4.Height;
newPageHeight = PageSize.A4.Width;
break;
}
}
}
else
{
switch (originalPageWidth > originalPageHeight)
{
case true:
{
newPageWidth = PageSize.A4.Height;
newPageHeight = PageSize.A4.Width;
break;
}
default:
{
newPageWidth = PageSize.A4.Width;
newPageHeight = PageSize.A4.Height;
break;
}
}
}
float zoom = Math.Min(newPageHeight / originalPageHeight,newPageWidth / originalPageWidth);
PdfPageEditor pdfEditor = new Aspose.Pdf.Facades.PdfPageEditor();
pdfEditor.BindPdf(inFile);
pdfEditor.ProcessPages = new int[] { 1 };
pdfEditor.Zoom = zoom;
pdfEditor.ApplyChanges();
pdfEditor.Save(outFile);
}