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

Generate PDF in Xamarin

Overview

Apryse's office template generation framework enables the dynamic generation of PDFs:

  • You provide a template in the form of an Office document (such as .docx)

  • You provide replacement data in JSON form

  • Apryse SDK will efficiently generate a PDF by merging the data with the template

  • Fully featured, with support for loops, conditionals, images, table generation, etc.

  • Use your preferred office editor to design attractive templates, and Apryse will take care of the rest

  • All logic is entirely contained within the SDK, with no external dependencies

Launch Online Demo

Easy to use

The generation framework requires minimal code to get up and running. Simply initiate a normal Office conversion, but with the optional TemplateParamsJson parameter set:

// Create a TemplateDocument object from an input office file.
TemplateDocument template_doc = Convert.CreateOfficeTemplate(input_path, null);

// Fill the template with data from a JSON string, producing a PDF document.
PDFDoc pdf_doc = template_doc.FillTemplateJson(json_data_string);

// Save the PDF to a file.
pdf_doc.Save(output_path, SDFDoc.SaveOptions.e_linearized);

Sample CodeAPI DocsTemplate Specification

Examples

The following are a series of real examples, generated using the code above. For each example, the template source and the json data source are included below, so that you can try them out yourself.

Simple text replacement (.docx, .json)

Tags in the template document are replaced with a string from the supplied JSON. To control the style of the text, simply modify the style of the template tag as desired:

Automatic reflow (.docx, .json)

Text reflows according to the rules set in the original template file, and will automatically generate extra pages if needed. Make use of column layouts and justification rules. This example uses a list loop with dynamic item renumbering.

Dynamic tables (.docx, .json)

Dynamically insert or remove rows into tables using loops and conditionals. Table formatting such as row bands are updated. Especially useful for invoice generation.

Insert images (.docx, .json)

Insert images into the text at any location using the image_url value specifier. Images can be resized as desired, and inserted at any position in the original document.

Reflow around figures (.docx, .json)

Automatically flow text around obstacles according to the template.

Apryse benefits

  • Securely merge data directly in your application. No need to share confidential data with anyone!

  • Use familiar tools (any word processor such as MS Word or Google Docs) to design professional looking templates with no plugins or extra tools required

  • Top quality PDF generation of your templates with the market leading Apryse SDK

  • Self-contained, with no third-party dependencies

  • Generated PDFs have automatically generated accessibility tags

Further Reading

For more information, see the following resources:

Detailed specification of the template generation data model To find out more details about the specification about the data model

Advanced features For a specification of advanced features, and greater detail on behavior

Live Web Sample To try a live sample of template filling using our WebViewer

Last updated

Was this helpful?