Resizing (some) PDF files result in a white page

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);

}





Hi Jason,


Thanks for contacting support.

I have tried to resize the page of a sample PDF using the code snippet which you have shared and was unable to notice any issue in the generated output. All pages in the output were fine. I have also attached the generated output for the reference.

We will really appreciate if you can share a sample input, you are facing issue with. We will test the scenario again in our environment and update you accordingly. We are sorry for the inconvenience.

Best Regards,

Hi,

I am experiencing the same problem.

I found a release note from some time back that indicates that was a bug in the past:

Setting page zoom factor disappears page contents

at this link:

Is this a re-occurrence of an old bug. Can you research and let us know your findings?

thanks.

I have attached a zip file that contains the input pdf and the resulting output after zoom.


Looking forward to an answer to this problem.

Thanks!

Hi Allen,

Thanks for contacting support and sharing file(s).

I have tried to set the zoom factor by following code snippet and the content of the file did not disappear in the output file. I have also attached the generated output for your reference.

Aspose.Pdf.Rectangle rect = pdfDocument.Pages[1].Rect;

Facades.PdfPageEditor ppe = new Facades.PdfPageEditor();

ppe.BindPdf(inFile);

ppe.Zoom = 0.5f;

ppe.PageSize = new Aspose.Pdf.PageSize((float)rect.Height, (float)rect.Width);

pdfDocument.Save(outFile);

However I have observed that setting the page zoom factor did not take any effect in the output file. For which I have logged the issue as PDFNET-42351 in our issue tracking system. We will further investigate the issue and keep you updated on the status of its resolution. Please be patient and spare us a little time.

We are sorry for the inconvenience.

Best Regards,

Thanks for that info.


What version of aspose.pdf were you using?

Allen

Hi Allen,


Thanks for your inquiry.

fosteral:
What version of aspose.pdf were you using?

I have used the latest version of the Aspose.Pdf which is 17.2.0.0 as it is always recommended to use latest version of the API. In case of any further assistance please feel free to contact us.


Best Regards,

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan