Skip to main content
All CollectionsAutomation & APIPDF generation
On-the-fly PDF with multiple pages
On-the-fly PDF with multiple pages

How can I generate on-the-fly PDF with multiple pages and templates

Updated over 2 years ago

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 https://www.catalogmachine.com/app/pdf-on-fly-test or from My Account page

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

  • Page Size: A4, A5, Letter, Half Letter

  • List of templates:templateID is a mandatory parameteryou can provide Product ID and all the fields in template will be filled from this productor you can provide item structure with custom field values.

{
  orientation: '{Portrait or Landscape}',
size: '{A4, A5, Letter, Half Letter}'
  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

{
  orientation: 'Portrait',
size: 'Letter',
  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).

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.

 

4. Generate PDF from any system. You can use any programming library that can send POST web requests with JSON data (parameter name 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.

Did this answer your question?