Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class PdfExport

  1. Object
  2. PdfExport

Writes a laid out document as PDF, page for page as DocumentView shows it.

DocumentModel model = new DocumentModel(new Document());
model.insertBlock(0, new Paragraph(model.newId('p'), RichText.of("Quarterly review")));
PdfMeasurer fonts = new PdfMeasurer();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
    PdfExport.write(new DocumentLayout(model.getDocument(), fonts), fonts, out);
    Log.p("PDF bytes: " + out.size());
} catch (IOException e) {
    Log.e(e);
}

Links become link annotations, tracked insertions are underlined and deletions struck through, and an embedded component is drawn from its snapshot, or as an empty frame when it has none. Pictures other than PNG and JPEG are drawn as frames.

Methods

public static void write(Document doc, OutputStream out) throws IOExceptionLays a document out with the standard PDF fonts and writes it.
public static void write(DocumentLayout layout, PdfMeasurer fonts, OutputStream out) throws IOExceptionWrites a layout.
public static PdfDocument toPdf(DocumentLayout layout, PdfMeasurer fonts)Draws a layout into a new PDF document, for callers that add metadata or pages of their own before saving.

Inherited methods

Method details

write

public static void write(Document doc, OutputStream out) throws IOException
Lays a document out with the standard PDF fonts and writes it.

Parameters

doc Document
the document
out OutputStream
the stream; it is flushed but not closed

Throws

IOException
when the stream fails

write

public static void write(DocumentLayout layout, PdfMeasurer fonts, OutputStream out) throws IOException
Writes a layout.

Parameters

layout DocumentLayout
the layout; for the text to fit its lines it should have been made with fonts
fonts PdfMeasurer
the fonts text is drawn in
out OutputStream
the stream; it is flushed but not closed

Throws

IOException
when the stream fails

toPdf

public static PdfDocument toPdf(DocumentLayout layout, PdfMeasurer fonts)
Draws a layout into a new PDF document, for callers that add metadata or pages of their own before saving.

Parameters

layout DocumentLayout
the layout
fonts PdfMeasurer
the fonts text is drawn in

Returns

the PDF document