PDF convert to PDF/A works in Windows- but failed in Linux

Hi,

I'm testing the PDF converting function in our system by using Java aspose-pdf 11.9.0. I've raised an issue with multi-threading. Here we got another issue when converting PDF to PDF/A.

For the same code and same pdf file, we can convert PDF to PDF/A in windows application, but when we deployed the application to our Linux server, the convert result is false.

The converting code is :

public void runTest(Path file, int times) throws IOException {
...
byte[] data = Files.readAllBytes(file);
byte[] pDFA = convertor.convertPDFToPDFA(data);
FileOutputStream pdfAOut = new FileOutputStream(RUN_PATH + "1_converted.pdf");
..
}


@Override
public byte[] convertPDFToPDFA(byte[] pdf) throws IOException {
ByteArrayInputStream pdfStream = null;
ByteArrayOutputStream pdfOutStream = null;
try {
pdfStream = new ByteArrayInputStream(pdf);
Document pdfDocument = new Document(pdfStream);
pdfOutStream = new ByteArrayOutputStream();
boolean success = pdfDocument.convert("./file.log", PdfFormat.PDF_A_1A, ConvertErrorAction.Delete);
if (!success) {
throw new RuntimeException ("Could not convert the PDF to a PDF/A-1A format PDF.");
}
DocumentInfo di = pdfDocument.getInfo();
pdfDocument.save(pdfOutStream);
System.out.println("save successfully:" + di.getCreationDate());

pdfOutStream.flush();
byte[] pdfOutput= pdfOutStream.toByteArray();
return pdfOutput;
} finally {
if (pdfOutStream != null) {
pdfOutStream.close();
}
if (pdfStream != null) {
pdfStream.close();
}

}
}


The convert result is success on windows, failed on linux.
boolean success = pdfDocument.convert("./file.log", PdfFormat.PDF_A_1A, ConvertErrorAction.Delete);

JVM is:
Java(TM) SE Runtime Environment (build pxa6480sr1fp1-20150603_01(SR1 FP1))
IBM J9 VM (build 2.8, JRE 1.8.0 Linux amd64-64 Compressed References 20150410_243669 (JIT enabled, AOT enabled)

Operating system is:
Linux 3.10.0-327.28.3.el7.x86_64 #1 x86_64 GNU/Linux

I attached the file.log from converting method as well.

We need to make a decision on our application soon, could you please have a look and give us a quick update? Thanks!

Hi Ryan,

Thanks for your inquiry. I have converted your PDF to PDFA on Linux and unable to notice the reported issue. As per PDFA standards the fonts should be embedded in PDFA file and It seems Aspose.Pdf for Java is unable to find fonts on your system. Please note on non-Windows OSs Aspose.Pdf for Java looks fonts in system default font path or specified local font path for custom font directory.

Please note most of the PDF documents that we convert are created by people using Windows or Mac OS operating systems with fonts that are installed with Microsoft Windows or with Microsoft Office. To resolve your issue either you can install Microsoft fonts on your system or copy fonts from your windows OS and paste to your system default font path.

Furthermore, if you want to use custom fonts from other than system default font path then you need to add that folder path into LocalFontPath as following. You can use following methods to get system folder of fonts or set font path to font folders.

  • Document.getLocalFontPath () - shows the system folder in which project will look for fonts.
  • Document.setLocalFontPath (String) - Setting font path to custom folder
// Set font folder path
String path = "/home/tilal/fonts/";

// Adding a single font directory
// com.aspose.pdf.Document.addLocalFontPath(path);

// Setting the user list for standard font directories
java.util.List list = com.aspose.pdf.Document.getLocalFontPaths();
list.add(path);
com.aspose.pdf.Document.setLocalFontPaths(list);

// ...
// ...

We are sorry for the inconvenience caused.

Best Regards,

I set up the fonts in the Linux and it works.


Thanks a lot for the help!

Hi Ryan,


Thanks for the acknowledgement.

We are pleased to hear that your problem is resolved. Please continue using our API’s and in the event of any further query, please feel free to contact.

Hello Ryan,

I’m facing the exact same issue as yours. I read the solution given here but I’m not able to understand completely how to implement it.
Can you please help me out in this?

Thanks,
Ankit

@baby1307

Thanks for posting your inquiry.

As shared earlier in this thread, PDF to PDF/A conversion requires all necessary fonts installed in your system. In case required font is not installed in your system, you may use document.setLocalFontPath(string) method, in order to set path to the directory where required font is located.

In case you still experience any issue, please share your input document along with sample code snippet and environment details (i.e JDK version, OS, etc.). We will test the scenario in our environment and address it accordingly.