Class PdfImage

java.lang.Object
com.codename1.pdf.PdfImage

public final class PdfImage extends Object

An image to draw on a PDF page, built from encoded JPEG or PNG bytes or from ARGB pixels. Works without the UI layer, so a server can use it.

A JPEG is embedded as it is, without decoding. A PNG is decoded and its transparency kept as a soft mask.

PdfDocument doc = new PdfDocument();
PdfCanvas canvas = doc.addPage(PdfPageSize.A4).getCanvas();
PdfImage logo = PdfImage.create(Util.readInputStream(CN.getResourceAsStream("/logo.png")));
canvas.drawImage(logo, 36, 36, 120, 120 * logo.getHeight() / logo.getWidth());
  • Method Details

    • create

      public static PdfImage create(byte[] encoded) throws IOException
      An image from the bytes of a JPEG or PNG file, told apart by their signatures. Throws IOException for any other format.
      Throws:
      IOException
    • create

      public static PdfImage create(int[] argb, int width, int height)
      An image from pixels 0xAARRGGBB, row by row from the top.
    • getWidth

      public int getWidth()
      The width in pixels.
    • getHeight

      public int getHeight()
      The height in pixels.