Error message "Wrong format of page's content" when saving some PDFs

Support Team,

Our issue seems to be very similar to the Support ticket seen here:

We, too, are noticing Aspose crashes using Aspose PDF version 23.12 on files that previously worked fine using Aspose version 23.8. Here’s a sample of the stack trace that we’ve seen in our application logs when the Aspose PDF library crashes:

class com.aspose.pdf.internal.ms.System.l6n: Wrong format of page’s content.
com.aspose.pdf.internal.l4t.lu.lI(Unknown Source)
com.aspose.pdf.internal.l4t.lu.lI(Unknown Source)
com.aspose.pdf.internal.l4t.lu.lI(Unknown Source)
com.aspose.pdf.Annotation.lh(Unknown Source)
com.aspose.pdf.AnnotationCollection.lf(Unknown Source)
com.aspose.pdf.ADocument.preSave(Unknown Source)
com.aspose.pdf.ADocument.lf(Unknown Source)
com.aspose.pdf.ADocument.lf(Unknown Source)
com.aspose.pdf.ADocument.save(Unknown Source)
com.aspose.pdf.Document.save(Unknown Source)

Here’s a snippet of code that mimics what our application code is doing - we’re creating a new PDF document from an existing PDF and attempting to save the first page of the new PDF document.

/* Aspose Java Version 23.12 - sometimes crashes with the stack trace above during save /
/
Aspose Jave Version 23.8 - consistently works fine even on files where 23.12 crashes */
pdfDocument = new Document(filePathToProblemPDF);
currentDocument = new Document();
currentDocument.getPages().add(pdfDocument.getPages().get_Item(0));
currentDocument.save(tmpOutPath);

When we switched back to Aspose PDF version 23.8, the PDF files that have problems with version 23.12 work fine with version 23.8. While we have a limited number of PDF files that are having this issue so far, we are concerned we may begin seeing more.

Application running on Linux Ubuntu 20.04 with Java OpenJDK 21.0.1

Attaching one page of a PDF document that exhibits the issue in our application.
Sample_Aspose_PDF_23.12_WrongFormatSaveIssue.zip (42.7 KB)

@jmuth

We could not notice any issue while using the code snippet in our environment with 23.12 and 24.1 versions of the API.

However, we noticed that you are not adding pages correctly. The Page Collection in Aspose.Pdf.Document starts from 1 index unlike usual collections that start with 0 index. Therefore, we used the code like below and it did not raise any Exception:

Document pdfDocument = new Document(dataDir + "tmp_2109_0.pdf");
Document currentDocument = new Document();
currentDocument.getPages().add(pdfDocument.getPages().get_Item(1));
currentDocument.save(dataDir + "tempOutout.pdf");

tempOutout.pdf (49.3 KB)

Asad,

You are correct - the index should be 1 since I mocked up the code incorrectly. While you were unable to reproduce the issue with this PDF, I can try to attach other PDFs to see if you can see the issue.

Also, were you able to look at the stack trace to identify potential changes in the code between versions 23.8 and 23.12 that may account for differences in saving PDFs? Since there are multiple reports on this same error now, I believe there’s something that’s flawed, though possibly inconsistent, in the 23.12 version.

Thanks, Jerry

@jmuth

In order to further comment on the issue that you are facing, we need to replicate and investigate the case. If there have been some changes to cause it, we will determine and detect it during our analysis and provide fixes. Please share some sample document and steps to reproduce the issue so that wr can proceed further accordingly.

Asad,

We have not been able to replicate the Aspose crashes outside of our application with the sample files (one of which I provided previously). We will attempt to upgrade to PDF version 24.1 to see if that resolves the issue. If not, we’ll continue monitoring the other ticket open on this issue - 277419 - and see if any improvements are made for that issue which resembles the issue that we are seeing.

Thank you.

@jmuth

Sure, please take your time to further investigate and monitor things at your side. Feel free to post here in case you find something buggy related to Aspose.PDF. We will further proceed to address the issue accordingly.

Asad,

We upgraded Aspose PDF from 23.12 to 24.1 and the problem is still there in our application, and we still cannot reproduce the problem outside of our application.

Can you analyze the stack traces (see below) and give us some clue about the problem and hopefully help us to reproduce the problem.

class com.aspose.pdf.internal.ms.System.l6n: Wrong format of page’s content.

com.aspose.pdf.internal.l4t.lu.lI(Unknown Source)

com.aspose.pdf.internal.l4t.lu.lI(Unknown Source)

com.aspose.pdf.internal.l4t.lu.lI(Unknown Source)

com.aspose.pdf.Annotation.lh(Unknown Source)

com.aspose.pdf.AnnotationCollection.lf(Unknown Source)

com.aspose.pdf.ADocument.preSave(Unknown Source)

com.aspose.pdf.ADocument.lf(Unknown Source)

com.aspose.pdf.ADocument.lf(Unknown Source)

com.aspose.pdf.ADocument.save(Unknown Source)

com.aspose.pdf.Document.save(Unknown Source)

@xyang

Is it possible that your application may have modified the document in some other way during its entire routine? Also, is it the complete stack trace? Please share complete stack trace information so that we can proceed with logging an investigation ticket and share the ID with you.

MoreSampleFiles.zip (1.6 MB)

Got more details and found out why the problem only happens inside our application but not outside.

The original pdf file is first converted to Black and White format with GhostScript, and then it is split into individual page pdf files.

The GhostScript command is as follows
sudo gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sFONTPATH=/usr/share/fonts/ -dHaveTransparency=true -dProcessColorModel=/DeviceGray -dColorConversionStrategy=/Gray -o /tmp/YAX.PC.00000142_gray.pdf -f /tmp/processing/YAX.PC.00000142.pdf

The following warning was found in the output of the command:
Artifex Ghostscript 10.02.1 (2023-11-01) Copyright (C) 2023 Artifex Software, Inc. All rights reserved.
Processing pages 1 through 1.
Page 1
The following warnings were encountered at least once while processing this file:
A Form XObject had a BBox with a width or height of 0
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Aspose.PDF for Java 23.12 <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe’s published PDF
**** specification.

Or

Artifex Ghostscript 10.02.1 (2023-11-01)\nCopyright (C) 2023 Artifex Software, Inc. All rights reserved.
Processing pages 1 through 5.
Page 1
Loading font Helvetica (or substitute) from %rom%Resource/Font/NimbusSans-Regular
Page 2
Page 3
Page 4
Page 5
The following errors were encountered at least once while processing this file:
circular reference to indirect object
There was an error in an annotation
The following warnings were encountered at least once while processing this file:
A problem was encountered trying to preserve the Outlines
A Form XObject had a BBox with a width or height of 0
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Bluebeam PDF Library 20 <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe’s published PDF
**** specification.

It seems that the sample files do not conform to Adobe specification. And the Black and White pdf files converted with certain GhostScript version have problem.

GhostScript version in our application is Artifex Ghostscript 10.02.1 (2023-11-01), and that outside the application is GPL Ghostscript 10.01.2 (2023-06-21).

Attached are four original PDF files, the Black and White pdf files (cannot not reproduce the problem) converted with GhostScript 10.01.2 and the Black and White pdf files (can reproduce the problem) converted with GhostScript 10.02.1. Hope they can help you to analyze the problem and find out a solution.

@jmuth

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-43575

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thanks, Asad. We look forward to hearing about a fix for this issue soon.

@jmuth

We will surely prioritize the issue on first come first serve basis and as soon as it is resolved, we will inform you via this forum thread. Please spare us some time.

@asad.ali this has been raised as a paid support service issue

@aweech

Right. We have just confirmed that the ticket is raised to Enterprise Support now.

@asad.ali
We also filed a ticket to GhostScript (https://bugs.ghostscript.com/show_bug.cgi?id=707579). They made a fix regarding the warning about BBox and that resolved the issue.

@xyang

Thanks for sharing the details. We will also let you know in the respective paid support ticket as soon as the issue is fixed.

The issues you have found earlier (filed as PDFJAVA-43575) have been fixed in Aspose.PDF for Java 24.2.