Null pointer Exception with Aspose PDF

While converting a pdf to PDF/A-1B , I get following error

Exception while converting PDF to PDFA_1B
java.lang.NullPointerException: null
	at com.aspose.pdf.internal.l6v.l1h.l2k(Unknown Source) ~[aspose-pdf-22.4.jar!/:na]
	at com.aspose.pdf.ADocument.lf(Unknown Source) ~[aspose-pdf-22.4.jar!/:na]
	at com.aspose.pdf.ADocument.lf(Unknown Source) ~[aspose-pdf-22.4.jar!/:na]
	at com.aspose.pdf.ADocument.preSave(Unknown Source) ~[aspose-pdf-22.4.jar!/:na]
	at com.aspose.pdf.ADocument.lf(Unknown Source) ~[aspose-pdf-22.4.jar!/:na]

When I check the aspose logs for conversion, I see the following

<Compliance Name="Log" Operation="Validation" Target="PDF/A-1B">
    <Version>1.0</Version>
    <Copyright>Copyright (c) 2001-2022 Aspose Pty Ltd. All Rights Reserved.</Copyright>
    <Date>3/7/2025 12:03:33 PM</Date>
    <File Version="1.4" Name="errored.pdf" Pages="32">
        <Security />
        <Catalog>
            <Problem Severity="Error" Clause="6.9" Convertable="True">Acroform is enabled</Problem>
        </Catalog>
        <Problem Severity="Error" Clause="6.4" ObjectID="370" Page="2" Convertable="True">The transparency is prohibited ('Group' key)</Problem>
        <Problem Severity="Error" Clause="6.4" ObjectID="374" Page="3" Convertable="True">The transparency is prohibited ('Group' key)</Problem>
        <Problem Severity="Error" Clause="6.4" ObjectID="418" Page="4" Convertable="True">The transparency is prohibited ('Group' key)</Problem>
        <Problem Severity="Error" Clause="6.4" ObjectID="431" Page="5" Convertable="True">The transparency is prohibited ('Group' key)</Problem>
        <Problem Severity="Error" Clause="6.4" Page="2" Convertable="True">The transparency is prohibited ('Group' key)</Problem>
        <Problem Severity="Error" Clause="6.4" Page="3" Convertable="True">The transparency is prohibited ('Group' key)</Problem>
        <Problem Severity="Error" Clause="6.4" Page="4" Convertable="True">The transparency is prohibited ('Group' key)</Problem>
        <Problem Severity="Error" Clause="6.4" Page="5" Convertable="True">The transparency is prohibited ('Group' key)</Problem>
        <Header />
        <Annotations />
        <Fonts />
        <trailer />
        <Metadata>
            <Problem Severity="Error" Clause="6.7.3" Convertable="True">Document information entry 'Creator' not synchronized with metadata property 'xmp:CreatorTool'</Problem>
            <Problem Severity="Error" Clause="6.7.3" Convertable="True">Document information entry 'Producer' not synchronized with metadata property 'pdf:Producer'</Problem>
            <Problem Severity="Error" Clause="6.7.3" Convertable="True">Document information entry 'CreationDate' not synchronized with metadata property 'xmp:CreateDate'</Problem>
            <Problem Severity="Error" Clause="6.7.3" Convertable="True">Document information entry 'ModDate' not synchronized with metadata property 'xmp:ModifyDate'</Problem>
            <Problem Severity="Error" Clause="6.7.11" Convertable="True">Required property 'pdfaid:part' for schema 'pdfaid' missing</Problem>
            <Problem Severity="Error" Clause="6.7.11" Convertable="True">Required property 'pdfaid:conformance' for schema 'pdfaid' missing</Problem>
        </Metadata>
        <objects>
            <Problem Severity="Error" Clause="6.4" ObjectID="406" Convertable="True">ExtGState 'ca' value shall be 1.0</Problem>
            <Problem Severity="Error" Clause="6.4" ObjectID="406" Convertable="True">ExtGState 'CA' value shall be 1.0</Problem>
            <Problem Severity="Error" Clause="6.4" ObjectID="406" Convertable="True">ExtGState 'BM' value shall be 'Normal' or 'Compatible'</Problem>
        </objects>
        <xObjects>
            <Problem Severity="Error" Clause="6.2.4" ObjectID="365" Convertable="True">The key 'Metadata' is prohibited for image</Problem>
            <Problem Severity="Error" Clause="6.2.4" ObjectID="404" Convertable="True">The key 'Metadata' is prohibited for image</Problem>
        </xObjects>
        <actions />
        <Problem Severity="Error" Clause="6.4" Page="3" Convertable="True">ExtGState 'SMask' value shall be 'None'</Problem>
    </File>
</Compliance>

However, for another pdf for which I see similar conversion logs , the conversion is successful though.

<Compliance Name="Log" Operation="Validation" Target="PDF/A-1B">
    <Version>1.0</Version>
    <Copyright>Copyright (c) 2001-2022 Aspose Pty Ltd. All Rights Reserved.</Copyright>
    <Date>3/7/2025 12:19:28 PM</Date>
    <File Version="1.4" Name="successful.pdf" Pages="2">
        <Security />
        <Catalog />
        <Problem Severity="Error" Clause="6.4" ObjectID="2" Page="1" Convertable="True">The transparency is prohibited ('Group' key)</Problem>
        <Header />
        <Annotations />
        <Fonts>
            <Problem Severity="Error" Clause="6.3.5" ObjectID="7" Page="1" Convertable="True">CIDSet is missing or incomplete for font 'AAAAAA+SourceSansPro-Regular'</Problem>
            <Problem Severity="Error" Clause="6.3.5" ObjectID="9" Page="1" Convertable="True">CIDSet is missing or incomplete for font 'BAAAAA+SourceSansPro-Bold'</Problem>
            <Problem Severity="Error" Clause="6.3.5" ObjectID="10" Page="1" Convertable="True">CIDSet is missing or incomplete for font 'CAAAAA+FontAwesome'</Problem>
            <Problem Severity="Error" Clause="6.3.5" ObjectID="11" Page="1" Convertable="True">CIDSet is missing or incomplete for font 'DAAAAA+ArialMT'</Problem>
        </Fonts>
        <trailer />
        <Metadata>
            <Problem Severity="Error" Clause="6.7.11" Convertable="True">Required property 'pdfaid:part' for schema 'pdfaid' missing</Problem>
            <Problem Severity="Error" Clause="6.7.11" Convertable="True">Required property 'pdfaid:conformance' for schema 'pdfaid' missing</Problem>
        </Metadata>
        <objects />
        <xObjects />
        <actions />
    </File>
</Compliance>

This is using Licensed aspose-pdf-22.4 with Java11.
Please do suggest.

@sd2040.gmail

It seems you are encountering a NullPointerException while trying to convert a PDF to PDF/A-1B format using Aspose.PDF. This type of error can often be caused by issues within the PDF document itself, particularly if it contains elements that are not compliant with the PDF/A standards.

From the logs you provided, there are several errors related to transparency and metadata synchronization that could be contributing to the conversion failure. Here are some steps you can take to troubleshoot and potentially resolve the issue:

  1. Check for Transparency Issues: The logs indicate that transparency is prohibited in PDF/A-1B. You may need to flatten any transparent elements in your PDF before conversion. This can be done by rendering the PDF pages to images and then creating a new PDF from those images.

  2. Validate Document Metadata: Ensure that the document’s metadata entries (like ‘Creator’, ‘Producer’, ‘CreationDate’, and ‘ModDate’) are synchronized with the XMP properties. You can manually set these properties in your PDF document to ensure they match.

  3. Review the PDF Structure: The errors related to ExtGState and Metadata suggest that there are specific elements in your PDF that are not compliant with PDF/A-1B. You may need to remove or modify these elements.

  4. Use Conversion Logs: Utilize the conversion logs to identify specific issues. You can generate a log file during the conversion process to get detailed information about what might be causing the failure.

  5. Test with Different PDFs: Since you mentioned that another PDF converted successfully despite similar logs, try to identify differences between the two PDFs. This might help you pinpoint what specific elements in the problematic PDF are causing the issue.

  6. Update Aspose.PDF: Ensure you are using the latest version of Aspose.PDF, as updates often include bug fixes and improvements that could resolve your issue.

Here is a sample code snippet for converting a PDF to PDF/A-1B while generating a log file:

import com.aspose.pdf.Document;
import com.aspose.pdf.PdfFormat;
import com.aspose.pdf.ConvertErrorAction;

public class ConvertPDFToPDFA {
    public static void main(String[] args) {
        // Load the PDF document
        Document pdfDocument = new Document("path/to/your/document.pdf");
        
        // Convert to PDF/A-1B compliant document
        pdfDocument.convert("path/to/log.xml", PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);
        
        // Save the output document
        pdfDocument.save("path/to/output/document.pdf");
    }
}

By following these steps and using the provided code, you should be able to troubleshoot the NullPointerException and successfully convert your PDF to PDF/A-1B format. If the issue persists, consider reaching out to Aspose support with detailed logs and the problematic PDF for further assistance.

@sd2040.gmail
The issue seems document specific.
As you are using older version of Aspose Pdf for Java product, you can try to check if it’s fixed on newer versions - you can find them here

If issue persist and if it’s possible you can provide document and code you used to reproduce this issue and I will add task for development team to investigate and fix in later version of Aspose Pdf library