diff --git a/ListDocFonts/.idea/runConfigurations/ListFonts.xml b/ListDocFonts/.idea/runConfigurations/ListFonts.xml new file mode 100644 index 0000000..df0c6b1 --- /dev/null +++ b/ListDocFonts/.idea/runConfigurations/ListFonts.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/ListDocFonts/pom.xml b/ListDocFonts/pom.xml new file mode 100644 index 0000000..6e54b4e --- /dev/null +++ b/ListDocFonts/pom.xml @@ -0,0 +1,160 @@ + + + 4.0.0 + com.datalogics.pdfl.samples + ListFonts + 1.0-SNAPSHOT + + 1.8 + 1.8 + + + + Windows64 + + + windows + amd64 + + + + win-x86-64-jni + + + + MacArm + + + mac + aarch64 + + + + mac-arm-64-jni + + + + Linux64 + + + + Linux + amd64 + + + + linux-x86-64-jni + + + + + + com.datalogics.pdfl + pdfl + 18.37.0 + pom + + + com.datalogics.pdfl + pdfl + 18.37.0 + + + com.datalogics.pdfl + pdfl + 18.37.0 + zip + ${jni.classifier} + + + com.datalogics.pdfl + pdfl + 18.37.0 + zip + resources + + + com.datalogics.pdfl + pdfl + 18.37.0 + javadoc + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.0.2 + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack-resources + generate-resources + + unpack + + + + + com.datalogics.pdfl + pdfl + resources + zip + ${project.build.directory}/lib/Resources + + + + + + unpack-jni + generate-resources + + unpack + + + + + com.datalogics.pdfl + pdfl + ${jni.classifier} + zip + ${project.build.directory}/lib + + + + + + + + maven-assembly-plugin + + + package + + single + + + + + + + true + com.datalogics.pdfl.samples.ListDocFonts + + + + jar-with-dependencies + + + + + + diff --git a/ListDocFonts/src/main/java/com/datalogics/pdfl/samples/ListDocFonts.java b/ListDocFonts/src/main/java/com/datalogics/pdfl/samples/ListDocFonts.java new file mode 100644 index 0000000..f2f263f --- /dev/null +++ b/ListDocFonts/src/main/java/com/datalogics/pdfl/samples/ListDocFonts.java @@ -0,0 +1,61 @@ +package com.datalogics.pdfl.samples; + +import com.datalogics.PDFL.*; +import java.util.List; +import java.awt.Font; + +/* + * + * A sample which demonstrates how to list + * the fonts used in a document. + * + * Copyright (c) 2007-2024, Datalogics, Inc. All rights reserved. + * + */ +public class ListDocFonts { + public static void main(String[] args) throws Throwable { + Library lib = new Library(); + + System.out.println("Initialized the library."); + + String sInput = "../../Resources/Sample_Input/sample.pdf"; + + if (args.length > 0) + sInput = args[0]; + + System.out.println("Input file: " + sInput); + + Document doc = new Document(sInput); + + try { + List docFonts = doc.getFonts(0, doc.getNumPages() - 1); + + for (com.datalogics.PDFL.Font font : docFonts) { + System.out.println(font.getName()); + System.out.println("\t"+font.getFullName()); + System.out.println("\t"+font.getType()); + System.out.println("\tFont is" + (font.getEmbedded() ? "" : " not") + " embedded."); + + System.out.println("\t"+font.getEncoding()); + + if (font.getType().equals("Type0") && font.getEmbedded()) { + PDFArray descFontsArray = (PDFArray) font.getPDFDict().get("DescendantFonts"); + PDFDict descFont = (PDFDict) descFontsArray.get(0); + PDFDict fontDescriptor = (PDFDict) descFont.get("FontDescriptor"); + if (fontDescriptor.contains("FontFile2")) { + PDFStream fontStream = (PDFStream) fontDescriptor.get("FontFile2"); + + java.awt.Font f = Font.createFont(Font.TRUETYPE_FONT, fontStream.getFilteredStream()); + + System.out.println("\t\t"+f.getName()); + System.out.println("\t\t"+f.getFontName()); + System.out.println("\t\t"+f.getFamily()); + System.out.println("\t\t"+f.getPSName()); + } + } + } + } finally { + lib.delete(); + } + } +};