/** * Draw an inline image at the x,y coordinates and a certain width and height. * * @param inlineImage The inline image to draw. * @param x The x-coordinate to draw the inline image. * @param y The y-coordinate to draw the inline image. * @param width The width of the inline image to draw. * @param height The height of the inline image to draw. * * @throws IOException If there is an error writing to the stream. * @deprecated Use {@link #drawImage(PDInlineImage, float, float, float, float)} instead. */ @Deprecated public void drawInlineImage(PDInlineImage inlineImage, float x, float y, float width, float height) throws IOException { drawImage(inlineImage, x, y, width, height); }
/** * Draw an inline image at the x,y coordinates, with the default size of the image. * * @param inlineImage The inline image to draw. * @param x The x-coordinate to draw the inline image. * @param y The y-coordinate to draw the inline image. * * @throws IOException If there is an error writing to the stream. * @deprecated Use {@link #drawImage(PDInlineImage, float, float)} instead. */ @Deprecated public void drawInlineImage(PDInlineImage inlineImage, float x, float y) throws IOException { drawImage(inlineImage, x, y, inlineImage.getWidth(), inlineImage.getHeight()); }
PDDocument document = new PDDocument(); InputStream in = new FileInputStream(someImage); BufferedImage bimg = ImageIO.read(in); float width = bimg.getWidth(); float height = bimg.getHeight(); PDPage page = new PDPage(new PDRectangle(width, height)); document.addPage(page); PDXObjectImage img = new PDJpeg(document, new FileInputStream(someImage)); PDPageContentStream contentStream = new PDPageContentStream(document, page); contentStream.drawImage(img, 0, 0); contentStream.close(); in.close(); document.save("test.pdf"); document.close();
contents.drawImage(pdImage, 20, 20);
contentStream.drawImage(pdImage, 20, 20, pdImage.getWidth() * scale, pdImage.getHeight() * scale);
PDPageContentStream contentStream = ...; PDDocument document = ...; InputStream imageStream = this.getClass().getClassLoader().getResourceAsStream("image.jpg"); PDImageXObject image = JPEGFactory.createFromStream(document,imageStream); contentStream.drawImage(image, 50, 700, 250, 67);
PDPageContentStream content = new PDPageContentStream(doc, page); PDXObjectImage ximage = new PDJpeg(doc, bufferedImage); content.drawImage(ximage, x, y);
public void drawImage(PDImageXObject xobject, float x, float y, float w, float h) { try { cs.drawImage(xobject, x, y, w, h); } catch (IOException e) { logAndThrow("drawImage", e); } }
public void drawImage(PDImageXObject xobject, float x, float y, float w, float h) { try { cs.drawImage(xobject, x, y, w, h); } catch (IOException e) { logAndThrow("drawImage", e); } }
public PDRectangle drawImage(final float x, final float y, final float width, final float height, final String resourceImageName) throws IOException, URISyntaxException { final float startingY = checkYAndSwitchPage(y, height); final BufferedImage bufferedImage = ImageIO.read(getClass().getResourceAsStream(resourceImageName)); final PDImageXObject pdImage = LosslessFactory.createFromImage(document, bufferedImage); contentStream.drawImage(pdImage, x, startingY, width, height); return new PDRectangle(x, startingY, width, height); }
/** * Draw an inline image at the x,y coordinates, with the default size of the image. * * @param inlineImage The inline image to draw. * @param x The x-coordinate to draw the inline image. * @param y The y-coordinate to draw the inline image. * * @throws IOException If there is an error writing to the stream. * @deprecated Use {@link #drawImage(PDInlineImage, float, float)} instead. */ @Deprecated public void drawInlineImage(PDInlineImage inlineImage, float x, float y) throws IOException { drawImage(inlineImage, x, y, inlineImage.getWidth(), inlineImage.getHeight()); }
/** * Draw an inline image at the x,y coordinates, with the default size of the image. * * @param inlineImage The inline image to draw. * @param x The x-coordinate to draw the inline image. * @param y The y-coordinate to draw the inline image. * * @throws IOException If there is an error writing to the stream. */ public void drawImage(PDInlineImage inlineImage, float x, float y) throws IOException { drawImage(inlineImage, x, y, inlineImage.getWidth(), inlineImage.getHeight()); }
/** * Draw an image at the x,y coordinates, with the default size of the image. * * @param image The image to draw. * @param x The x-coordinate to draw the image. * @param y The y-coordinate to draw the image. * * @throws IOException If there is an error writing to the stream. */ public void drawImage(PDImageXObject image, float x, float y) throws IOException { drawImage(image, x, y, image.getWidth(), image.getHeight()); }
PDDocument doc = null; doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage(page); try{ BufferedImage awtImage = ImageIO.read( new File( "c://temp//line_chart.png" ) ); PDImageXObject pdImageXObject = LosslessFactory.createFromImage(doc, awtImage); PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, false); contentStream.drawImage(pdImageXObject, 200, 300, awtImage.getWidth() / 2, awtImage.getHeight() / 2); contentStream.close(); doc.save( "c://temp//pdf//PDF_image.pdf" ); doc.close(); } catch (Exception io){ System.out.println(" -- fail --" + io); }
protected void addPicture(PDImageXObject ximage, float cursorX, float cursorY, int width, int height) throws IOException { PDPageContentStream contentStream = new PDPageContentStream(getDocument(), this, true, false); contentStream.drawImage(ximage, cursorX, cursorY, width, height); contentStream.close(); }
cs.transform(Matrix.getScaleInstance(0.25f, 0.25f)); PDImageXObject img = PDImageXObject.createFromFileByExtension(imageFile, doc); cs.drawImage(img, 0, 0); cs.restoreGraphicsState();
PDDocument document = new PDDocument(); PDPage page = new PDPage(); document.addPage(page); PDImageXObject pdi = PDImageXObject.createFromFileByContent(screenshot ,document); PDPageContentStream contentStream = new PDPageContentStream(document, page); contentStream.drawImage(pdi,100,100); contentStream.close(); // do this before saving! document.save("C:/Users/123456/Documents/sample.pdf"); document.close();
protected void addPageToDocument(final PDDocument document, final ImageWithDimension image) throws IOException { PDPage page = new PDPage(new PDRectangle(image.width, image.height)); document.addPage(page); final PDImageXObject imageXObject = LosslessFactory.createFromImage(document, image.bufferedImage); try (PDPageContentStream contentStream = new PDPageContentStream(document, page)) { contentStream.drawImage(imageXObject, 0, 0, image.width, image.height); } }
@Override public void commit(PDPageContentStream stream) throws IOException { // stream.drawImage(png, x, y); XyDim dim = scaledPng.dimensions(); stream.drawImage(png, toFloat(x), toFloat(y), toFloat(dim.x()), toFloat(dim.y())); } }
@Override public void commit(PDPageContentStream stream) throws IOException { // stream.drawImage(jpeg, x, y); XyDim dim = scaledJpeg.dimensions(); stream.drawImage(jpeg, toFloat(x), toFloat(y), toFloat(dim.x()), toFloat(dim.y())); } }