org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage Java Examples
The following examples show how to use
org.apache.pdfbox.pdmodel.graphics.xobject.PDXObjectImage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtractImages.java From bluima with Apache License 2.0 | 6 votes |
@Test public void testPdfBox() throws IOException { File pdfFile = new File(PdfHelper.PDF_TEST_RESOURCES + "pdf/1.pdf"); File outDir = new File("target"); PDDocument document = PDDocument.load(pdfFile); @SuppressWarnings("unchecked") List<PDPage> pages = document.getDocumentCatalog().getAllPages(); int imageId = 0; for (PDPage page : pages) { for (PDXObjectImage img : page.getResources().getImages().values()) { int height = img.getHeight(); int width = img.getWidth(); System.out.println(img.getCOSStream().toString()); img.write2file(new File(outDir, imageId++ + "." + img.getSuffix())); } } }
Example #2
Source File: PDFObjectExtractor.java From pdfxtk with Apache License 2.0 | 6 votes |
/** * TODO: extract byte[] from img and add it to ImageSegment * * @param x1 * @param x2 * @param y1 * @param y2 * @param img */ public void simpleDrawImage(float x1, float x2, float y1, float y2, PDXObjectImage img ) { ImageSegment newImageSegment = new ImageSegment(x1, x2, y1, y2); //(ctm.getXPosition(), ctm.getXPosition() + (float)twh.getX(), //ctm.getYPosition(), ctm.getYPosition() + (float)twh.getY()); ///// System.out.println("adding image segment: " + newImageSegment); newImageSegment.correctNegativeDimensions(); newImageSegment.rotate(page); ///// System.out.println("image before clipping: " + newImageSegment); ///// System.out.println("clipBounds: " + clipBounds); newImageSegment.shrinkBoundingBox(clipBounds); if (!newImageSegment.isZeroSize()) { ///// System.out.println("adding image segment"); imageList.add(newImageSegment); } ///// else System.out.println("not adding image segment"); ///// System.out.println("after rotation: " + newImageSegment); }
Example #3
Source File: CompatibilityHelper.java From pdfbox-layout with MIT License | 5 votes |
public static void drawImage(final BufferedImage image, final PDDocument document, final PDPageContentStream contentStream, Position upperLeft, final float width, final float height) throws IOException { PDXObjectImage cachedImage = getCachedImage(document, image); float x = upperLeft.getX(); float y = upperLeft.getY() - height; contentStream.drawXObject(cachedImage, x, y, width, height); }
Example #4
Source File: CompatibilityHelper.java From pdfbox-layout with MIT License | 5 votes |
private static synchronized Map<BufferedImage, PDXObjectImage> getImageCache( final PDDocument document) { Map<String, Map<?, ?>> documentCache = getDocumentCache(document); @SuppressWarnings("unchecked") Map<BufferedImage, PDXObjectImage> imageCache = (Map<BufferedImage, PDXObjectImage>) documentCache .get(IMAGE_CACHE); if (imageCache == null) { imageCache = new HashMap<BufferedImage, PDXObjectImage>(); documentCache.put(IMAGE_CACHE, imageCache); } return imageCache; }
Example #5
Source File: ReportConvertPdf.java From yuzhouwan with Apache License 2.0 | 5 votes |
private static void drawImageWithScale(PDDocument doc, PDPageContentStream content, String imgPath, int bufferedImageType, float scale) throws IOException { BufferedImage bufferedImage = ImageIO.read(new File(imgPath)); BufferedImage image = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), bufferedImageType); image.createGraphics().drawRenderedImage(bufferedImage, null); PDXObjectImage xImage = new PDPixelMap(doc, image); content.drawXObject(xImage, 100, 100, xImage.getWidth() * scale, xImage.getHeight() * scale); }