Aspose Total 25.1 can't read Java stream properly

I had this way:
inputStream = new FileInputStream(sourcePath.toFile().getAbsolutePath());
pdfDocument = new com.aspose.pdf.Document(inputStream);
pdfDocument.convert(new PdfFormatConversionOptions(tempFileForAspose, PdfFormat.valueOf(“PDF_A_” + kokeiltavaPdfaVersio)));

I had in one folder 798 files to convert (from other than pdf ->) pdf → pdf/a
First run → 718 ok, other various exceptions
Second run 58 ok
Third run 17 ok
Fourth run the rest 5 ok.

I made some additions:

inputStream = new FileInputStream(sourcePath.toFile().getAbsolutePath());
pdfDocument = new com.aspose.pdf.Document(inputStream);
inputStream.readAllBytes(); //i added this
inputStream.close(); // i added this, too; if there had raised problems, i’d remove this
pdfDocument.convert(new PdfFormatConversionOptions(tempFileForAspose, PdfFormat.valueOf(“PDF_A_” + kokeiltavaPdfaVersio)));

→ Everything ok by one run.

Dependencies:

    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-3d</artifactId>
        <version>25.1.0</version>
        <classifier>jdk8</classifier>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-barcode</artifactId>
        <version>25.1</version>
        <classifier>jdk18</classifier>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-cad</artifactId>
        <version>24.9</version>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-cells</artifactId>
        <version>25.1</version>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-diagram</artifactId>
        <version>25.1</version>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-drawing</artifactId>
        <version>24.11</version>
        <classifier>jdk18</classifier>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-email</artifactId>
        <version>24.12</version>
        <classifier>jdk16</classifier>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-font</artifactId>
        <version>24.12</version>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-html</artifactId>
        <version>25.1</version>
        <classifier>jdk21</classifier>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-imaging</artifactId>
        <version>24.12</version>
        <classifier>jdk16</classifier>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-note</artifactId>
        <version>24.12</version>
        <classifier>jdk17</classifier>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-ocr</artifactId>
        <version>25.1.0</version>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-omr</artifactId>
        <version>24.12</version>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-page</artifactId>
        <version>25.1</version>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-pdf</artifactId>
        <version>25.1</version>
        <classifier>jdk17</classifier>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-psd</artifactId>
        <version>25.1</version>
        <classifier>jdk16</classifier>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-pub</artifactId>
        <version>22.8</version>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-slides</artifactId>
        <version>25.1</version>
        <classifier>jdk16</classifier>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-tasks</artifactId>
        <version>25.1</version>
        <classifier>jdk18</classifier>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-tex</artifactId>
        <version>24.12</version>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-words</artifactId>
        <version>25.1</version>
        <classifier>jdk17</classifier>
    </dependency>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-zip</artifactId>
        <version>25.1</version>
    </dependency>

@jouko.tiihonen,

It seems you are getting issue with Aspose.PDF for Java, so I am moving your thread to respective forum where one of our colleagues from Aspose.PDF team will evaluate your issue and assist you accordingly.

@jouko.tiihonen

Can you please share a complete minimal sample of code snippet that we can execute in our environment to reproduce the same issue that you noticed?

Unfortunately testing set is not possible, because all our data is highly personal data.

It it were some files, we could change real data to fake one, but as I told:
I had in one folder 798 files to convert (from other than pdf ->) pdf → pdf/a
First run → 718 went ok, other had various exceptions
Second run 58 went ok (the previous ok we don’t handle again)
Third run went 17 ok
Fourth run the rest 5 ok.

Some of the exceptions:

Virhe (1): Could not initialize class com.aspose.words.internal.zzWtn
Virhe (2): Exception java.util.ServiceConfigurationError: javax.imageio.spi.ImageWriterSpi: Provider com.aspose.note.internal.twelvemonkeys.imageio.plugins.tiff.TIFFImageWriterSpi not found [in thread “main”]
java.base/java.util.ServiceLoader.fail(ServiceLoader.java:593)
java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(ServiceLoader.java:1219)
java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1228)
java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1273)
java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1309)
java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1393)
java.desktop/javax.imageio.spi.IIORegistry.registerApplicationClasspathSpis(IIORegistry.java:179)
java.desktop/javax.imageio.spi.IIORegistry.(IIORegistry.java:107)
java.desktop/javax.imageio.spi.IIORegistry.getDefaultInstance(IIORegistry.java:128)
java.desktop/javax.imageio.ImageIO.(ImageIO.java:64)
com.aspose.words.internal.zzWtn.(Unknown Source)
com.aspose.words.internal.zzZZY.zzXWG(Unknown Source)
com.aspose.words.internal.zzZZ5.zzY30(Unknown Source)
com.aspose.words.internal.zzZZ5.(Unknown Source)
com.aspose.words.zzYO3.zzY30(Unknown Source)
com.aspose.words.zzZaJ.zzY30(Unknown Source)
com.aspose.words.zzZrm.zzY30(Unknown Source)
com.aspose.words.zzZrm.zzY30(Unknown Source)
com.aspose.words.zzZrm.zzY30(Unknown Source)
com.aspose.words.zzWf6.zzYai(Unknown Source)
com.aspose.words.zzWf6.zzY30(Unknown Source)
com.aspose.words.zzYlz.zzY30(Unknown Source)
com.aspose.words.zzYlz.zzY30(Unknown Source)
com.aspose.words.zzYac.zzam(Unknown Source)
com.aspose.words.zzYac.zzXGM(Unknown Source)
com.aspose.words.zzYac.zzXGM(Unknown Source)
com.aspose.words.zzYSX.zzWft(Unknown Source)
com.aspose.words.zzX71.zzXuK(Unknown Source)
com.aspose.words.zzWzN.zzZUD(Unknown Source)
com.aspose.words.zzWzN.zzY30(Unknown Source)
com.aspose.words.zzWzN.zzY30(Unknown Source)
com.aspose.words.zzWzN.zzXlV(Unknown Source)
com.aspose.words.zzWOO.zzY30(Unknown Source)
com.aspose.words.zzYdB.zzX8M(Unknown Source)
com.aspose.words.zzYdB.zzY30(Unknown Source)
com.aspose.words.Document.zzY30(Unknown Source)
com.aspose.words.zzZu0.zzWjK(Unknown Source)
com.aspose.words.zzZu0.zzY30(Unknown Source)
com.aspose.words.zzWCO.zzY30(Unknown Source)
com.aspose.words.Document.zzWjK(Unknown Source)
com.aspose.words.Document.zzY30(Unknown Source)
com.aspose.words.Document.save(Unknown Source)
com.aspose.words.Document.save(Unknown Source)

Virhe (1): Invalid font name
com.aspose.pdf.FontCollection.get_Item(Unknown Source)
com.aspose.pdf.internal.l10v.l0u$lu.visit(Unknown Source)
com.aspose.pdf.operators.SelectFont.accept(Unknown Source)
com.aspose.pdf.internal.l10v.l0u$lu.lI(Unknown Source)
com.aspose.pdf.internal.l10v.l0u.lI(Unknown Source)
com.aspose.pdf.internal.l10v.l0u.lt(Unknown Source)
com.aspose.pdf.internal.l10v.l0if.ly(Unknown Source)
com.aspose.pdf.internal.l10v.ly.lt(Unknown Source)
com.aspose.pdf.internal.l10v.l0if.l0p(Unknown Source)
com.aspose.pdf.internal.l10v.ly.lI(Unknown Source)
com.aspose.pdf.ADocument.lI(Unknown Source)
com.aspose.pdf.ADocument.convert(Unknown Source)
com.aspose.pdf.Document.convert(Unknown Source)

@jouko.tiihonen

One of the exceptions is related to Aspose.Words and we suggest that you create new topic in Aspose.Words forum category so that it can be addressed.

Related to other exception, it looks like document specific issue. We are not asking to share all files but only one for which this error is happening.

Related to the code snippet that you shared, can we simply put it inside a loop reading multiple files from a directory and test it to replicate the issue?

Since Aspose’s mistake can be avoided so easily, I have no motive in taking the matter forward.

I reported it to Aspose because this is a very annoying bug (as well as performance freezing when converting thousands of documents (from <1s to 30s per document, thus we restart Java every 500 documents)).

I’ve been developing applications non-stop since 1985, I’m 63 years old now and I’ve got three projects to do, no time to fiddle with these mistakes. I hope that your younger generation would take responsibility for building reliable applications.

“can we simply put it inside a loop reading multiple files from a directory and test it to replicate the issue?”
Yes, this is how it should be tried.

@jouko.tiihonen

We tested below code in our environment and could not replicate the above exception. We tested with 25.1 version of the API:

try {
    File folder = new File(dataDir + "testfiles\\");
    File[] listOfFiles = folder.listFiles();

    for (int i = 0; i < listOfFiles.length; i++) {
        final int index = i;
        try {
            System.out.println("Processing " + dataDir + "testfiles\\" + listOfFiles[index].getName());
            FileInputStream inputStream = new FileInputStream(dataDir + "testfiles\\" + listOfFiles[index].getName());
            Document pdfDocument = new com.aspose.pdf.Document(inputStream);
            pdfDocument.convert(new PdfFormatConversionOptions(dataDir + "testfiles\\" + i + ".xml", PdfFormat.PDF_A_2A));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
} catch (Exception ex) {
    ex.printStackTrace();
}

We did notice some exceptions in the console output but they were all related to specific PDF files. We believe that the code snippet is fine and should produce expected results. If you are facing some exception then it is related to specific PDF document because API is unable to process it with this code. We need to address this issue and apply fix in the API. That is why requested you to share some sample files with us.

Please note that we do understand your concerns and value them as well. It is quite difficult analyze and determine the error cause without replicating it in our environment. In case your files are confidential, you can share them in a private message. We assure you that we only use them for testing purposes and erase them from our system as soon as the case is closed. You can please click on the username and press Blue Message button to send a private message.