private void writeFont(PDFontDescriptor fd, String name) throws IOException { if (fd != null) { PDStream ff2Stream = fd.getFontFile2(); if (ff2Stream != null) { System.out.println("Writing font: " + name); try (OutputStream os = new FileOutputStream(new File(name + ".ttf")); InputStream is = ff2Stream.createInputStream()) { IOUtils.copy(is, os); } } } }
protected boolean fontFileNotEmbedded(PDFontDescriptor fontDescriptor) { PDStream ff1 = fontDescriptor.getFontFile(); PDStream ff2 = fontDescriptor.getFontFile2(); PDStream ff3 = fontDescriptor.getFontFile3(); return (ff1 == null && ff2 == null && ff3 == null); }
/** * Return true if the FontDescriptor has only one FontFile entry. * * @param fontDescriptor * @return true if the FontDescriptor has only one FontFile entry. */ protected boolean hasOnlyOneFontFile(PDFontDescriptor fontDescriptor) { PDStream ff1 = fontDescriptor.getFontFile(); PDStream ff2 = fontDescriptor.getFontFile2(); PDStream ff3 = fontDescriptor.getFontFile3(); return (ff1 != null ^ ff2 != null ^ ff3 != null); }
@Override public PDStream extractFontFile(PDFontDescriptor fontDescriptor) { PDStream ff2 = fontDescriptor.getFontFile2(); if (ff2 != null) { // Stream validation should be done by the StreamValidateHelper. Process font specific check COSStream stream = ff2.getCOSObject(); if (stream == null) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile is missing")); this.fContainer.notEmbedded(); } } checkCIDSet(fontDescriptor); return ff2; }
@Override public PDStream extractFontFile(PDFontDescriptor fontDescriptor) { PDStream fontFile = fontDescriptor.getFontFile2(); COSStream stream = (fontFile == null ? null : fontFile.getCOSObject()); if (stream == null) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile2 is missing")); this.fContainer.notEmbedded(); return null; } if (stream.getInt(COSName.LENGTH1) <= 0) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile entry /Length1 is invalid")); return null; } return fontFile; }
PDStream ff2Stream = fd.getFontFile2(); if (ff2Stream != null)
if (fd != null) stream = fd.getFontFile2(); if (stream == null)
protected boolean fontFileNotEmbedded(PDFontDescriptor fontDescriptor) { PDStream ff1 = fontDescriptor.getFontFile(); PDStream ff2 = fontDescriptor.getFontFile2(); PDStream ff3 = fontDescriptor.getFontFile3(); return (ff1 == null && ff2 == null && ff3 == null); }
protected boolean fontFileNotEmbedded(PDFontDescriptor fontDescriptor) { PDStream ff1 = fontDescriptor.getFontFile(); PDStream ff2 = fontDescriptor.getFontFile2(); PDStream ff3 = fontDescriptor.getFontFile3(); return (ff1 == null && ff2 == null && ff3 == null); }
PDFontDescriptorAdapter(PDFontDescriptor descriptor) { this.descriptor = descriptor; file = descriptor.getFontFile(); if (file == null) { file = descriptor.getFontFile2(); } if (file == null) { file = descriptor.getFontFile3(); } }
/** * Return true if the FontDescriptor has only one FontFile entry. * * @param fontDescriptor * @return true if the FontDescriptor has only one FontFile entry. */ protected boolean hasOnlyOneFontFile(PDFontDescriptor fontDescriptor) { PDStream ff1 = fontDescriptor.getFontFile(); PDStream ff2 = fontDescriptor.getFontFile2(); PDStream ff3 = fontDescriptor.getFontFile3(); return (ff1 != null ^ ff2 != null ^ ff3 != null); }
/** * Return true if the FontDescriptor has only one FontFile entry. * * @param fontDescriptor * @return true if the FontDescriptor has only one FontFile entry. */ protected boolean hasOnlyOneFontFile(PDFontDescriptor fontDescriptor) { PDStream ff1 = fontDescriptor.getFontFile(); PDStream ff2 = fontDescriptor.getFontFile2(); PDStream ff3 = fontDescriptor.getFontFile3(); return (ff1 != null ^ ff2 != null ^ ff3 != null); }
private byte[] loadType0TtfDescendantFont() throws IOException { mimeType = "application/x-font-truetype"; fileEnding = "ttf"; try { FVFont font = PdfFontExtractor.convertType0FontToOpenType((PDType0Font) baseFont); byte[] fontData = tryNormalizeFVFont(font); if (fontData.length != 0) return fontData; } catch (Exception ex) { log.warn("Error loading type 0 with ttf descendant font '{}' Message: {} {}", fontName, ex.getMessage(), ex.getClass()); } return descriptor.getFontFile2().toByteArray(); }
public byte[] getData() throws IOException { if (cachedFontData != null) return cachedFontData; if (descriptor.getFontFile2() != null && baseFont instanceof PDType0Font) cachedFontData = loadType0TtfDescendantFont(); else if (descriptor.getFontFile2() != null) cachedFontData = loadTrueTypeFont(descriptor.getFontFile2()); else if (descriptor.getFontFile() != null) cachedFontData = loadType1Font(descriptor.getFontFile()); else if (descriptor.getFontFile3() != null) // FontFile3 docs say any font type besides TTF/OTF or Type 1.. cachedFontData = loadOtherTypeFont(descriptor.getFontFile3()); return cachedFontData; }
private OpenTypeFont getOtfFromDescendantFont(PDCIDFont descendantFont) throws IOException, InstantiationException, IllegalAccessException { if (isTtfDescendant()) { byte[] ttfData = type0Font.getFontDescriptor().getFontFile2().toByteArray(); OpenTypeParser otfParser = new OpenTypeParser(); return otfParser.parse(ttfData); } else if (isCffDescendant()) return buildFromCff(); // don't think descendant can be anything but cff or ttf but just incase throw new IOException("Descendant font type not supported: " + descendantFont.getClass().getSimpleName()); }
private static boolean descendantFontProgramIsNull(PDType0Font font) { org.apache.pdfbox.pdmodel.font.PDCIDFont descendant = font.getDescendantFont(); if(descendant instanceof PDCIDFontType2) { if(descendant.getFontDescriptor() != null) { return descendant.getFontDescriptor().getFontFile3() == null && descendant.getFontDescriptor().getFontFile2() == null; } } else { return descendant.getFontDescriptor().getFontFile3() == null; } return true; }
@Override public PDStream extractFontFile(PDFontDescriptor fontDescriptor) { PDStream ff2 = fontDescriptor.getFontFile2(); if (ff2 != null) { // Stream validation should be done by the StreamValidateHelper. Process font specific check COSStream stream = ff2.getCOSObject(); if (stream == null) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile is missing")); this.fContainer.notEmbedded(); } } checkCIDSet(fontDescriptor); return ff2; }
@Override public PDStream extractFontFile(PDFontDescriptor fontDescriptor) { PDStream ff2 = fontDescriptor.getFontFile2(); if (ff2 != null) { // Stream validation should be done by the StreamValidateHelper. Process font specific check COSStream stream = ff2.getCOSObject(); if (stream == null) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile is missing")); this.fContainer.notEmbedded(); } } checkCIDSet(fontDescriptor); return ff2; }
public static FVFont convertFont(PDFont font, FontFormat format) throws IOException { FVFont readFont = null; if (font instanceof PDTrueTypeFont) { if (font.getFontDescriptor() == null || font.getFontDescriptor().getFontFile2() == null) { log.warn("Skipped font: '{}'. No font file 2 found", font.getName()); return null; } byte[] data = font.getFontDescriptor().getFontFile2().toByteArray(); readFont = FontVerter.readFont(data); } else if (font instanceof PDType0Font) { readFont = convertType0FontToOpenType((PDType0Font) font); readFont.normalize(); } else if (font instanceof PDType1CFont) { byte[] data = font.getFontDescriptor().getFontFile3().toByteArray(); readFont = FontVerter.readFont(data); } else log.warn("Skipped font: '{}'. FontVerter does not support font type: '{}'", font.getName(), font.getType()); if (readFont == null) return null; if (!readFont.isValid()) readFont.normalize(); return FontVerter.convertFont(readFont, format); }
@Override public PDStream extractFontFile(PDFontDescriptor fontDescriptor) { PDStream fontFile = fontDescriptor.getFontFile2(); COSStream stream = (fontFile == null ? null : fontFile.getCOSObject()); if (stream == null) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile2 is missing")); this.fContainer.notEmbedded(); return null; } if (stream.getInt(COSName.LENGTH1) <= 0) { this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile entry /Length1 is invalid")); return null; } return fontFile; }