Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class PdfExport
- Object
- 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
Inherited methods
Method details
write
public static void write(Document doc, OutputStream out)
throws IOExceptionLays a document out with the standard PDF fonts and writes it.
Parameters
docDocument- the document
outOutputStream- 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 IOExceptionWrites a layout.
Parameters
layoutDocumentLayout- the layout; for the text to fit its lines it should have been made with
fonts fontsPdfMeasurer- the fonts text is drawn in
outOutputStream- 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
layoutDocumentLayout- the layout
fontsPdfMeasurer- the fonts text is drawn in
Returns
the PDF document