PDF Document.Save InvalidOperationException Wrong Format of page's content

Attempting to read and save a pdf results in System.InvalidOperationException: Wrong format of page’s content. This occurs for certain PDF files with annotations. If we remove the annotations, the document can be saved. This is a work around, but then our document is missing signatures and form elements. Aspose.PDF v25.9.0

This is the full exception:
System.InvalidOperationException
HResult=0x80131509
Message=Wrong format of page’s content.
Source=Aspose.PDF
StackTrace:
at #=zExLBj0hJQRLgnh3jDKPpSL_oftPGZHCkMcPsq4cgSyIB.#=zqQh61RJq_4HA(#=zRgeJvk2czMWeXMV7OJg4Rdn8OnXgpNFxIw== #=zOFLadhU=, Int64& #=zkdn8lro=)
at #=zExLBj0hJQRLgnh3jDKPpSL_oftPGZHCkMcPsq4cgSyIB.#=zpVAAYed458Ov(#=zRgeJvk2czMWeXMV7OJg4Rdn8OnXgpNFxIw== #=zOFLadhU=, #=zm8QRzXVnqH5AAJVwGrRqOmJWQif0yHE05exj3WY4m8i8 #=zEDz_4_6vfL18tIGLcA==, Boolean #=zsv2ycRR5KmIc, Boolean #=zFhIfNNfS5YMB)
at #=zExLBj0hJQRLgnh3jDKPpSL_oftPGZHCkMcPsq4cgSyIB.#=zpVAAYed458Ov(#=zRgeJvk2czMWeXMV7OJg4Rdn8OnXgpNFxIw== #=zOFLadhU=, #=zm8QRzXVnqH5AAJVwGrRqOmJWQif0yHE05exj3WY4m8i8 #=zEDz_4_6vfL18tIGLcA==)
at Aspose.Pdf.Annotations.Annotation.#=zqbAQwpbiGwUf(#=zRgeJvk2czMWeXMV7OJg4Rdn8OnXgpNFxIw== #=zP2nqHOcjLAzD)
at Aspose.Pdf.Annotations.Annotation.#=zm$4IUip1dxpP()
at Aspose.Pdf.Annotations.AnnotationCollection.#=zGqdXBLT4FR7d()
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zpu0SGso0NseGWLXhKrY1Sdcxku26zam_sZJLjJrYU9Uj(MethodBase #=z5uDaQm4=, Object #=zyk5QGgw=, Object[] #=zWJ9YnEg=, Boolean #=zhYaYijI=)
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zmUe6vnszuUNun$qyuzwEuqQ=(MethodBase #=z5uDaQm4=, Boolean #=zyk5QGgw=)
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=z2_aTiucSm05oLvZkKKitUoWvb39L(dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd #=z5uDaQm4=, #=q1CFHSu4PSt0Yzn9qbpWBp3vVDIxQYhBNC_0udBnIKog= #=zyk5QGgw=)
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zYGwWYwLzQRAW$Tc2RQi6X2foJTOs(Boolean #=z5uDaQm4=)
— End of stack trace from previous location —
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zWWu7v3WVF4Z5f$LA6dZEqVNLemOxrTVIyXdHxcE=(Exception #=z5uDaQm4=)
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zwdG8DaDJ9MDJo$0nYw05Ne8V8JwG(Object #=z5uDaQm4=)
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zN2I_3z$tZbuG_Y4MhVq2zG1FaZe6()
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zOTt3JcXlpKifs$hMdsAP4SU8HbIwt2mYMQ==(dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd #=z5uDaQm4=, #=q1CFHSu4PSt0Yzn9qbpWBp3vVDIxQYhBNC_0udBnIKog= #=zyk5QGgw=)
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zYGwWYwLzQRAW$Tc2RQi6X2foJTOs(Boolean #=z5uDaQm4=)
— End of stack trace from previous location —
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zWWu7v3WVF4Z5f$LA6dZEqVNLemOxrTVIyXdHxcE=(Exception #=z5uDaQm4=)
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zwdG8DaDJ9MDJo$0nYw05Ne8V8JwG(Object #=z5uDaQm4=)
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zN2I_3z$tZbuG_Y4MhVq2zG1FaZe6()
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zBsTadT_j4cZ6jM3lsmL_KYzbN9D9GNbP05Nv88A=(Object #=z5uDaQm4=, UInt32 #=zyk5QGgw=)
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zYGwWYwLzQRAW$Tc2RQi6X2foJTOs(Boolean #=z5uDaQm4=)
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zYGwWYwLzQRAW$Tc2RQi6X2foJTOs(Boolean #=z5uDaQm4=)
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zVJrY4w7eHyjv2BL98Vwa9jmWBZ74fum_E8ttiLs_8HBQ(Object[] #=z5uDaQm4=, Type[] #=zyk5QGgw=, Type[] #=zWJ9YnEg=, Object[] #=zhYaYijI=)
at dje_qVJ24SYYBED2PMPQKKH9PMFNE9CE3ASFDNZE9R6FDKT5DMCUZEXTQ_ejd.#=zJ8gG0HTuG5kK1BSkipspRfO1i0$i(Stream #=z5uDaQm4=, String #=zyk5QGgw=, Object[] #=zWJ9YnEg=)
at Aspose.Pdf.Document.#=ziEx$3M2zno$v(Stream #=zVErAv_8=, SaveOptions #=zVLb3O24Qnbf4)
at Aspose.Pdf.Document.#=z2Y2S8tjqhd_y(Stream #=zVErAv_8=, SaveOptions #=zVLb3O24Qnbf4)
at Aspose.Pdf.Document.#=zNK1baOJ4OZEl(Stream #=z6EgXLihBA9uk, SaveOptions #=zxYGJx9c=)
at Aspose.Pdf.Document.#=zNK1baOJ4OZEl(Stream #=z6EgXLihBA9uk, SaveFormat #=zCJw4ygY=)
at Aspose.Pdf.Document.Save(Stream outputStream, SaveFormat format)
at ACES.Document.DomainModel.Utilities.ConvertToPdfUtility.PDFStream(Stream ms, String filename) in C:_Unite\ACES.Document.ServiceFabric\ACES.Document.DomainModel\Utilities\ConvertToPdfUtility.cs:line 220

This exception was originally thrown at this call stack:
[External Code]
ACES.Document.DomainModel.Utilities.ConvertToPdfUtility.PDFStream(System.IO.Stream, string) in ConvertToPdfUtility.cs

@llewis

It appears that the System.InvalidOperationException: Wrong format of page's content error is related to the presence of annotations in certain PDF files. This issue can arise when the PDF structure is not compatible with the Aspose.PDF library’s expectations for processing.

As you’ve noted, removing the annotations allows the document to be saved, but this workaround results in the loss of important elements like signatures and form fields. Unfortunately, this indicates that the annotations may be causing the content format to be invalid.

To address this, consider the following options:

  1. Update Aspose.PDF: Ensure you are using the latest version of the library, as updates may include fixes for such issues.
  2. Check PDF Structure: Validate the PDF files for any corruption or non-standard structures that could be causing the error.
  3. Contact Support: If the issue persists, reaching out to Aspose support with the problematic PDF files may provide further insights or solutions.

I hope this helps you resolve the issue effectively.

Best regards,
Professionalize.Discourse Bot

We are using latest Aspose.PDF v25.9.0. The PDF file is not corrupt and displays properly in Adobe Reader with the annotations.

@llewis

Would you please share your sample PDF document and code snippet with us? We will test the scenario in our environment and address it accordingly.