/** * Parses an appearance stream into tokens. */ private List<Object> tokenize(PDAppearanceStream appearanceStream) throws IOException { PDFStreamParser parser = new PDFStreamParser(appearanceStream.getContents()); parser.parse(); return parser.getTokens(); }
/** * Processes the operators of the given content stream. * * @param content the content to parse. * @throws IOException if there is an error reading or parsing the content stream. */ private void processAppearanceStringOperators(byte[] content) throws IOException { List<COSBase> arguments = new ArrayList<>(); PDFStreamParser parser = new PDFStreamParser(content); Object token = parser.parseNextToken(); while (token != null) { if (token instanceof COSObject) { arguments.add(((COSObject) token).getObject()); } else if (token instanceof Operator) { processOperator((Operator) token, arguments); arguments = new ArrayList<>(); } else { arguments.add((COSBase) token); } token = parser.parseNextToken(); } }
private static List<Object> createTokensWithoutText(PDContentStream contentStream) throws IOException PDFStreamParser parser = new PDFStreamParser(contentStream.getContents()); Object token = parser.parseNextToken(); List<Object> newTokens = new ArrayList<>();
/** * Processes the operators of the given content stream. * * @param contentStream to content stream to parse. * @throws IOException if there is an error reading or parsing the content stream. */ private void processStreamOperators(PDContentStream contentStream) throws IOException { List<COSBase> arguments = new ArrayList<>(); PDFStreamParser parser = new PDFStreamParser(contentStream.getContents()); Object token = parser.parseNextToken(); while (token != null) { if (token instanceof COSObject) { arguments.add(((COSObject) token).getObject()); } else if (token instanceof Operator) { processOperator((Operator) token, arguments); arguments = new ArrayList<>(); } else { arguments.add((COSBase) token); } token = parser.parseNextToken(); } }
/** * Get the width from a type3 charproc stream. * * @return the glyph width. * @throws IOException if the stream could not be read, or did not have d0 or d1 as first * operator, or if their first argument was not a number. */ public float getWidth() throws IOException { List<COSBase> arguments = new ArrayList<>(); PDFStreamParser parser = new PDFStreamParser(getContents()); Object token = parser.parseNextToken(); while (token != null) { if (token instanceof COSObject) { arguments.add(((COSObject) token).getObject()); } else if (token instanceof Operator) { return parseWidth((Operator) token, arguments); } else { arguments.add((COSBase) token); } token = parser.parseNextToken(); } throw new IOException("Unexpected end of stream"); }
PDFStreamParser parser = new PDFStreamParser(getContents()); Object token = parser.parseNextToken(); while (token != null)
private PDDocument removeText(PDPage page) throws IOException { PDFStreamParser parser = new PDFStreamParser(page); parser.parse(); List<Object> tokens = parser.getTokens();
private StyledDocument getContentStreamDocument(InputStream inputStream) { StyledDocument docu = new DefaultStyledDocument(); PDFStreamParser parser; try { parser = new PDFStreamParser(IOUtils.toByteArray(inputStream)); parser.parse(); } catch (IOException e) { return null; } for (Object obj : parser.getTokens()) { writeToken(obj, docu); } return docu; }
PDFStreamParser parser = new PDFStreamParser(defaultAppearance.getBytes(Charsets.US_ASCII)); COSArray arguments = new COSArray(); COSArray colors = null;
PDFStreamParser parser = new PDFStreamParser(defaultAppearance.getBytes(Charsets.US_ASCII)); COSArray arguments = new COSArray(); COSArray fontArguments = new COSArray();
/** * Parses an appearance stream into tokens. */ private List<Object> tokenize(PDAppearanceStream appearanceStream) throws IOException { PDFStreamParser parser = new PDFStreamParser(appearanceStream); parser.parse(); return parser.getTokens(); }
/** * Parses an appearance stream into tokens. */ private List<Object> tokenize(PDAppearanceStream appearanceStream) throws IOException { PDFStreamParser parser = new PDFStreamParser(appearanceStream); parser.parse(); return parser.getTokens(); }
/** * Processes the operators of the given content stream. * * @param contentStream to content stream to parse. * @throws IOException if there is an error reading or parsing the content stream. */ private void processStreamOperators(PDContentStream contentStream) throws IOException { List<COSBase> arguments = new ArrayList<COSBase>(); PDFStreamParser parser = new PDFStreamParser(contentStream); Object token = parser.parseNextToken(); while (token != null) { if (token instanceof COSObject) { arguments.add(((COSObject) token).getObject()); } else if (token instanceof Operator) { processOperator((Operator) token, arguments); arguments = new ArrayList<COSBase>(); } else { arguments.add((COSBase) token); } token = parser.parseNextToken(); } }
/** * Processes the operators of the given content stream. * * @param content the content to parse. * @throws IOException if there is an error reading or parsing the content stream. */ private void processAppearanceStringOperators(byte[] content) throws IOException { List<COSBase> arguments = new ArrayList<COSBase>(); PDFStreamParser parser = new PDFStreamParser(content); Object token = parser.parseNextToken(); while (token != null) { if (token instanceof COSObject) { arguments.add(((COSObject) token).getObject()); } else if (token instanceof Operator) { processOperator((Operator) token, arguments); arguments = new ArrayList<COSBase>(); } else { arguments.add((COSBase) token); } token = parser.parseNextToken(); } }
/** * Get the width from a type3 charproc stream. * * @return the glyph width. * @throws IOException if the stream could not be read, or did not have d0 or d1 as first * operator, or if their first argument was not a number. */ public float getWidth() throws IOException { List<COSBase> arguments = new ArrayList<COSBase>(); PDFStreamParser parser = new PDFStreamParser(this); Object token = parser.parseNextToken(); while (token != null) { if (token instanceof COSObject) { arguments.add(((COSObject) token).getObject()); } else if (token instanceof Operator) { return parseWidth((Operator) token, arguments); } else { arguments.add((COSBase) token); } token = parser.parseNextToken(); } throw new IOException("Unexpected end of stream"); }
/** * Processes the operators of the given content stream. * * @param content the content to parse. * @throws IOException if there is an error reading or parsing the content stream. */ private void processAppearanceStringOperators(byte[] content) throws IOException { List<COSBase> arguments = new ArrayList<>(); PDFStreamParser parser = new PDFStreamParser(content); Object token = parser.parseNextToken(); while (token != null) { if (token instanceof COSObject) { arguments.add(((COSObject) token).getObject()); } else if (token instanceof Operator) { processOperator((Operator) token, arguments); arguments = new ArrayList<>(); } else { arguments.add((COSBase) token); } token = parser.parseNextToken(); } }
private static List<Object> createTokensWithoutText(PDContentStream contentStream) throws IOException PDFStreamParser parser = new PDFStreamParser(contentStream); Object token = parser.parseNextToken(); List<Object> newTokens = new ArrayList<Object>();
/** * Get the width from a type3 charproc stream. * * @return the glyph width. * @throws IOException if the stream could not be read, or did not have d0 or d1 as first * operator, or if their first argument was not a number. */ public float getWidth() throws IOException { List<COSBase> arguments = new ArrayList<>(); PDFStreamParser parser = new PDFStreamParser(this); Object token = parser.parseNextToken(); while (token != null) { if (token instanceof COSObject) { arguments.add(((COSObject) token).getObject()); } else if (token instanceof Operator) { return parseWidth((Operator) token, arguments); } else { arguments.add((COSBase) token); } token = parser.parseNextToken(); } throw new IOException("Unexpected end of stream"); }
private void parseOperators() { try { COSStream cStream = this.contentStream.getContentStream(); if (cStream != null) { PDFStreamParser streamParser = new PDFStreamParser( cStream, true); streamParser.parse(); OperatorFactory operatorFactory = new OperatorFactory(); List<Operator> result = operatorFactory.operatorsFromTokens( streamParser.getTokens(), this.resources, this.document, this.flavour); this.containsTransparency = operatorFactory.isLastParsedContainsTransparency(); this.operators = Collections.unmodifiableList(result); } else { this.operators = Collections.emptyList(); } } catch (IOException e) { LOGGER.debug( "Error while parsing content stream. " + e.getMessage(), e); this.operators = Collections.emptyList(); } } }
PDFStreamParser parser = new PDFStreamParser(contentStream); final Clock clock = Clock.systemUTC(); final long startTime = clock.millis();