How can I generate on-the-fly PDF with a multiple templates?

Catalog Machine provides advanced API to generate multi-page PDF with JSON. You can use any programming library that can send JSON data to out API (human readable text to transmit data between a server and web application). Use our test page to test and prepare JSON.

You can try simpler url-based API to generate one-page PDF.

To use API and prepare data follow the steps below

1. Go to PDF-on-the-fly test page in Templates menu

pdf-on-fly-menu

2. Prepare JSON data. Enter valid JSON data for the PDF generation in the following format. You can find Template and Product IDs in the right columns.

Parameters:

  • Orientation of PDF: Portrait or Landscape
  • List of templates:
    • templateID is a mandatory parameter
    • you can provide Product ID and all the fields in template will be filled from this product
    • or you can provide item structure with custom field values.
{
  orientation: '{Portrait or Landscape}',
  templates: [
    {
      templateId: '{Template ID}',
      productId: '{Product ID}'
    },
    {
      templateId: '{Template ID}',
      item: {
        Field1: '{Field 1 value}',
        Field2: '{Field 2 value}',
        {more fields}
      }     
    },
    {more templates}
  ]
}

For example

pdf-on-fly-page

{
  orientation: 'Portrait',
  templates: [
    {
      templateId: '2fc59ede-79b9-415c-977c-a3e4b24f0079',
      productId: 'c4d22827-e470-4117-9c57-1279e00d22cb'
    },
    {
      templateId: 'a4c5897f-1d6a-4db8-859d-3e1fe84d9193',
      productId: '04e1790e-814a-440b-b1b1-8aac2604f988'
    },
    {
      templateId: 'a4c5897f-1d6a-4db8-859d-3e1fe84d9193',
      productId: '215d9d41-4034-443b-aec9-5f7010cd8d50'
    },
    {
      templateId: 'a4c5897f-1d6a-4db8-859d-3e1fe84d9193',
      item: {
        Name: 'New Salomon Ski',
        Price: '$500',
        Image: 'image:Sample/SalomonRockerSki.jpg'
      }
    }
  ]
}

Images should refer to a local path that you can copy from image preview and prefix image: should be added before (as in example).

image-path

3. Design templates. You can use existing templates or create templates the same as for any catalog. In addition, Full page templates enable special attributes for designer elements to control PDF page rendering of the large text blocks.

  • Fixed attribute marks header or footer elements that will be repeated on every page if the page content expands to the new page.
  • Expandable attribute marks text elements that can flow to the next page. This text will fill space between fixed elements on the new page.

element-fix-expand

 

4. Generate PDF from any system. You can use any programming library that can send POST web requests with JSON data (parameter name json).

API address is http://www.catalogmachine.com/public/api/1/pdf.json.

The simplest way is to use POST request from the web form and send prepared JSON data.

Sample form HTML:
<form method="POST" action="/public/api/1/pdf.json">
 <textarea name="json"></textarea>
 <br/>
 <button type="submit">Generate PDF</button>
</form>

Note: Daily quote of API calls depends on plan limits.

Leave a Reply

Your email address will not be published. Required fields are marked *