java - Generate PDF files using iText and apache velocity template(.vm) -


What is the common workflow for generating PDFs using iText and Apache velocity template file (.vm) in Java?

I'm interested in knowing the steps like a pars template file, put Java objects in context and steps taken to generate pdf.

I know this is a very basic question but I can not find any such example on the web I found, but I am interested in learning about other options.

Please help me with some sample project links or at least steps to get started.

,

  • Velocity generates plain text content.
  • In other words, velocity can not generate PDF

    XDocReport is capable of generating a docx / odt report by merge into a docx / odt template that includes some velocity / freeware syntax with Java context. The generated docx / odt report can convert it to PDF / XHTML.

    This works because Docs / ODT is a ZIP that has many XML entries, if you open Dock, you will see the word / document.xml. In this entry, you will see the content that you have written with MS Word. Word / document.xml is a plain text, so velocity can be used in this case.

    Here the XDocReport process uses velocity to create a PDF from a DOCX template:

    1. Load docx template. In this stage it is mandatory to open maps and stores in each XML entries (name entry and value in the form of key byte array). For example, the word / document.xml contains a key along with XML content of this entry in the form of value.
    2. Loop for each XML entries that should be merged with Java context. For example, velocity with the word / document.xml Java reference is merged, and as a result of the merging, instead of the word / document.xml value of the map
    3. ziping each entry on the map, a new docx Rebuild.

    On this step we have a generated doc (report).

    To convert it to another format, XDocReport offers a docx-to-pdf converter based on Apache XDocReport process to replace the DOCX for POI and iText PDI:

    1. Load DOCs with Apache POI
    2. Loop (IText paragraph) for each frame of POI (XWPF paragraph, etc.) to create IITEX structure. Note that XDocReport is modular and you can also use other converters.


    Comments