/** * Constructor. * * @param functionStream The function stream. * @throws IOException if an I/O error occurs while reading the function */ public PDFunctionType4(COSBase functionStream) throws IOException { super( functionStream ); byte[] bytes = getPDStream().toByteArray(); String string = new String(bytes, "ISO-8859-1"); this.instructions = InstructionSequenceBuilder.parse(string); }
private byte[] getLookupData() throws IOException { if (lookupData == null) { COSBase lookupTable = array.getObject(3); if (lookupTable instanceof COSString) { lookupData = ((COSString) lookupTable).getBytes(); } else if (lookupTable instanceof COSStream) { lookupData = new PDStream((COSStream)lookupTable).toByteArray(); } else if (lookupTable == null) { lookupData = new byte[0]; } else { throw new IOException("Error: Unknown type for lookup table " + lookupTable); } } return lookupData; }
try bytes = new PDStream(stream).toByteArray();
byte[] bytes = fontFile.toByteArray(); length1 = repairLength1(bytes, length1); length2 = repairLength2(bytes, length1, length2);
/** * Constructor. * * @param functionStream The function stream. * @throws IOException if an I/O error occurs while reading the function */ public PDFunctionType4(COSBase functionStream) throws IOException { super( functionStream ); byte[] bytes = getPDStream().toByteArray(); String string = new String(bytes, "ISO-8859-1"); this.instructions = InstructionSequenceBuilder.parse(string); }
/** * Constructor. * * @param functionStream The function stream. * @throws IOException if an I/O error occurs while reading the function */ public PDFunctionType4(COSBase functionStream) throws IOException { super( functionStream ); byte[] bytes = getPDStream().toByteArray(); String string = new String(bytes, "ISO-8859-1"); this.instructions = InstructionSequenceBuilder.parse(string); }
private byte[] loadTrueTypeFont(PDStream fontFile) throws IOException { // could convert to WOFF though for optimal html output instead. mimeType = "application/x-font-truetype"; fileEnding = "otf"; byte[] fontData = fontFile.toByteArray(); FVFont font = FontVerter.readFont(fontData); byte[] fvFontData = tryNormalizeFVFont(font); if (fvFontData.length != 0) fontData = fvFontData; return fontData; }
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(); }
private byte[] loadOtherTypeFont(PDStream fontFile) throws IOException { // Likley Bare CFF which needs to be converted to a font supported by browsers, can be // other font types which are not yet supported. try { FVFont font = FontVerter.convertFont(fontFile.toByteArray(), FontVerter.FontFormat.WOFF1); mimeType = "application/x-font-woff"; fileEnding = font.getProperties().getFileEnding(); return font.getData(); } catch (Exception ex) { log.error("Issue converting Bare CFF font or the font type is not supportedby Pdf2Dom, " + "Font: {} Exception: {} {}", fontName, ex.getMessage(), ex.getClass()); // don't barf completley for font conversion issue, html will still be useable without. return new byte[0]; } }
private OpenTypeFont buildFromCff() throws IOException { byte[] cffData = type0Font.getFontDescriptor().getFontFile3().toByteArray(); OpenTypeFont otfFont = (OpenTypeFont) FontVerter.convertFont(cffData, FontVerter.FontFormat.OTF); return otfFont; }
private byte[] getLookupData() throws IOException { if (lookupData == null) { COSBase lookupTable = array.getObject(3); if (lookupTable instanceof COSString) { lookupData = ((COSString) lookupTable).getBytes(); } else if (lookupTable instanceof COSStream) { lookupData = new PDStream((COSStream)lookupTable).toByteArray(); } else if (lookupTable == null) { lookupData = new byte[0]; } else { throw new IOException("Error: Unknown type for lookup table " + lookupTable); } } return lookupData; }
private byte[] getLookupData() throws IOException { if (lookupData == null) { COSBase lookupTable = array.getObject(3); if (lookupTable instanceof COSString) { lookupData = ((COSString) lookupTable).getBytes(); } else if (lookupTable instanceof COSStream) { lookupData = new PDStream((COSStream)lookupTable).toByteArray(); } else if (lookupTable == null) { lookupData = new byte[0]; } else { throw new IOException("Error: Unknown type for lookup table " + lookupTable); } } return lookupData; }
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()); }
PDFStreamParser streamParser = new PDFStreamParser(stream.toByteArray()); streamParser.parse(); for (Object token : streamParser.getTokens()) {
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); }
try bytes = new PDStream(stream).toByteArray();
byte[] bytes = fontFile.toByteArray(); length1 = repairLength1(bytes, length1); length2 = repairLength2(bytes, length1, length2);
byte[] bytes = fontFile.toByteArray(); length1 = repairLength1(bytes, length1); length2 = repairLength2(bytes, length1, length2);