Invalid PDF file created when calibri italics used

We’re seeing an issue where a customer is saving an Excel file to PDF which produces an invalid PDF file. We’ve identified that a single cell containing Calibri Italics causes the issue. When we remove the italics the PDF file is valid, when we add the italics it is invalid. You’ll see in the attached screenshot that the PDF without italics loads fine and we can review the embedded fonts in the Adobe properties screen. The screenshot of the PDF with italics shows an error message loading and the Properties screen hangs on loading font information.

We’re seeing this issue when run from .NET Core 3.1 on Windows Server 2019 with Calibri Italics version 6.22 and Aspose PDF version .NET 21.10.0. We can not reproduce the issue from .NET Framework 4.7.2 on the same machine or from .NET Core 3.1 on a different machine.

Attached is a copy of the bad and good PDF files (with and without italics) and a copy of the Excel file used to generate the PDF. The screenshots are from Adobe Acrobat.

The code path uses Aspose.Cells to convert the Excel file to a PDF file, then uses Aspose.PDF to merge the PDF with other PDF files and maniputlate the bookmarks, although in this specific case there are no other files to merge with.

var pdfFileStream = new MemoryStream();
var workbook = new Workbook(path);
workbook.Save(pdfFileStream, SaveFormat.Pdf);
pdfFileStream.Seek(0, SeekOrigin.Begin);

var mainDocument = new Document();
var mainDocumentStream = new MemoryStream();
mainDocument.Save(mainDocumentStream);
mainDocumentStream.Seek(0, SeekOrigin.Begin);

var mergeFileStream = new MemoryStream();
var mergeDocument = new Document(pdfFileStream);
mergeDocument.Save(mergeFileStream );
mergeFileStream.Seek(0, SeekOrigin.Begin);

 var pdfEditor = new PdfFileEditor();
var combinedStream = new MemoryStream();
pdfEditor.Concatenate(mainDocumentStream, mergeFileStream, combinedStream);

var savePdfFileStream= new MemoryStream();
var savePdfFileDocument = new Document(combinedStream);
savePdfFileDocument.Save(savePdfFileStream);

// Omitted is manipulation of Bookmarks

//  savePdfFileStream is combined output file

Control Total Validation.zip (11.7 KB)
Bad - includes italics.pdf (58.8 KB)
Good - no italics.pdf (50.1 KB)
pdf_error.png (14.5 KB)
pdf_error_2.png (6.2 KB)
pdf_working.png (23.8 KB)

@weissa

Have you tried using 21.11 version of the API? We tested using Aspose.PDF for .NET 21.11 and did not notice any issue. Please find the attached output PDF generated in our environment and try using the latest version of the API. In case you still face any issues, please let us know.

output.pdf (58.3 KB)

@asad.ali,

We’ll try and setup a test with .NET 21.11. It’s difficult for our customer to update software on their server so we were hoping that a review of the bad PDF file might reveal something.

Thank you for testing internally.
-Andy

@weissa

You can test with 21.11 version by using a free 30-day temporary license. Furthermore, you can also double check if all required fonts are correctly installed in the system where issue is occurring. Please feel free to let us know in case you need further assistance.

@asad.ali,

We haven’t been able to test the latest version yet because our customer has a challenging environment when it comes to upgrades. I did some analysis and found the cause of the bad pdf and how to manually correct it.

The good PDF created using .NET Framework contains a media box with dimensions 595.44 & 841.68

<</Type/Page/Parent 9 0 R/Contents 11 0 R/MediaBox[0 0 595.44 841.68]/Group<</CS/DeviceRGB/S/Transparency/Type/Group>>/Resources<</Font<</FAAAAI 12 0 R/FAAABD 17 0 R/FAAABI 22 0 R/FAAACD 27 0 R>>>>>>

The bad PDF created with .NET Core 3.1 has height and width values that expand to 20 decimal places of precision. If I manually adjust the file to round it down to 2 decimal places of precision then the file works fine. It seems that this is causing an overflow with most PDF readers.

<</Type/Page/Parent 9 0 R/Contents 11 0 R/MediaBox[0 0 595.44000000000005456968 841.67999999999994997779]/Group<</CS/DeviceRGB/S/Transparency/Type/Group>>/Resources<</Font<</FAAAAI 12 0 R/FAAABD 17 0 R/FAAABI 22 0 R/FAAACD 27 0 R>>>>>>

With this information would you mind having a look to see if there are any obvious issues that should be corrected before we ask the customer to upgrade?

Thank you,
-Andy

@weissa

We again tested the scenario using both 21.10 and 21.12 versions of the API under .NET Core 3.1 environment. In both case, we achieved a correct PDF document. It seems like the issue is related to fonts installation. Please check the PDF which is attached and see the fonts by going into document properties. You can compare it with the PDF generated at your end and install the missing fonts in order to prevent the issue. output.pdf (58.3 KB)

Can you make the file public please

@weissa

Please use this link to download the file.