For the complete documentation index, see llms.txt. This page is also available as Markdown.

Document creation API

Overview

Apryse's document creation framework (the FlowDocument API) lets you generate PDFs without positioning anything on a page. Create a strong foundation for end-to-end PDF creation workflows.

You can:

  • You build a content tree with paragraphs, tables, lists, shapes, charts and floats.

  • You style the elements with familiar word-processor concepts like fonts, colors, indents, justification, borders, tab stops.

  • Apryse SDK paginates the tree into a PDF, breaking content across pages, flowing text around floats, and resolving page numbers.

  • Sections let you mix page sizes, orientations, headers and footers within a single document.

  • It's self-contained, with no external dependencies and no office application required.

This is complementary to template based generation. Use templates when a designer owns the layout in an Office file, and use the document creation API when the document structure itself is computed by your application.

Info

This feature is available to all customers with a Server SDK license and the Template add-on.

Use cases include:

  • Invoice generation at volume: company branding, line-item tables, page numbers, payment information, metadata, and configured page size and margins.

  • Analytics and business reports: structured content, charts or chart-like visual elements, branded headers, landscape pages, and custom page numbering.

  • Contracts and proposals: logos, hyperlinks to terms or support, disclaimers in footers, shapes used as signature placeholders, metadata, and multi-page layout.

  • Statements, dashboards, labels, and other dynamically generated documents produced from operational systems, CRMs, ERPs, billing systems, and reporting tools.

  • OEM teams embedding the SDK in their own product and needing programmatic PDF generation as part of it.

Hello world

Hello world examples with text saying 'hello world.'

That is the whole workflow: create a FlowDocument, append content, call PaginateToPDF, and save the resulting PDFDoc.

Because the result is an ordinary PDFDoc, the rest of the SDK applies to it as usual. You can encrypt it, append other documents, or set its document metadata before saving.

Flow layout vs. fixed layout

The ElementBuilder / ElementWriter API is a fixed layout API. You decide the exact coordinates of every glyph, line and image. The document creation API is a flow layout API:

Fixed layout (ElementBuilder)

Flow layout (FlowDocument)

You specify

Absolute positions

Logical structure

Pagination

Manual

Automatic

Text wrapping

Manual

Automatic

Page numbers

Computed by you

Dynamic elements

Best for

Precise stamping, overlays

Reports, invoices, letters, newsletters

The content tree

Everything you add to a document is a ContentElement. Elements that can contain other elements are ContentNodes, and the subset of nodes that accept paragraphs, tables and lists are ContentContainers.

Key relationships to remember:

  • A FlowDocument is itself a ContentContainer. Content added directly to it goes into the current section.

  • A TableCell is a full ContentContainer, so cells can hold paragraphs, nested tables, and lists.

  • A Shape exposes a ContentContainer through GetTextBox, which turns any shape into a text box.

  • A Float is a ContentContainer that is lifted out of the main flow.

Info

Class names per language. In PHP, the float and list classes are named FloatContainer and ListContainer because float and list are reserved words. In Ruby, the float class is FloatContainer, while the list class stays List. In Objective-C, every class carries a PT prefix, for example, PTFlowDocument and PTParagraph. In JavaScript, the classes live on the PDFNet namespace, for example, PDFNet.FlowDocument.

Styling

Two styling surfaces exist:

  • TextStyledElement : Character level styling (font face, size, bold, italic, text color, background color). Retrieved with GetTextStyledElement from any content element. Setting it on a node applies the style to the content added to that node.

  • Element specific setters: Paragraph indents, spacing and justification, cell borders and alignment, shape geometry and fill, among others.

Conventions

  • All dimensions are in points (1/72 inch). US Letter is 612 x 792, A4 is 595 x 842.

  • Colors are 8-bit RGB triplets in the range [0..255].

  • Fonts are resolved by name through the platform font providers. Prefer widely available families, or ship the fonts you need, so the output is identical across machines.

  • Build, then paginate. PaginateToPDF is the only expensive step; calling it more than once for the same document repeats the whole layout.

  • Generated PDFs carry structure tags, so the output is accessible by construction.

  • Enum spelling differs per language. C++ and Python use Paragraph.e_text_justify_center, C# uses Paragraph.TextJustification.e_center, Java and JavaScript use Paragraph.TextJustification.e_text_justify_center, Go uses ParagraphE_text_justify_center, PHP uses Paragraph::e_text_justify_center, Ruby uses Paragraph::E_text_justify_center, and Objective-C uses e_ptpara_text_justify_center.

  • Every JavaScript call is asynchronous. The Node.js and WebViewer bindings return promises, so each call has to be awaited, including the property getters such as getTextStyledElement.

  • Objective-C renames overloads. AddParagraph(text) becomes AddParagraphWithText:, AddImage(w, h, path) becomes AddImageWithPath:height:image_path:, and SetNumberFormat(format, suffix, cascade) becomes SetNumberFormatWithSuffix:suffix:cascade:.

Document creation options

There are several options available to use when programmatically creating a document.

Page
Contents

Text runs, character styling, justification, indents, tab stops, hyperlinks.

Ordered lists, nesting, number formats, label styling.

Rows and cells, borders, shading, alignment, cell merging, nested content.

Inline images, shape types, text boxes, rotation and flipping.

Positioning content outside the flow and wrapping text around it.

Page setup per section, headers and footers, dynamic page numbers.

Adding charts and sizing them.

Full specification of the chart definition string.

Inspecting and post-processing content before pagination.

Setting the title, author, subject, and keywords of the generated PDF.

Further Reading

Template generation for generating documents from Office templates and JSON data instead.

Last updated

Was this helpful?