Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Sep 30, 2024 8:07 pm

Hi all,

I've developed a Java program that parses various types of PDF files, and it runs fine on my local Windows machine; all the tests pass and all the output is what one would expect. However, when running on a Linux box for CI/CD, I get the following errors, which seem to be repeated for each failed test. The test assertions also fail, because I get unusual output. The common factor seems to be the extractTable() method, and the issue appears to arise from management of fonts and an inability to find a particular class. Since our CI/CD is run headless and my code doesn't do anything with fonts, I'm not sure we need the font management at all.

I'm using the most recent version of Spire.PDF for Java and compiling with Java 17.

Can someone please give me some guidance for how I might be able to resolve this? Any call to extractTable() seems to cause this issue.

EDIT: It appears we resolved this by installing font packages on our CI/CD machine, however this was through a lot of trial and error. Can you please explain which fonts are necessary for extractTable() and why?

jsrcastrogiovanni
 
Posts: 18
Joined: Thu Aug 22, 2024 6:02 pm

Tue Oct 01, 2024 10:03 am

Hello,

Thanks for your inquiry.
Kindly note that when extracting the table, our Spire.PDF will read the font on the system based on the embedded font in the document. If there is no font on the system, an error will be reported.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 757
Joined: Mon Dec 27, 2021 2:23 am

Tue Oct 01, 2024 4:35 pm

Thank you,
Does that mean Spire.PDF requires specific fonts to be on the system in order to read tables correctly? If so, which ones? And, is there a way before calling extractTable() to check whether the necessary fonts are on the system?

jsrcastrogiovanni
 
Posts: 18
Joined: Thu Aug 22, 2024 6:02 pm

Wed Oct 02, 2024 8:37 am

Hello,

Thanks for your reply.
More precisely, the font files embedded in the documents need to be installed on the system in order for the tables to be accurately extracted. The following code is used to obtain embedded fonts in PDF files, which you can use for testing.
Code: Select all
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("test.pdf");
PdfUsedFont[] usedFonts = pdf.UsedFonts;

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 757
Joined: Mon Dec 27, 2021 2:23 am

Fri Oct 04, 2024 6:23 pm

Thank you,
I need some more information, please. Does the getName() method of PdfUsedFont reflect the name of the font on the system? If so, I plan to identify the fonts with something like this:

Code: Select all
  public static void main(String args[]) {
      GraphicsEnvironment g= null;
        g=GraphicsEnvironment.getLocalGraphicsEnvironment();
        String []fonts=g.getAvailableFontFamilyNames();
            for (int i = 0; i < fonts.length; i++) {
            System.out.println(fonts[i]);
            if(fonts[i].equals("YOUR FONT")){
                System.out.println("Found!");
            }
    }


Is that a reasonable approach?

Thanks,
Jessica

jsrcastrogiovanni
 
Posts: 18
Joined: Thu Aug 22, 2024 6:02 pm

Tue Oct 08, 2024 7:27 am

Hello,

Thanks for your feedback.
"PdfUsedFont[] usedFonts = pdfDocument.getUsedFonts();" returns the font files used in the document. You can use the code you provided to identify whether the font is installed in the system.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 757
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.PDF

cron