@Override public InputStream getData() { if (file != null) { COSStream stream = file.getStream(); if (stream != null) { try { return stream.getUnfilteredStream(); } catch (IOException e) { LOGGER.debug("Error while obtaining unfiltered font stream", e); } } } return null; } }
private List<CosStream> getCIDSet() { PDStream cidSet = getCIDSetStream(); if (cidSet != null) { List<CosStream> res = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); res.add(new PBCosStream(cidSet.getStream(), this.pdDocument, this.flavour)); return Collections.unmodifiableList(res); } return Collections.emptyList(); }
private List<ICCInputProfile> getICCProfile() { PDStream pdStream = ((org.apache.pdfbox.pdmodel.graphics.color.PDICCBased) this.simplePDObject) .getPDStream(); List<ICCInputProfile> inputProfile = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); inputProfile.add(new PBoxICCInputProfile(pdStream.getStream())); return Collections.unmodifiableList(inputProfile); } }
private List<JPEG2000> parseJPXStream() { try { PDStream stream = ((PDImageXObjectProxy) (this.simplePDObject)).getPDStream(); List<COSName> filters = stream.getFilters(); if (filters != null && filters.contains(COSName.JPX_DECODE)) { // TODO: handle the case when jpx stream is additionally hex // encoded try (InputStream image = stream.getStream().getFilteredStream()) { ArrayList<JPEG2000> list = new ArrayList<>(MAX_NUMBER_OF_ELEMENTS); PBoxJPEG2000 jpeg2000 = PBoxJPEG2000.fromStream(image, this.document, this.flavour); this.colorSpaceFromImage = jpeg2000.getImageColorSpace(); list.add(jpeg2000); return Collections.unmodifiableList(list); } } } catch (IOException e) { LOGGER.debug("Problems with stream obtain.", e); } return Collections.emptyList(); }
PDFStreamParser parser = new PDFStreamParser(contents.getStream()); parser.parse(); List tokens = parser.getTokens();
return null; stream.getStream().setInt(COSName.N, nrOfComp); array.add(stream); return new PDICCBased(array);
PDStream contentStream = page.getContents(); if (contentStream != null) { COSStream contents = contentStream.getStream(); processPage(page, contents);
PDFStreamParser parser = new PDFStreamParser(contents.getStream() ); parser.parse(); List tokens = parser.getTokens();
processStream( page, resources, page.getContents().getStream() ); List annotations = page.getAnnotations(); for( int i=0; i<annotations.size(); i++ )
PDDocument document = PDDocument.load("0006-sun1-4.pdf"); List<PDPage> allPages = document.getDocumentCatalog().getAllPages(); PDPage firstPage = allPages.get(0); PDRectangle pageSize = firstPage.findMediaBox(); PDStream contents = firstPage.getContents(); PDFStreamParser parser = new PDFStreamParser(contents.getStream()); parser.parse(); List<Object> tokens = parser.getTokens(); tokens.add(0, PDFOperator.getOperator("q")); tokens.add(PDFOperator.getOperator("Q")); PDStream updatedStream = new PDStream(document); OutputStream out = updatedStream.createOutputStream(); ContentStreamWriter tokenWriter = new ContentStreamWriter(out); tokenWriter.writeTokens(tokens); firstPage.setContents(updatedStream); PDPageContentStream contentStream = new PDPageContentStream(document, firstPage, true, true); contentStream.setStrokingColor(Color.red); contentStream.beginText(); contentStream.moveTextPositionByAmount(300, pageSize.getUpperRightY() - 420 - 10); contentStream.setFont(PDType1Font.HELVETICA_BOLD, 10); contentStream.drawString("MIDDLE"); contentStream.endText(); contentStream.close(); document.save("0006-sun1-4-restoredAdd.pdf"); document.close();
PDPage page = (PDPage) pages.get(i); PDStream contents = page.getContents(); PDFStreamParser parser = new PDFStreamParser(contents.getStream()); parser.parse(); List tokens = parser.getTokens();
/** * Parses a document extracting the images * * @param filename PDF document path */ public void parse(String filename) throws IOException { PDDocument document = null; try { document = PDDocument.load(filename, false); List allPages = document.getDocumentCatalog().getAllPages(); for( int i=0; i<allPages.size(); i++ ) { PDPage page = (PDPage)allPages.get( i ); currentPage = i; processStream( page, page.findResources(), page.getContents().getStream() ); } } finally { if (document != null) { document.close(); } } }
/** * Parses a document extracting the colors for the specified words in * the constructor * * @param filename PDF document path */ public void parse (String filename) throws IOException { PDDocument document = null; try { document = PDDocument.load(filename, false); List allPages = document.getDocumentCatalog().getAllPages(); for( int i=0; i<allPages.size(); i++ ) { PDPage page = (PDPage)allPages.get( i ); PDStream contents = page.getContents(); if (contents != null) { processStream( page, page.getResources(), page.getContents().getStream() ); } } } finally { if (document != null) { document.close(); } } }