<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: IgorR</title>
    <description>The latest articles on DEV Community by IgorR (@advicement_sa).</description>
    <link>https://dev.to/advicement_sa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F652809%2F58a3bc14-a07b-4360-8017-966a408a990d.jpg</url>
      <title>DEV Community: IgorR</title>
      <link>https://dev.to/advicement_sa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/advicement_sa"/>
    <language>en</language>
    <item>
      <title>JSON to PDF Magic: Harnessing LaTeX and JSON for Effortless Customization and Dynamic PDF Generation</title>
      <dc:creator>IgorR</dc:creator>
      <pubDate>Mon, 24 Apr 2023 06:59:00 +0000</pubDate>
      <link>https://dev.to/advicement/json-to-pdf-magic-harnessing-latex-and-json-for-effortless-customization-and-dynamic-pdf-generation-2om0</link>
      <guid>https://dev.to/advicement/json-to-pdf-magic-harnessing-latex-and-json-for-effortless-customization-and-dynamic-pdf-generation-2om0</guid>
      <description>&lt;p&gt;In this article, we show how to control the layout and content of the PDF document via the JSON body of the API call with &lt;a href="https://advicement.io/dynamic-documents-api" rel="noopener noreferrer"&gt;DynamicDocs API&lt;/a&gt;. We present three different JSON examples and produce three different types of documents using the same end-point. In each case, making changes to the PDF is done by editing the JSON payload. To do this, we utilise the power of LaTeX to control the layout of the PDF document.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is LaTeX?
&lt;/h2&gt;

&lt;p&gt;LaTeX is a programming language specifically designed for creating PDF documents. Source files in LaTeX have a .tex extension and are usually compiled into PDF format. While it's highly popular in academia for crafting dissertations and scholarly articles, LaTeX is also excellent for producing visually appealing documents. Its strength lies in the separation of content and stylistic rules, allowing for precise control over the document's appearance. However, a significant drawback of LaTeX is the steep learning curve involved in mastering the language for document layout.&lt;/p&gt;

&lt;h2&gt;
  
  
  PDF Generation via JSON to PDF
&lt;/h2&gt;

&lt;p&gt;In many cases, PDF generation requirements change, and developers need to perform additional development by changing the PDF template and then ensuring the new design/changes works as expected. This process can be time-consuming. We introduce a new template called &lt;a href="https://advicement.io/dynamic-documents-api/json-to-pdf-templates/pub-general-json-to-pdf-template-v1" rel="noopener noreferrer"&gt;General JSON to PDF Template&lt;/a&gt; which lets API users change the layout and content in one source, the JSON body of the API call. By simply changing the JSON to create a different output, developers do not need to alter templates. This simplifies the PDF generation process and gives developers an edge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;To get started we will use General JSON to PDF Template end-point:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://api.advicement.io/v1/templates/pub-general-json-to-pdf-template-v1/compile" rel="noopener noreferrer"&gt;https://api.advicement.io/v1/templates/pub-general-json-to-pdf-template-v1/compile&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The corresponding JSON payload structure for the end-point is as follows:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "documentSettings": {
    "font": "roboto",
    "fontSize": 8,
    "primaryHEXColour": "343D49",
    "secondaryHEXColour": "0dbb72",
    "textHEXColour": "444444",
    "documentName": "General JSON to PDF Template from ADVICEment",
    "topMargin": "-0.1cm",
    "rightMargin": "1cm",
    "bottomMargin": "-0.1cm",
    "leftMargin": "1cm",
    "headheight": "3.13cm",
    "headsep": "0.5cm",
    "footskip": "1.5cm",
    "includehead": true,
    "includefoot": true,
    "showframe": true,
    "header": {
      "headerLine": false,
      "leftContent": "",
      "centerContent": "\\begin{tikzpicture}[remember picture,overlay] \\node at ([xshift=0.00cm, yshift=-1.5cm]current page.north) {\\bfseries\\color{black}\\Huge{HEADER}}; \\end{tikzpicture}",
      "rightContent": "",
      "adjustMargin": "1cm"
    },
    "footer": {
      "footerLine": false,
      "leftContent": "",
      "centerContent": "\\begin{tikzpicture}[remember picture,overlay] \\node at ([xshift=0.00cm, yshift=0.75cm]current page.south) {\\bfseries\\color{black}\\Huge{FOOTER}}; \\end{tikzpicture}",
      "rightContent": "",
      "adjustMargin": "1cm"
    },
    "latexPreamble": "\\definecolor{Blue}{HTML}{00FFFF}"
  },
  "documentContent": {
    "content": [
      {
        "type": "latex",
        "content": "Some content here with LaTeX commands",
        "order": 1
      }
      ]
  }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This JSON object contains two main keys: "documentSettings" and "documentContent". It is a configuration file for generating a PDF document using LaTeX, a typesetting system used for creating high-quality documents. The "documentSettings" key describes various settings for the document, such as font, font size, colors, margins, header/footer details, while "documentContent" key describes the layout of the document using LaTeX commands.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"&lt;code&gt;documentSettings&lt;/code&gt;": This key contains an object with properties related to the overall document settings.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;font&lt;/code&gt;": An optional string which contains the font of the document. Possible options are: 'helvetica', 'avant garde', 'sans serif', 'charter', 'open sans', 'bera', 'venturis', 'raleway', 'overlock', 'roboto', 'spectral', 'clear sans', 'noto sans', 'noto mono', 'josefin', 'bera sans', 'latin modern', 'theano modern', 'droid sans', 'fira sans', 'XCharter', 'bookman', 'gyre bonum', 'gyre schola', 'gyre termes'.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;fontSize&lt;/code&gt;": An optional integer which contains the font size of the document. Possible options are: 8, 9, 10, 11, 12, 14.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;primaryHEXColour&lt;/code&gt;", "&lt;code&gt;secondaryHEXColour&lt;/code&gt;", "&lt;code&gt;textHEXColour&lt;/code&gt;": Define the primary, secondary, and text colors using their respective HEX codes.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;documentName&lt;/code&gt;": Sets the document name to "General JSON to PDF Template from ADVICEment".&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;topMargin&lt;/code&gt;", "&lt;code&gt;rightMargin&lt;/code&gt;", "&lt;code&gt;bottomMargin&lt;/code&gt;", "&lt;code&gt;leftMargin&lt;/code&gt;": Define the margins of the document.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;headheight&lt;/code&gt;", "&lt;code&gt;headsep&lt;/code&gt;", "&lt;code&gt;footskip&lt;/code&gt;": Define the header height, header separation, and footer skip values.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;includehead&lt;/code&gt;", "&lt;code&gt;includefoot&lt;/code&gt;": Specify whether to include the header and footer in the document.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;showframe&lt;/code&gt;": Indicates whether to display the frame around the document.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;header&lt;/code&gt;" and "&lt;code&gt;footer&lt;/code&gt;": Define the properties of the header and footer, such as:&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;headerLine&lt;/code&gt;" and "&lt;code&gt;footerLine&lt;/code&gt;": Specify whether to display a line for the header and footer.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;leftContent&lt;/code&gt;", "&lt;code&gt;centerContent&lt;/code&gt;", "&lt;code&gt;rightContent&lt;/code&gt;": Define the content for the left, center, and right parts of the header and footer.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;adjustMargin&lt;/code&gt;": Sets the margin adjustment for the header and footer.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;latexPreamble&lt;/code&gt;": Contains LaTeX commands which are included before '\begin{document}' in the LaTeX file.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;documentContent&lt;/code&gt;": This key contains an object with a "content" property that holds an array of content elements to be included in the document.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;type&lt;/code&gt;": Specifies the content type, in this case, "latex". Possible options are: 'heading', 'section', 'subsection', 'paragraph', 'newpage', 'enumerate', 'itemize', 'kable' and 'chart'.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;content&lt;/code&gt;": Contains the LaTeX-formatted content to be included in the document.&lt;/li&gt;
&lt;li&gt;"&lt;code&gt;order&lt;/code&gt;": Specifies the order in which the content should appear.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In summary, this JSON object defines a configuration for a PDF document created using LaTeX. The document settings include font, font size, colors, margins, header/footer configurations, and a custom color defined in the LaTeX preamble. The document content is specified as an array of elements, each with a type, content, and order.&lt;/p&gt;

&lt;h2&gt;
  
  
  JSON to PDF with Dynamic Images
&lt;/h2&gt;

&lt;p&gt;In this section, we provide an image of the PDF, which contains a dynamic image. This hands-on approach offers valuable insights into the versatility and power of using JSON to control the layout and content of your PDF documents through API calls.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcsyxbz719c2l9f2drx01.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcsyxbz719c2l9f2drx01.jpg" alt="Image of Contract PDF"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The image in the JSON are generated using the \advGetImage function. The JSON component looks as follows:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "documentSettings": {
    "font": "open sans",
    "fontSize": 8,
    "primaryHEXColour": "343D49",
    "secondaryHEXColour": "0dbb72",
    "textHEXColour": "444444",
    "documentName": "Contract Template from ADVICEment",
    "topMargin": "0.5cm",
    "rightMargin": "1cm",
    "bottomMargin": "0.5cm",
    "leftMargin": "1cm",
    "headheight": "1.25cm",
    "headsep": "0.75cm",
    "footskip": "1.0cm",
    "includehead": true,
    "includefoot": true,
    "showframe": false,
    "header": {
      "headerLine": true,
      "leftContent": "",
      "centerContent": "\\advGetImage{key = logo, typeKey=logoType, widthKey = logoWidth}\\medskip",
      "rightContent": ""
    },
    "footer": {
      "footerLine": true,
      "leftContent": "",
      "centerContent": "\\thepage",
      "rightContent": ""
    }
}
....


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;\\advGetImage&lt;/code&gt; function in the JSON file is used to insert images dynamically into the generated PDF. The function appears in the "&lt;code&gt;header&lt;/code&gt;" section of the JSON file, indicating that it is used to display a logo in the header of the PDF document.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;\\advGetImage&lt;/code&gt; function has the following parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;key&lt;/code&gt;: Represents the key to access the image data (base64-encoded string) in the JSON. In this case, the key is "&lt;code&gt;logo&lt;/code&gt;".&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;typeKey&lt;/code&gt;: Represents the key to access the image type (e.g., PNG, JPEG) in the JSON. In this case, the key is "&lt;code&gt;logoType&lt;/code&gt;".&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;widthKey&lt;/code&gt;: Represents the key to access the image width in the JSON. In this case, the key is "&lt;code&gt;logoWidth&lt;/code&gt;".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When the PDF is generated, the &lt;code&gt;\\advGetImage&lt;/code&gt; function retrieves the image data, type, and width from the JSON file using the provided keys. Then, it embeds the image into the PDF document with the specified width, maintaining the aspect ratio of the original image.&lt;/p&gt;

&lt;h2&gt;
  
  
  JSON to PDF with Dynamic Tables
&lt;/h2&gt;

&lt;p&gt;In this section, we provide both an image of the PDF and a part of the corresponding JSON body of the API call used to generate it. As shown below, this PDF contains dynamic tables, which are discussed in this section.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft6ojjfae6ktqhetjalnh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft6ojjfae6ktqhetjalnh.jpg" alt="Image of Invoice PDF"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "documentSettings": {
    "font": "clear sans",
    "fontSize": 8,
    "primaryHEXColour": "343D49",
    "secondaryHEXColour": "0dbb72",
    "textHEXColour": "444444",
    "documentName": "Invoice Template from ADVICEment",
    "topMargin": "0.5cm",
    "rightMargin": "1cm",
    "bottomMargin": "0.5cm",
    "leftMargin": "1cm",
    "headheight": "1.25cm",
    "headsep": "0.75cm",
    "footskip": "1.0cm",
    "includehead": true,
    "includefoot": true,
    "showframe": false,
    "header": {
      "headerLine": true,
      "leftContent": "\\advGetImage{key = logo, typeKey=logoType, widthKey = logoWidth}\\medskip",
      "centerContent": "",
      "rightContent": "\\color{gray} \\Huge Invoice #: 123456789 \\vspace{0.4cm}"
    },
    "footer": {
      "footerLine": true
    },
    "latexPreamble": "\\usepackage{anyfontsize} \\definecolor{Facebook}{HTML}{3B5998} \\definecolor{Twitter}{HTML}{00ACEE}"
  },
  "documentContent": {
    "content": [
      {
        "type": "latex",
        "content": "\\renewcommand{\\arraystretch}{1.5}",
        "order": 0
      },
      {
        "type": "latex",
        "content": "\\begin{multicols}{2}",
        "order": 1
      },
      {
        "type": "kable",
        "content": "kable(data.frame(lapply(params$firstColumnData,latexifyWithCommands)), escape = FALSE, format = 'latex', format.args = list(scientific = FALSE, big.mark = ' '), col.names = c('Invoice Details', ''),  align = c('L{4cm}','R{4cm}'),booktabs = T, bottomrule = '',toprule = '',midrule = '',linesep = '') %&amp;gt;% row_spec(0, bold = T, color = 'white', background = 'Secondary') %&amp;gt;% kable_styling(font_size = 9) %&amp;gt;% stri_replace_all_fixed('\\\\begin{table}', '') %&amp;gt;% stri_replace_all_fixed('\\\\end{table}', '')" ,
        "order": 2
      },
....
  "firstColumnData": [
    {
      "column1": "Invoice Date",      
      "column2": "2023-03-01"
    },
    {
      "column1": "Invoice Issued By",      
      "column2": "Company (Pty) Ltd"
    },
    {
      "column1": "",      
      "column2": ""
    },
    {
      "column1": "On Behalf Of:",      
      "column2": "123 Street"
    },
    {
      "column1": "",      
      "column2": "Cnr Edith Cavell and Kapteijn"
    },
    {
      "column1": "",      
      "column2": "Hillbrow"
    },
    {
      "column1": "",      
      "column2": "Johannebsurg"
    },
    {
      "column1": "",      
      "column2": "South Africa"
    },
    {
      "column1": "",      
      "column2": "2001"
    }
  ]
....


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The dynamic tables in the JSON are generated using the &lt;code&gt;kable&lt;/code&gt; function from the R package &lt;strong&gt;knitr&lt;/strong&gt;. &lt;code&gt;kable&lt;/code&gt;is used to create tables in LaTeX format within the '&lt;code&gt;documentContent&lt;/code&gt;' array.&lt;/p&gt;

&lt;p&gt;For example, the first table is generated with the following code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "type": "kable",
  "content": "kable(data.frame(lapply(params$firstColumnData,latexifyWithCommands)), escape = FALSE, format = 'latex', format.args = list(scientific = FALSE, big.mark = ' '), col.names = c('Invoice Details', ''),  align = c('L{4cm}','R{4cm}'),booktabs = T, bottomrule = '',toprule = '',midrule = '',linesep = '') %&amp;gt;% row_spec(0, bold = T, color = 'white', background = 'Secondary') %&amp;gt;% kable_styling(font_size = 9) %&amp;gt;% stri_replace_all_fixed('\\\\begin{table}', '') %&amp;gt;% stri_replace_all_fixed('\\\\end{table}', '')" ,
  "order": 2
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This code creates a table with two columns, 'Invoice Details' and an empty column header. The table is constructed from the data in '&lt;code&gt;firstColumnData&lt;/code&gt;' in the JSON using &lt;code&gt;params$firstColumnData&lt;/code&gt;. The &lt;code&gt;latexifyWithCommands&lt;/code&gt; function is applied to each element of this list to ensure proper LaTeX formatting.&lt;/p&gt;

&lt;p&gt;Additionally, some table formatting options are set, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;'&lt;code&gt;escape = FALSE&lt;/code&gt;': Prevents escaping of special characters in the table&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;format = 'latex'&lt;/code&gt;: Specifies that the table should be output in LaTeX format&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;align = c('L{4cm}','R{4cm}')&lt;/code&gt;: Sets the alignment of the columns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The table is further styled using the **kableExtra **package. For example, &lt;code&gt;row_spec(0, bold = T, color = 'white', background = 'Secondary')&lt;/code&gt; specifies that the first row should be bold, with white text and a background color defined by '&lt;code&gt;Secondary&lt;/code&gt;'. The table is stripped of the default &lt;code&gt;\\begin{table}&lt;/code&gt; and &lt;code&gt;\\end{table}&lt;/code&gt; LaTeX commands using &lt;code&gt;stri_replace_all_fixed&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A similar process is followed for generating the other tables within the '&lt;code&gt;documentContent&lt;/code&gt;' array, with the corresponding data sources in the JSON ('&lt;code&gt;secondColumnData&lt;/code&gt;', '&lt;code&gt;invoiceDetailsData&lt;/code&gt;') being used to create the content of each table.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For more information on how to use &lt;strong&gt;kable&lt;/strong&gt; and create tables consult the &lt;a href="https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_pdf.pdf" rel="noopener noreferrer"&gt;Create Awesome LaTeX Table with knitr::kable and kableExtra&lt;/a&gt; document.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  JSON to PDF with Dynamic Charts
&lt;/h2&gt;

&lt;p&gt;In this section, we provide both an image of the PDF and a part of the corresponding JSON body of the API call used to generate a report. As shown below, this PDF contains dynamic charts, which are discussed in this section.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fopccpk5jvhx752fkyq3a.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fopccpk5jvhx752fkyq3a.jpg" alt="Image of Report PDF"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "documentSettings": {
    "font": "roboto",
    "fontSize": 8,
    "primaryHEXColour": "343D49",
    "secondaryHEXColour": "0dbb72",
    "textHEXColour": "444444",
    "documentName": "Report Template from ADVICEment",
    "topMargin": "-0.1cm",
    "rightMargin": "1cm",
    "bottomMargin": "-0.1cm",
    "leftMargin": "1cm",
    "headheight": "3.13cm",
    "headsep": "0.5cm",
    "footskip": "1.5cm",
    "includehead": true,
    "includefoot": true,
    "showframe": false,
    "header": {
      "headerLine": false,
      "leftContent": "\\begin{tikzpicture} \\node (rectange) [rectangle, shading = axis, shading angle=135, left color=Primary, right color=Secondary, anchor=south west, inner sep=0,outer sep =0, fill = Primary, minimum width = 21cm,  minimum height = 3.0cm] at ([xshift=0.0cm, yshift=0cm]current page.north west)  {}; \\node[right] at ([xshift=0.90cm, yshift=-0.9cm]rectange.north west) {\\bfseries\\color{white}\\huge{Report Template by ADVICEment}}; \\node[right] at ([xshift=0.90cm, yshift=-1.675cm]rectange.north west) {\\color{white}\\LARGE April 2023}; \\node (subtitle) [minimum width=11cm, anchor=north west, text width=11cm, inner sep=0.0cm, outer sep=0] at ([xshift=1.00cm, yshift=-2.25cm]rectange.north west) {\\color{white}\\normalsize\\bfseries{Best Dynamic PDF Generation} }; \\node (logo) [left] at ([xshift=-0.99cm, yshift=-1.5cm]rectange.north east) {\\advGetImage{key = logo, typeKey=logoType, widthKey = logoWidth}}; \\end{tikzpicture}",
      "centerContent": "",
      "rightContent": "",
      "adjustMargin": "1cm"
    },
    "footer": {
      "footerLine": false,
      "leftContent": "\\begin{tikzpicture} \\node (rectange) [rectangle, shading = axis, shading angle=135, left color=Primary, right color=Secondary, anchor=south west, inner sep=0,outer sep =0, fill = Primary, minimum width = 21cm,  minimum height = 1.0cm] at ([xshift=0.0cm, yshift=0cm]current page.south west)  {}; \\node[right] at ([xshift=0.90cm, yshift=0.5cm]rectange.south west) {\\bfseries\\color{white}\\tiny{Legal notice goes here and other fun things}}; \\end{tikzpicture}",
      "centerContent": "",
      "rightContent": "",
      "adjustMargin": "1cm"
    },
    "latexPreamble": " \\usepackage{lipsum} \\usepackage{paracol}"
  },
  "documentContent": {
    "content": [
      {
        "type": "latex",
        "content": "\\sloppy",
        "order": 1
      },
      {
        "type": "latex",
        "content": "\\columnratio{0.65,0.35} \\begin{paracol}{2} \\begin{leftcolumn}",
        "order": 2
      },
      {
        "type": "section",
        "content": "Description",
        "order": 3
      },
      {
        "type": "paragraph",
        "content": "\\lipsum[1]",
        "order": 4
      },
      {
        "type": "section",
        "content": "Cumulative Chart",
        "order": 5
      },
      {
        "type": "chart",
        "content": "ggplot(data=params$performanceGraph)+geom_line(aes(x=as.Date(Date), y=CumulativeBenchmarkReturn, color =' Benchmark ' ), linetype='solid', size=1)+geom_line(aes(x=as.Date(Date), y=CumulativeFundReturn, color =' Fund '), linetype='solid', size=1)+scale_colour_manual(breaks = c(' Fund ',' Benchmark '), values=c('#343D49','#0dbb72')) +theme_economist()+theme(panel.background = element_rect(fill = '#FFFFFF', colour = '#FFFFFF'),plot.background = element_rect(fill = '#FFFFFF', colour = '#FFFFFF'),axis.title.x=element_blank()) +theme(panel.grid.major = element_line(colour = '#A7A8AA', size=0.5))+theme(panel.grid.minor = element_blank())+theme(axis.line = element_line(colour = '#A7A8AA', size = 0.5)) +theme(axis.text = element_text(size = 12, colour = '#28334A'))+theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) +theme(axis.ticks.x = element_line(colour = '#A7A8AA', size = 0.5))+theme(legend.position='bottom', legend.title=element_blank(),legend.background=element_rect(fill = '#FFFFFF', colour = '#FFFFFF'))+ theme(legend.text=element_text(size=16,color='#58595b'))+theme(legend.key = element_rect(fill = 'white'))+theme(axis.title.y=element_text(colour = '#28334A',size=12,margin=unit(c(0,0.2,0,0.2),units='cm'))) +theme(axis.title.y = element_blank()) +theme(legend.spacing=unit(0.1, units = 'cm'),legend.margin=margin(t = 0.1, unit='cm')) +scale_x_date(breaks = seq(as.Date('2004-06-30'), as.Date('2050-06-30'), by='6 months'), labels=date_format('%b-%Y'), expand = c(0.1, 0.1))+scale_y_continuous(breaks = pretty(c(params$performanceGraph$CumulativeFundReturn,params$performanceGraph$CumulativeBenchmarkReturn),n=8),labels=dollar_format(prefix='',big.mark = ' '))",
        "order": 5,
        "height": 4,
        "width": 10
      }
....
  "performanceGraph":   [
      {
        "Date":  "2017-11-30",
        "Benchmark":  -0.97267,
        "Fund":  -0.63828,
        "CumulativeFundReturn":  100,
        "CumulativeBenchmarkReturn":  100
      },
      {
        "Date":  "2017-12-31",
        "Benchmark":  5.65561,
        "Fund":  5.48700,
        "CumulativeFundReturn":  111.874435153,
        "CumulativeBenchmarkReturn":  109.896525389
      },
      {
        "Date":  "2018-01-31",
        "Benchmark":  1.85912,
        "Fund":  1.93257,
        "CumulativeFundReturn":  114.036486924,
        "CumulativeBenchmarkReturn":  111.939633672
      },
      {
        "Date":  "2018-02-28",
        "Benchmark":  3.93107,
        "Fund":  4.04714,
        "CumulativeFundReturn":  118.651703201,
        "CumulativeBenchmarkReturn":  116.340059029
      }
....


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;There are two charts being created in the PDF document. These charts are generated using the R package &lt;strong&gt;ggplot2&lt;/strong&gt;, and their code is provided within the JSON. The charts are part of the document content and are represented as objects with the "&lt;code&gt;type&lt;/code&gt;": "&lt;code&gt;chart&lt;/code&gt;" key-value pair.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cumulative Chart
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "type": "chart",
  "content": "ggplot(data=params$performanceGraph)+geom_line(aes(x=as.Date(Date), y=CumulativeBenchmarkReturn, color =' Benchmark ' ), linetype='solid', size=1)+geom_line(aes(x=as.Date(Date), y=CumulativeFundReturn, color =' Fund '), linetype='solid', size=1)+scale_colour_manual(breaks = c(' Fund ',' Benchmark '), values=c('#343D49','#0dbb72')) +theme_economist()+theme(panel.background = element_rect(fill = '#FFFFFF', colour = '#FFFFFF'),plot.background = element_rect(fill = '#FFFFFF', colour = '#FFFFFF'),axis.title.x=element_blank()) +theme(panel.grid.major = element_line(colour = '#A7A8AA', size=0.5))+theme(panel.grid.minor = element_blank())+theme(axis.line = element_line(colour = '#A7A8AA', size = 0.5)) +theme(axis.text = element_text(size = 12, colour = '#28334A'))+theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) +theme(axis.ticks.x = element_line(colour = '#A7A8AA', size = 0.5))+theme(legend.position='bottom', legend.title=element_blank(),legend.background=element_rect(fill = '#FFFFFF', colour = '#FFFFFF'))+ theme(legend.text=element_text(size=16,color='#58595b'))+theme(legend.key = element_rect(fill = 'white'))+theme(axis.title.y=element_text(colour = '#28334A',size=12,margin=unit(c(0,0.2,0,0.2),units='cm'))) +theme(axis.title.y = element_blank()) +theme(legend.spacing=unit(0.1, units = 'cm'),legend.margin=margin(t = 0.1, unit='cm')) +scale_x_date(breaks = seq(as.Date('2004-06-30'), as.Date('2050-06-30'), by='6 months'), labels=date_format('%b-%Y'), expand = c(0.1, 0.1))+scale_y_continuous(breaks = pretty(c(params$performanceGraph$CumulativeFundReturn,params$performanceGraph$CumulativeBenchmarkReturn),n=8),labels=dollar_format(prefix='',big.mark = ' '))",
  "order": 5,
  "height": 4,
  "width": 10
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This chart is a line chart showing the Cumulative Benchmark Return and the Cumulative Fund Return. The code for this chart is provided in the "&lt;code&gt;content&lt;/code&gt;" field as a &lt;strong&gt;ggplot2&lt;/strong&gt; expression. The chart's dimensions are set with the "&lt;code&gt;height&lt;/code&gt;" and "&lt;code&gt;width&lt;/code&gt;" fields, measuring 4 units high and 10 units wide.&lt;/p&gt;

&lt;h3&gt;
  
  
  Asset Allocation Chart
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "type": "chart",
  "content": "ggplot(params$assetAllocationChart,aes(x = factor(Name, levels = params$assetAllocationChart$Name), y = Weight))+geom_bar(stat='identity', position=position_dodge(width=1), width = 0.75, fill = '#0dbb72')+geom_label(aes(label = Label), fill = 'white', colour = 'black', position= position_dodge(width=1), size = 5) +theme_economist()+scale_colour_economist()+theme(legend.position='bottom')+theme(legend.position='bottom', legend.direction = 'horizontal', legend.title=element_blank(),legend.background=element_rect(fill = '#FFFFFF', colour = '#FFFFFF'),legend.box.background=element_rect(fill = '#FFFFFF', colour = '#FFFFFF'),legend.key=element_rect(fill = '#FFFFFF', colour = '#FFFFFF'))+theme(legend.text=element_text(size=12,color='#2D2323',face='plain'))+guides(fill = guide_legend(nrow = 1))+theme(panel.background = element_rect(fill = '#FFFFFF', colour = '#FFFFFF'),plot.background = element_rect(fill = '#FFFFFF', colour = '#FFFFFF')) +theme(panel.grid.major = element_line(colour = 'lightgrey', size=0.5))+theme(panel.grid.minor = element_blank())+theme(axis.title.x=element_blank()) +theme(axis.title.y=element_text(colour = '#2D2323',size=12,margin=unit(c(0.0,0.25,0.0,0.25),units='cm'))) +theme(legend.spacing.x = unit(0.1, 'cm'))+theme(axis.text = element_text(size=12,color='#2D2323', face='plain'))+theme(axis.title = element_text(size=12,color='#2D2323', face='plain'))+scale_y_continuous(breaks = pretty(c(params$assetAllocationChart$Weight),n=6),labels=percent_format(accuracy = 0.1))+labs(y='Weight')+coord_cartesian(clip = 'off')",
  "order": 7,
  "height": 3.5,
  "width": 10
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This chart is a bar chart displaying the weight of each asset in the portfolio. The &lt;strong&gt;ggplot2&lt;/strong&gt; code for generating this chart is provided in the "content" field. The chart's dimensions are set with the "&lt;code&gt;height&lt;/code&gt;" and "&lt;code&gt;width&lt;/code&gt;" fields, measuring 3.5 units high and 10 units wide.&lt;/p&gt;

&lt;p&gt;Once the R code for generating these charts is executed, the resulting chart images are incorporated into the PDF document as specified by their respective order in the "&lt;code&gt;documentContent&lt;/code&gt;" section of the JSON data.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;For more information on how to use &lt;strong&gt;ggplot2&lt;/strong&gt; and create charts consult the &lt;a href="https://ggplot2.tidyverse.org/" rel="noopener noreferrer"&gt;ggplot2 official page&lt;/a&gt; or the &lt;a href="https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf" rel="noopener noreferrer"&gt;ggplot2 cheat graphic&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Data and Layout Separation
&lt;/h2&gt;

&lt;p&gt;In the aforementioned examples, it is crucial to recognize that the table and chart data reside independently from the PDF layout within the JSON. This distinction is significant as it allows for seamless updates to the document's underlying data in the JSON, automatically reflecting the changes within the document. This approach offers considerable benefits for developers tasked with PDF generation, streamlining their workflow and enhancing efficiency.&lt;/p&gt;

&lt;h2&gt;
  
  
  General JSON to PDF Postman Collection
&lt;/h2&gt;

&lt;p&gt;To make it easier to test the General JSON to PDF Endpoint, we've provided a ready-to-use Postman collection. This allows you to generate the PDFs mentioned above with ease. Feel free to use the link below to access the collection and explore its features, or even fork the collection to customize it according to your needs.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://www.postman.com/advicement/workspace/dynamicdocs-api-public-workspace/collection/8428379-43ff3fab-fe32-4fb9-9cfb-9140077c51f3" rel="noopener noreferrer"&gt;Postman Collection&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Harnessing LaTeX and JSON for Effortless Customization
&lt;/h2&gt;

&lt;p&gt;In conclusion, this article has demonstrated the versatility and efficiency of using JSON in conjunction with LaTeX to generate PDF documents through API calls. By showcasing three distinct examples, we have illustrated the ease of adapting the layout and content of PDFs by simply modifying the JSON payload. LaTeX, while possessing a steep learning curve, offers unparalleled control over the appearance and structure of documents. The &lt;a href="https://advicement.io/dynamic-documents-api/json-to-pdf-templates/pub-general-json-to-pdf-template-v1" rel="noopener noreferrer"&gt;General JSON to PDF Template&lt;/a&gt; introduced in this article streamlines the PDF generation process by allowing developers to make layout and content changes within the JSON body of the API call, eliminating the need to modify templates. This innovative approach saves time, reduces complexity, and enhances the developer experience in creating professional and aesthetically pleasing PDF documents.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>productivity</category>
      <category>api</category>
      <category>automation</category>
    </item>
    <item>
      <title>5 Advantages of Using LaTeX API for PDF Generation</title>
      <dc:creator>IgorR</dc:creator>
      <pubDate>Thu, 27 Oct 2022 20:29:05 +0000</pubDate>
      <link>https://dev.to/advicement/5-advantages-of-using-latex-api-for-pdf-generation-3lk7</link>
      <guid>https://dev.to/advicement/5-advantages-of-using-latex-api-for-pdf-generation-3lk7</guid>
      <description>&lt;p&gt;DynamicDocs is an innovative &lt;a href="https://advicement.io/dynamic-documents-api"&gt;LaTeX to PDF API&lt;/a&gt; utilising LaTeX and serverless computing for PDF generation. The API has been developed to create dynamic PDF documents containing dynamic text, tables and charts.&lt;/p&gt;

&lt;p&gt;LaTeX is a popular document preparation software (for high-quality typesetting) used to create PDF documents using files with a tex extension. One of the reasons for its immense popularity is that LaTeX enables authors to write extensive documents in a markup language. This concept appeals well to users looking to generate documents in high-quality with full customisation.&lt;/p&gt;

&lt;p&gt;DynamicDocs API is particularly useful in the following cases to generate documents:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://advicement.io/dynamic-documents-api"&gt;Generate PDFs&lt;/a&gt; in bulk via API requests.&lt;/li&gt;
&lt;li&gt;Edit &lt;a href="https://advicement.io/dynamic-documents-api/template-examples"&gt;LaTeX templates&lt;/a&gt; and enhance your documents with dynamic data, tables and charts.&lt;/li&gt;
&lt;li&gt;Use existing &lt;a href="https://advicement.io/dynamic-documents-api/json-to-pdf-templates"&gt;JSON to PDF templates&lt;/a&gt; (which require no knowledge of LaTeX).&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://advicement.io/dynamic-documents-api/json-to-pdf-templates?type=tex+to+pdf"&gt;Convert Tex to PDF&lt;/a&gt; with a full library of LaTeX packages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The use cases above centre around using LaTeX for &lt;a href="https://advicement.io/dynamic-documents-api"&gt;PDF generation&lt;/a&gt;. This article presents five advantages of using the DynamicDocs API to generate documents through LaTeX instead of the more common HTML to PDF approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of Using LaTeX to PDF API
&lt;/h2&gt;

&lt;h3&gt;
  
  
  High-Quality PDF Documents
&lt;/h3&gt;

&lt;p&gt;One of the most useful features of LaTeX is its excellent job at typesetting. LaTeX complies with various built-in algorithms to achieve the optimal layout of the document. Its typesetting algorithms are highly refined as LaTeX uses scaled points as a measurement which results in profoundly accurate pdf generation. Editing and reformatting a LaTeX document is much easier than working with large Word documents. The document snippets can be easily moved and rested in the document allowing greater flexibility without disturbing the overall layout of the document.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dynamic PDF Documents with JSON Payload
&lt;/h3&gt;

&lt;p&gt;The different templates offered by DynamicDocs API can perform calculations and be truly dynamic by including dynamic data, tables and charts. The output document is optimised for display with high quality, dynamic content and client branding. Special commands allow developers to convert the data in the JSON payload into formatted text, tables which can span pages and beautiful charts, all based on the data sent to the API.&lt;/p&gt;

&lt;h3&gt;
  
  
  Modularity of LaTeX
&lt;/h3&gt;

&lt;p&gt;LaTeX is inherently modular, meaning that you can break the document into two distinct parts: the content part, which controls the input of the document and the styling part, which contains macros and functions governing the look and feel. This is a powerful feature of LaTeX as it allows users to step away from styling each element and instead write overall rules. The LaTeX macros and functions from different packages can be loaded into the document, and some have been in development for many years. Their documentation is widely available on &lt;a href="https://ctan.org/"&gt;CTAN&lt;/a&gt; (The Comprehensive TEX Archive Network). The numerous packages benefit users using LaTeX as they can rely on previous work, and there is no need to reinvent the wheel. For example, the &lt;a href="https://ctan.org/pkg/fancyhdr"&gt;fancyhdr package&lt;/a&gt; provides powerful methods of defining headers and footers on every page in the document. Using CSS to style the document's headers and footers for HTML to PDF generation will take much more time and effort.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fast Implementation
&lt;/h3&gt;

&lt;p&gt;The business benefit of DynamicDocs API is that it significantly reduces development time through quick API integration and avoids long document generation development cycles. This is true when compared to the deployment of a stand-alone PDF-generating solution. The API enables any application to get additional transactional PDF functionality, typically associated with established enterprises. The developers do not need to worry about building or deploying new servers as part of the publishing process. &lt;a href="https://www.postman.com/advicement/workspace/2cee92d9-3594-48c6-90d9-8c985e40f60e/api/14ffeb81-3857-4c05-b8d1-7bd117b2601f"&gt;DynamicDocs API call examples&lt;/a&gt; are available as a Postman collection and can be examined immediately or once the integration is required.&lt;/p&gt;

&lt;h3&gt;
  
  
  Document Size and Security
&lt;/h3&gt;

&lt;p&gt;The compressibility of documents produced through LaTeX allows for much smaller documents in size when compared to standard PDF documents produced from HTML. This is a tremendous advantage for transactional documents that are generated in bulk and then sent via email. Furthermore, DynamicDocs API offers various PDF encryption algorithms, offering an additional layer of security for applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  The downside of HTML to PDF Generation
&lt;/h2&gt;

&lt;p&gt;HTML to PDF is a popular approach for PDF Generation&lt;br&gt;
HTML (hypertext markup language) is the coding language commonly used to create the structure of web pages, but it can also be used to create PDFs through HTML to PDF converters. Although HTML is exceptionally popular for rendering websites, LaTeX is a more optimal tool for PDF creation.&lt;/p&gt;

&lt;p&gt;Firstly, unlike LaTeX, HTML relies heavily on CSS (cascading style sheets) to control the layout of the documents. This reliance on CSS is one of its disadvantages. Common tasks like creating headers and footers that span documents become complicated when using CSS (unless you are a CSS wizard). The HTML to PDF approach also becomes time-consuming, styling each element and creating tables which span multiple pages. Lastly, creating charts with HTML to PDF relies on external Javascript libraries, which, for the most part, are built to render in browsers instead of documents, which can complicate the HTML to PDF approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Remarks
&lt;/h2&gt;

&lt;p&gt;Using LaTeX is a different but optimal approach for document generation that looks past the complexity of HTML and CSS. LaTeX is designed to do exactly one thing: generate high-quality PDF documents. The dynamic documentation structure helps users start writing documents faster with the flexibility of numerous packages available.&lt;/p&gt;

&lt;p&gt;On the other hand, LaTeX does have a steep learning curve (unless you are from academia, where it is exceptionally popular). The scientific community has built a steady infrastructure around LaTeX, with almost every publisher providing LaTeX guidelines and templates for their papers. Its wide adoption in academia shows its growing popularity due to its unique features.&lt;/p&gt;

&lt;p&gt;For those looking for tools to get LaTeX quality output in your PDF generation, &lt;a href="https://advicement.io/dynamic-documents-api"&gt;DynamicDocs API&lt;/a&gt; is the perfect place to start!&lt;/p&gt;

</description>
      <category>api</category>
      <category>pdf</category>
      <category>productivity</category>
      <category>showdev</category>
    </item>
    <item>
      <title>How to convert Tex to PDF with a LaTeX API</title>
      <dc:creator>IgorR</dc:creator>
      <pubDate>Tue, 18 Oct 2022 12:53:42 +0000</pubDate>
      <link>https://dev.to/advicement/how-to-convert-tex-to-pdf-with-a-latex-api-49ll</link>
      <guid>https://dev.to/advicement/how-to-convert-tex-to-pdf-with-a-latex-api-49ll</guid>
      <description>&lt;p&gt;The modern approach to API development is often associated with the use of the cloud. Therefore, it has become increasingly important to present novel ideas capable of improving users' and developers' digital experiences.&lt;/p&gt;

&lt;p&gt;With that in mind, the &lt;a href="https://advicement.io/dynamic-documents-api"&gt;DynamicDocs API&lt;/a&gt; approach to PDF generation is to use LaTeX, a language that is designed for high-quality typesetting.&lt;/p&gt;

&lt;p&gt;The DynamicDocs API provides an alternative to deploying a stand-alone PDF-generating solution for startups and enterprises. The API approach allows developers to test the solution quickly via Postman and generate large amounts of PDF documents, while incorporating graphics and logic into the templates.&lt;/p&gt;

&lt;p&gt;In this article, we present a specific type of &lt;a href="https://advicement.io/blog/pdf-generation-made-easy-using-ready-made-templates-and-json-to-pdf-api"&gt;JSON to PDF&lt;/a&gt; template called &lt;a href="https://advicement.io/dynamic-documents-api/json-to-pdf-templates?type=tex+to+pdf"&gt;TEX to PDF&lt;/a&gt;, which allows users to send their LaTeX source file and compile it via the API.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is LaTeX?
&lt;/h2&gt;

&lt;p&gt;LaTeX is a computer language used for document preparation, specifically PDF generation. LaTeX source files have a Tex extension and are typically compiled into PDFs. Although it is very popular in academia, where it is used for dissertations and journal articles, the language lends itself well to creating great-looking documents in general.&lt;/p&gt;

&lt;p&gt;One of its advantages is the separation of document content and the rules governing the look and feel of the document. A notable disadvantage of LaTeX is that the learning curve for writing the rules of the document layout can be steep and require a significant investment in time for the user.&lt;/p&gt;

&lt;p&gt;To circumvent this, DynamicDocs API has a library of ready-made PDF to JSON templates that do not require any knowledge of LaTeX. However, this article assumes that you already have a working Tex file that needs to be compiled.&lt;/p&gt;

&lt;h2&gt;
  
  
  LaTeX Compilers
&lt;/h2&gt;

&lt;p&gt;To convert LaTeX source files into PDFs, one needs a compiler. DynamicDocs API offers two compilers, namely pdfLaTeX and LuaLaTeX.&lt;/p&gt;

&lt;p&gt;Tex to PDF Template range consists of two general templates allowing users to upload their own tex file and optionally include Base64 encoded images in the JSON payload.&lt;/p&gt;

&lt;p&gt;The templates correspond to the two compilers available. For more information on calling the two templates, visit &lt;a href="https://advicement.io/dynamic-documents-api/json-to-pdf-templates/pub-tex-to-pdf-with-pdflatex-v1"&gt;Tex to PDF with pdfLaTeX&lt;/a&gt; Template and &lt;a href="https://advicement.io/dynamic-documents-api/json-to-pdf-templates/pub-tex-to-pdf-with-lualatex-v1"&gt;Tex to PDF with LuaLaTeX&lt;/a&gt; Template.&lt;/p&gt;

&lt;p&gt;Let's now look at the case when it makes sense to use TEX to PDF conversion with an API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Considerations for TEX to PDF with DynamicDocs API
&lt;/h2&gt;

&lt;p&gt;The following list explains the criteria for when using DynamicDocs API makes sense for TEX to PDF conversion:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need to generate several PDF documents and want to do it programmatically.&lt;/li&gt;
&lt;li&gt;You have (or can create) a Tex file that can be adjusted with the dynamic data.&lt;/li&gt;
&lt;li&gt;You can make a POST request to the API with your TeX file formatted as JSON.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If any of those points do not apply to your use case, you will likely be better off using a simple &lt;a href="https://www.freefileconvert.com/tex-pdf"&gt;online Tex to PDF converter&lt;/a&gt; or &lt;a href="https://www.overleaf.com/"&gt;Overleaf&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tutorial to Convert TEX to PDF with DynamicDocs API
&lt;/h2&gt;

&lt;p&gt;Consider a situation where you have to create PDF name tags where the underlying data is stored in the system and can be accessed programmatically. The aim is to create a PDF document that looks as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---zJ5OA_N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7552g13tmicqp8fvzqz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---zJ5OA_N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7552g13tmicqp8fvzqz.png" alt="Name Tag Example" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get started with DynamicDocs API, you will need to &lt;a href="https://advicement.io/sign-up"&gt;sign up&lt;/a&gt; for an account with ADVICEment. Without needing to give bank card information, the new accounts are automatically set up with a FREE plan which offers a limited number of API calls. Once the account email address is confirmed, users can log in and access the Dashboard, where they can get their account API key.&lt;/p&gt;

&lt;p&gt;We are now almost ready to make the API call. To create the PDF document above, we have written the following Tex file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\documentclass[10pt]{article}

\usepackage[paperheight=3in, paperwidth=4in, left=0mm, right=0mm, top=0mm, bottom=0mm, noheadfoot]{geometry}
\usepackage[T1]{fontenc}
\usepackage[sfdefault,lf]{carlito}
\usepackage{graphicx}
\usepackage{ragged2e}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[none]{hyphenat}

%%%%%%%%%%%%%%%%%%%%%%% content definition %%%%%%%%%%%%%%%%%%%%%%%
\makeatletter\let\thetitle\@title\makeatother
\usepackage[pdfencoding=auto,unicode, bookmarks=false, colorlinks=false, pdfborder={0 0 0},pdftitle={Name Tag}, pdfauthor={Advicement}, pdfsubject={Name Tag}, pdfkeywords={Name Tag}]{hyperref}

%%%%%%%%%%%%%%%%%%%%%% color definitions %%%%%%%%%%%%%%%%%%%%%%
\definecolor{White}{HTML}{FFFFFF} 
\definecolor{Black}{HTML}{000000} 
\definecolor{AdvGreen}{HTML}{0DBB72} 
\definecolor{AdvGray}{HTML}{383838}
\definecolor{AdvDarkGray}{HTML}{303030}

\begin{document} 
\pagecolor{White}
\begin{tikzpicture}[remember picture,overlay]
\node (rec1) [rectangle, inner sep=0.0cm, outer sep=0, draw = AdvGreen, anchor=north west, fill = AdvGreen, minimum width = 9.16cm, minimum height = 2cm] at ([xshift=0.5cm, yshift=-0.5cm]current page.north west) {}; 
\node (rec2) [rectangle, inner sep=0.0cm, outer sep=0, draw = AdvGreen, anchor=south west, fill = AdvGreen, minimum width = 9.16cm, minimum height = 0.3cm] at ([xshift=0.5cm, yshift=0.5cm]current page.south west) {}; 
\node (image) [anchor=north] at ([xshift=0cm, yshift=-0.4cm]rec1.north) {\advGetImage{key = image1, width=3.5cm, type = png}}; 
\node (name) [anchor=north, inner sep=0.0cm, outer sep=0] at ([xshift=0cm, yshift=-3.75cm]current page.north) {\color{AdvGreen} \bfseries \Huge{Name}};
\node (rec3) [rectangle, inner sep=0.0cm, outer sep=0, draw = AdvGreen, anchor=north, fill = AdvGreen, minimum width = 1cm, minimum height = 0.01cm] at ([xshift=0.0cm, yshift=-0.25cm]name.south) {}; 
\node (role) [anchor=north, inner sep=0.0cm, outer sep=0] at ([xshift=0cm, yshift=-0.25cm]rec3.north) {\color{AdvGreen} \LARGE{Title}};
\end{tikzpicture} 
\end{document}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Changing this Tex file by including different names and titles for each name tag can be done programmatically. Although at first glance, this looks like a normal Tex file, notice the \advGetImage function, which is a custom function used within DynamicDocs API to convert the image from JSON payload and insert it into the file.&lt;/p&gt;

&lt;p&gt;Notice that it references the image1 key in the JSON payload below. For more information on this function, visit &lt;a href="https://advicement.io/dynamic-documents-api/documentation/getting-started"&gt;DynamicDocs API documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now, we are ready to formulate our JSON payload, which looks as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
"texFileContent": "\\documentclass[10pt]{article}\n\n\\usepackage[paperheight=3in, paperwidth=4in, left=0mm, right=0mm, top=0mm, bottom=0mm, noheadfoot]{geometry}\n\\usepackage[T1]{fontenc}\n\\usepackage[sfdefault,lf]{carlito}\n\\usepackage{graphicx}\n\\usepackage{ragged2e}\n\\usepackage{xcolor}\n\\usepackage{tikz}\n\\usetikzlibrary{calc}\n\\usepackage[none]{hyphenat}\n\n%%%%%%%%%%%%%%%%%%%%%%% content definition %%%%%%%%%%%%%%%%%%%%%%%\n\\makeatletter\\let\\thetitle\\@title\\makeatother\n\\usepackage[pdfencoding=auto,unicode, bookmarks=false, colorlinks=false, pdfborder={0 0 0},pdftitle={Name Tag}, pdfauthor={Advicement}, pdfsubject={Name Tag}, pdfkeywords={Name Tag}]{hyperref}\n\n%%%%%%%%%%%%%%%%%%%%%% color definitions %%%%%%%%%%%%%%%%%%%%%%\n\\definecolor{White}{HTML}{FFFFFF} \n\\definecolor{Black}{HTML}{000000} \n\\definecolor{AdvGreen}{HTML}{0DBB72} \n\\definecolor{AdvGray}{HTML}{383838}\n\\definecolor{AdvDarkGray}{HTML}{303030}\n\n\\begin{document} \n\\pagecolor{White}\n\\begin{tikzpicture}[remember picture,overlay]\n\\node (rec1) [rectangle, inner sep=0.0cm, outer sep=0, draw = AdvGreen, anchor=north west, fill = AdvGreen, minimum width = 9.16cm, minimum height = 2cm] at ([xshift=0.5cm, yshift=-0.5cm]current page.north west) {}; \n\\node (rec2) [rectangle, inner sep=0.0cm, outer sep=0, draw = AdvGreen, anchor=south west, fill = AdvGreen, minimum width = 9.16cm, minimum height = 0.3cm] at ([xshift=0.5cm, yshift=0.5cm]current page.south west) {}; \n\\node (image) [anchor=north] at ([xshift=0cm, yshift=-0.4cm]rec1.north) {\\advGetImage{key = image1, width=3.5cm, type = png}}; \n\\node (name) [anchor=north, inner sep=0.0cm, outer sep=0] at ([xshift=0cm, yshift=-3.75cm]current page.north) {\\color{AdvGreen} \\bfseries \\Huge{Name}};\n\\node (rec3) [rectangle, inner sep=0.0cm, outer sep=0, draw = AdvGreen, anchor=north, fill = AdvGreen, minimum width = 1cm, minimum height = 0.01cm] at ([xshift=0.0cm, yshift=-0.25cm]name.south) {}; \n\\node (role) [anchor=north, inner sep=0.0cm, outer sep=0] at ([xshift=0cm, yshift=-0.25cm]rec3.north) {\\color{AdvGreen} \\LARGE{Title}};\n\\end{tikzpicture} \n\\end{document}",      
"image1": "iVBORw0KGgoAAAANSUhEUgAAAMgAAAAyCAYAAAAZUZThAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAEnQAABJ0BfDRroQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAABDKSURBVHic7Z3pjxvnfce/z1wk5+Cx9yntarU6vE18yC4sww2CwqgdJ3btuIpbwECLugH6om9aNG77J7Rp2hdF+6ZoUSQFCtRubAeu7SSw01rqYctym1rH6trVrrQH9yKXM0POcI6nL7hL8uG13CUl0vZ8AEGa4XDmN5zn9/zOZ0RQg5mZM5LcazxPKZ4D8CCAMQBKrWMDAj6jmADuAOQTQuib2U319UuXXs1XHkQqd5x6/KkzhHB/CtDJeyJmQEB3MAfgjz4++85r5TuLCnLmzBl+ftX8LkB//56LFhDQNdC/mBzSXnn11Vc9AOB3d8u9E98LlCMggJze1vPK8uKNnwA7FqTgVpF/7qxgAQHdAyH0hfMfvPtDMjNzRor0GJcBTHVaqG7GFzhk7o9BTOWhzJmdFifgrkPm0yo9KexkqwLlqAOVOKQfiCP1WC8cTcDUX14HJQChnZYs4O5CJ2M6fVagFM93WpRuxJN5pB7tQerhHvhhDgAQuZ0DCIE5rUK9ZnRYwoC7DQfyHAfgVKcF6Ua4nAcAReUAAHVWhzGtwJxWOyVWwD2EEpziAAx1WpBuhFAg3xdi9qnXdOSHwoGCfHEYFQAET7sGvkhgTJWaB0JrNqTNPAbeXkXsfAi+wIFz/Q5KGHAPUIVOS9CtZCcVULHMvbqqF/8dWrc7IVJAB+D2PuSLiXFcY7bVq0FQ/kUkUJBaEDBxhqA7CK/kOihQQKdoi4vlhzlkZmJV++V5E9JWVYNkNQSw+0NwowJcTYQn8/AlDpQj8MMcuL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MMfnCq0VfR9sIH0qDnNSKbSd17hVzvURXshCvWYwxS/i0KoOgWaoXPDF2R44i4BrIDNxaDH1SuqMXELLjqkRt/E5D+M/WMT2g3GkT8VhD4ZBeQLK74wBCoTXLKhXdPg8+xpXzvGbSv2SfPlx1TLE/jcNJy4idbqnFIdQVBWwG17j4V/6Wletb/NDHEAIvEjhhgoPy2/re3B9kQA8G7gRx7+nr8ehIgcnJsCTBfgCAW/54E0XQsb5XK449GQeriYWljznfUgp5571qFGJg90fAvEpsw6mGbou57gblxy4eNTMNRwKOJ1dz02cgkUEmnix3ucAPuvdFRe2GUjeL7TKHwAOQBes5AkI6EoyHIDlTksRENCVULLMAeRCp+UICOhKCD7mCKFvdlqOgIBuhFL/R5xvrv0QwM1OCxMQ0GXMWSntTe7ChQsOgD/utDQBAd0ER+kfXrr0ap4HgOXFG5dHDh+NAuR0pwULCOg85Lvnz73zV0BZN+/kkPYKofhe54QKCOg8FPjzySHlT3a3q2ruj3zlqW9SSv4MwNQ9lSwgoLPc5Cj9zkfn3n29fGfNppSZmTNSOKH/KgfyHAV5CISOIfjvogM+Xxig5A4l9AIB3qDZtTd34nGG/wdeiOyeG+9arQAAAABJRU5ErkJggg=="
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the stringified Tex file has to be put under the texFileContent key in the JSON. Furthermore, the texFileContent value contains double backslashes where single backslashes were previously used in the Tex file.&lt;/p&gt;

&lt;p&gt;The double backslashes are a result of stringifying the TEX file. Finally, the JSON contains a Base64 encoded image which is referenced in the \advGetImage function above. This allows users to make images dynamic in the documents.&lt;/p&gt;

&lt;p&gt;We are now ready to make the API call and POST the JSON above to TEX to PDF with the pdfLaTeX template endpoint:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://api.advicement.io/v1/templates/pub-tex-to-pdf-with-pdflatex-v1/compile&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To do so successfully, you will have to authenticate your API request by including the API key as a header parameter as follows:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Header Key: &lt;strong&gt;Adv-Security-Token&lt;/strong&gt;&lt;br&gt;
Value: &lt;strong&gt;{Your Account API Key}&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To make the API call above, we suggest using Postman and viewing the &lt;a href="https://www.postman.com/advicement/workspace/dynamicdocs-api-public-workspace/collection/8428379-a75fccff-226d-4a68-9ea4-4af37c26f126"&gt;DynamicDocs API – Public Workspace&lt;/a&gt; for a working example.&lt;/p&gt;

&lt;p&gt;The response of the API call is a simple JSON with the location of the Status JSON. To see whether the PDF was generated successfully, we can GET the Status JSON using the URL found in the response.&lt;/p&gt;

&lt;p&gt;If the PDF is generated successfully, the Status JSON will look as follows and contain the link to download the PDF:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
"id": "47c2451a-8aa8-47eb-b5db-842dc770b53a",
"startedAt": "Tue Oct 09 2022 19:03:57 GMT+0000 (Coordinated Universal Time)",
"statusCode": 201,
"statusDescription": "document created successfully",
"calculationLogUrl": "https://advicement-prod-api-calls.s3.eu-west-1.amazonaws.com/test/blank-template/47c2451a-8aa8-47eb-b5db-842dc770b53a/output/log/calcLog.txt?AWSAccessKeyId=ASIA2L...",
"latexLogUrl": "https://advicement-prod-api-calls.s3.eu-west-1.amazonaws.com/test/blank-template/47c2451a-8aa8-47eb-b5db-842dc770b53a/output/log/inputFile.log?AWSAccessKeyId=ASIA2L...",
"documentUrl": "https://advicement-prod-api-calls.s3.eu-west-1.amazonaws.com/test/blank-template/47c2451a-8aa8-47eb-b5db-842dc770b53a/output/inputFile.pdf?AWSAccessKeyId=ASIA2L..."
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have completed the LaTeX to PDF process using an API. Of course, the Tex file above can be replaced with any working LaTeX source file. The approach above gives developers a powerful option of creating a large variety of different document types.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Remarks
&lt;/h2&gt;

&lt;p&gt;As outlined in this article, DynamicDocs API caters to a specific use case when doing &lt;a href="https://advicement.io/dynamic-documents-api/json-to-pdf-templates?type=tex+to+pdf"&gt;TEX to PDF conversion&lt;/a&gt; (see the Consideration section to see whether your use case fits).&lt;/p&gt;

&lt;p&gt;In an event where you have ticked all the conditions, TEX to PDF templates give the option of creating different document types, provided users can create their own working Tex file and dynamically populate it with their data.&lt;/p&gt;

&lt;p&gt;DynamicDocs API runs a full TeX Live 2021 Distribution, meaning that users have access to an extensive range of the latest LaTeX packages and fonts. For quick integration, follow the steps above or visit &lt;a href="https://www.postman.com/advicement/workspace/dynamicdocs-api-public-workspace/collection/8428379-a75fccff-226d-4a68-9ea4-4af37c26f126"&gt;DynamicDocs API – Public Workspace via Postman&lt;/a&gt; page.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>productivity</category>
      <category>showdev</category>
      <category>api</category>
    </item>
    <item>
      <title>Technology Options for Automated Dynamic PDF Generation</title>
      <dc:creator>IgorR</dc:creator>
      <pubDate>Sun, 20 Jun 2021 21:31:03 +0000</pubDate>
      <link>https://dev.to/advicement/technology-options-for-automated-dynamic-pdf-generation-4ieb</link>
      <guid>https://dev.to/advicement/technology-options-for-automated-dynamic-pdf-generation-4ieb</guid>
      <description>&lt;p&gt;Effective dynamic documents can add immense value to any business looking to engage with their clients through personalisation. These documents can take many forms, including customised statements, invoices, welcome letters, product schedules. However, production challenges with dynamic documents can set organisations back significantly in terms of time, budget and resources spent. This article will review the possible technology options available to businesses. Having the right technology to produce dynamic documents is crucial in keeping operations running optimally, creating documents quickly, and maintaining a consistent level of quality.&lt;/p&gt;

&lt;p&gt;We highlight three technology approaches below.&lt;/p&gt;

&lt;h2&gt;
  
  
  HTML to PDF
&lt;/h2&gt;

&lt;p&gt;A common option for producing dynamic documents is to write the template using HTML and CSS and then convert it into a PDF. To achieve this, a user will need a good understanding of HTML and CSS. Multiple libraries are available, as well as online solutions, including APIs. Most of the solutions implement an HTML to PDF converter such as wkhtmltopdf, which is open source. In some cases, the quality of produced PDF documents has been poor, but this has improved with time as new versions were, and continue to be, released.&lt;/p&gt;

&lt;p&gt;Typically, users will design an HTML page, which becomes a template, and then use another piece of software to change the HTML with data dynamically. One of the downsides of this approach is that developers will be required to use different software to create the documents, the choice of which is mainly dependent on (and limited by) their technology stack.&lt;/p&gt;

&lt;p&gt;HTML and CSS are well-known frameworks, making this approach a popular choice for developers when generating dynamic PDF documents. However, we caution against using this approach. It may feel like putting together a jigsaw puzzle that requires substantial testing and tinkering by the developers, resulting in an additional codebase needed to be maintained. Notwithstanding these limitations, having proficient skills in HTML with an already developed CSS library may mean that this approach is more than suitable for some businesses.&lt;/p&gt;

&lt;h2&gt;
  
  
  Word to PDF or similar
&lt;/h2&gt;

&lt;p&gt;In this category, we group the various solutions that enable a user to write a template in a program, such as MS Word, define the template's dynamic components, and then call the template with the data. The software then converts the newly created document into a PDF.&lt;/p&gt;

&lt;p&gt;There is a range of solutions available in this category, primarily targeting the enterprise type client, including some big technology providers such as &lt;a href="https://www.adobe.com/products/indesignserver.html"&gt;Adobe&lt;/a&gt; and &lt;a href="https://flow.microsoft.com/en-us/blog/intermediate-flow-of-the-week-create-pdf-invoices-using-word-templates-with-microsoft-flow/"&gt;Microsoft&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As each solution has its unique features, they are required to be evaluated individually. The core focus of the evaluation should centre on the usability of template building and the ease of integration for the development team. PDF quality and price are other important factors to be considered in evaluating each solution. Enterprise pricing is often a significant stumbling block for many businesses and can usually only be carried by larger companies with substantial budgets allocated for this. By way of example, the Adobe InDesign Server premium license is $13,500 per annum as of June 2021, which may not be feasible for start-ups and SMEs.&lt;/p&gt;

&lt;p&gt;It is essential to evaluate specific features of each solution against the particular business needs, as creating dynamic charts and dynamic tables with user-provided data may prove to be complex and incompatible with some solutions. The ease of use and pricing of the proposed solution are the most important items to evaluate in selecting an appropriate approach. Ultimately, both will have a cost impact on a user's business.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tex to PDF
&lt;/h2&gt;

&lt;p&gt;A third approach is to use LaTeX (a document preparation software for high-quality typesetting) to create dynamic PDF documents using files with a tex extension. One reason for LaTeX popularity is that it enables authors to write extensive documents in a mark-up style language. This approach bodes well if users are looking to generate high-quality PDF documents which are styled with maximum precision.&lt;/p&gt;

&lt;p&gt;To the best of our knowledge, &lt;a href="https://advicement.io/dynamic-documents-api"&gt;DynamicDocs API&lt;/a&gt;, developed by &lt;a href="https://advicement.io"&gt;ADVICEment&lt;/a&gt;, is the first API product that uses LaTeX to generate PDF documents with dynamic text, tables, and charts. The template files are written on the ADVICEment platform using LaTeX, where they can be tested and compiled. The dynamic data used in the documents are passed in the JSON format as the body of the API call. In the template files, one can indicate where the dynamic data needs to be placed and takes the form of stylised text, tables, or charts.&lt;/p&gt;

&lt;p&gt;The main disadvantage of this approach is that LaTeX may seem complicated to pick up as a certain amount of initial time is needed to learn the mark-up language. However, this investment in time is definitely worth it as users gain consistent programmatic formatting throughout the document based on the rules which they have defined. The benefit of separating content and design in LaTeX cannot be overstated.&lt;/p&gt;

&lt;p&gt;Another advantage of using DynamicDocs API is that &lt;a href="https://advicement.io/dynamic-documents-api/template-examples"&gt;PDF template files&lt;/a&gt; are available in a user's &lt;a href="https://advicement.io/dynamic-documents-api/dashboard"&gt;ADVICEment account&lt;/a&gt;, and changes can be implemented quickly and effectively. As with many API products, users pay for what they use, and there is a pricing plan with various pricing options suitable for users' needs. Users can also try the API with the simple &lt;a href="https://advicement.io/dynamic-documents-api/json-to-pdf-api-call"&gt;PDF generation form&lt;/a&gt; or &lt;a href="https://advicement.io/sign-up"&gt;sign up&lt;/a&gt; for a FREE plan to access the API.&lt;/p&gt;

&lt;p&gt;Using LaTeX to write document templates and create dynamic PDF documents is one of the most effective and efficient approaches. LaTeX offers a higher level of quality and possibility for these types of documents. Most importantly, you can use &lt;a href="https://advicement.io/dynamic-documents-api"&gt;DynamicDocs API to automate and maintain the PDF generation process&lt;/a&gt; with high-quality results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summing-up
&lt;/h2&gt;

&lt;p&gt;Dynamic documents can add immense value to any organisation. Creating effective dynamic documents comes down to the quality of the template and the conversion method used. Whilst effective results can be achieved from various options and service providers; it is imperative for businesses to do their due diligence. Due diligence must consider business-specific needs (special formatting requirements such as dynamic charts and tables) and take into account the existing technology stack.&lt;/p&gt;

&lt;p&gt;In this consideration, we note that a built-for-purpose &lt;a href="https://advicement.io/dynamic-documents-api"&gt;dynamic documents API using LaTeX&lt;/a&gt; is a strong contender for the most efficient and effective method to use.&lt;/p&gt;

</description>
      <category>pdf</category>
      <category>api</category>
      <category>automation</category>
      <category>serverless</category>
    </item>
  </channel>
</rss>
