Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public final class PdfImage

  1. Object
  2. PdfImage

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());

Methods

public static PdfImage create(byte[] encoded) throws IOExceptionAn image from the bytes of a JPEG or PNG file, told apart by their signatures.
public static PdfImage create(int[] argb, int width, int height)An image from pixels 0xAARRGGBB, row by row from the top.
public int getWidth()The width in pixels.
public int getHeight()The height in pixels.

Inherited methods

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.

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.