Issue:
Issue in converting few .pdfs to Letter size .pdf files.
Details:
The existing code (Aspose 4.0) stopped working after migrating to newer version (7.1) of Aspose.Pdf.
Tested the code with 3 different approaches and still see same issue.
Steps:
1. Open the .pdf file as doc in program and change the page size using Aspose.PDF
2. Save the .pdf file as new .pdf file
3. Few pdf files are showing error "There was an error processing a page. There was a problem reading this document."
e.g. TestA.pdf converted to Conv_TestA_1.pdf - Giving error
e…g TestB.pdf converted to Conv_TestB_1.pdf - Not Giving error
Refer Original&Covertedfile.zip for files
Code Details:
Refer AsposeChangePDFPageSize.zip for code details.
static void Main(string[] args)
{
string folderPath = @“E:\Test”;
SetAsposeLicence(folderPath);
// First (1) Approach
ChangePageSize1(folderPath + “TestA.pdf”, 620, 792, folderPath + “Conv_TestA_1.pdf”);
ChangePageSize1(folderPath + “TestB.pdf”, 620, 792, folderPath + “Conv_TestB_1.pdf”);
Console.WriteLine(“First (1) Approach - Complete”);
// Second (2) Approach
ChangePageSize2(folderPath + “TestA.pdf”, 620, 792, folderPath + “Conv_TestA_2.pdf”);
ChangePageSize2(folderPath + “TestB.pdf”, 620, 792, folderPath + “Conv_TestB_2.pdf”);
Console.WriteLine(“First (2) Approach - Complete”);
//Trird (3) Approach
ChangePageSize3(folderPath + “TestA.pdf”, 620, 792, folderPath + “Conv_TestA_3.pdf”);
ChangePageSize3(folderPath + “TestB.pdf”, 620, 792, folderPath + “Conv_TestB_3.pdf”);
Console.WriteLine(“First (3) Approach - Complete”);
Console.ReadLine();
}
private static void ChangePageSize1(string filePath, float pageWidth, float pageHeight, string newFilePath)
{
Document doc = new Document(filePath); //Read the source file
PageCollection pageCollection = doc.Pages;
for (int i=1; i<= pageCollection.Count; i++) //Change page size on all the pages
{
Page pdfPage = pageCollection[i];
pdfPage.SetPageSize(pageWidth,pageHeight);
}
doc.Save(newFilePath); //Save file as new file
}
private static void ChangePageSize2(string filePath, float pageWidth, float pageHeight, string newFilePath)
{
PdfPageEditor pageEditor = new PdfPageEditor();
pageEditor.BindPdf(filePath);//bind pdf file
pageEditor.PageSize = Aspose.Pdf.Facades.PageSize.PageLetter; //Change size to letter size
pageEditor.Save(newFilePath); //Save file as new file
}
private static void ChangePageSize3(string filePath, float pageWidth, float pageHeight, string newFilePath)
{
PdfFileEditor pdfFileEditor = new PdfFileEditor();
pdfFileEditor.MakeNUp(filePath, newFilePath, 1, 1, Aspose.Pdf.Facades.PageSize.PageLetter);
}
private static void SetAsposeLicence(string folderPath)
{
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(folderPath+“Aspose.Total.lic”);
}
Observation:
All 3 approaches fails on same documents/file. The original file opens with Adobe Reader.
Impact:
This has delayed our production implementation and increased our efforts on identifying root cause, retesting. Please help
Note: In intermediate versions we had issues in combining .pdf with .doc which was resolved in 7.1 but now with 7.1 we do see issue that some pdf files are not opening/processing.