We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Null Pointer Exception (NPE) when saving PDF document that was converted to PDFA

I have a pdf file that is causing NPE in Aspose pdf converter. Steps to reproduce:

  1. Have this file ns.pdf (49.4 KB)
  2. Create new com.aspose.pdf.Document from this file.
  3. Convert this document to PDFA (for example PDF_A_3B) with options ConvertErrorAction.Delete.
  4. Save conversion result to byte array.
  5. Create new com.aspose.pdf.Document from this byte array.
  6. Save his document to file.

Step 6 produces NPE:

    at com.aspose.pdf.internal.l10t.ly.lI(Unknown Source)
    at Main.main(Main.java:51)

It seems that this pdf file has some javascript code in it that makes Aspose behave wrong. Somehow if I don’t set ConversionOptions to Delete then Aspose doesn’t even convert a file to PDFA and convert() returns false. But out production uses option Delete and we need a way to convert PDF similar to this to PDFA. What do we do?

My system data:

Ubuntu 20.04.3 LTS
openjdk 11.0.10 2021-01-19
Aspose version: 21.12

Here is the code to reproduce an error:

public static void main(String[] args) {

    com.aspose.pdf.License pdfLicense = new com.aspose.pdf.License();
    try {
    catch (Exception e) {

    File inputFile = new File("../samples/ns.pdf");
    try {

        // reading source file to document
        com.aspose.pdf.Document doc = new Document(new FileInputStream(inputFile));

        // converting source document to PDFA
        Document convertedDoc = Main.toPDFA(doc);

        // saving PDF_A_3B document to byte array
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] content = baos.toByteArray();

        // we have some conversions here in production

        // getting document again from byte array
        Document reopenedDoc = new Document(new ByteArrayInputStream(content));

        // saving new document to file
    catch (Exception e) {


public static com.aspose.pdf.Document toPDFA(com.aspose.pdf.Document pdfDocument) {

    Path tempFilePath = null;
    try {
        tempFilePath = Files.createTempFile(null, "tmpfilename");
    } catch (IOException e) {
    String fileName = tempFilePath.toAbsolutePath().toString();

    PdfFormatConversionOptions conversionOptions = new PdfFormatConversionOptions(
    boolean converted = pdfDocument.convert(conversionOptions);
    System.out.println("converted: " + converted);

    return pdfDocument;


We were able to reproduce the issue in our environment while testing the scenario with the latest version of the API. Therefore, it has been logged as PDFJAVA-41555 in our issue tracking system. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

1 Like