Sign In

PDF Generation

You can use the HTML2PDF service to convert dynamically generated HTML into a PDF document. This can be used for generating customer-facing documents like proposals, quotes, invoices, etc.

You access the HTML2PDF service by making an API call as shown below.

Example - Generating a PDF from HTML

Simply call parasql_http() as shown below. Replace YOUR_API_KEY with a key you create via Tools > API Keys.

CALL parasql_http( 'POST', '', JSON_OBJECT( 'filename', 'MyInvoice.pdf', 'html', Invoice_GetHTML(12345), -- call a function to generate the HTML 'makePublic', true ), 'MyCallback', -- specify a callback procedure to process the response NULL, NULL );

In the above example the HTML is dynamically generated via a stored function called Invoice_GetHTML(); you can see the code here.

If makePublic is true anyone with the document URL can access it.

The Response

Your callback procedure must take the following parameters:

respCode INTEGER, respBody JSON, respHeaders JSON, optMetadata JSON

The respBody will look like this:

{ "status": "OK", "errorMessage": "", "errorCode": "", "data": { "documentField": "HelloWorld.pdf;1048;1598992707098;database/files/a655f610-febd-4f6a-b11d-6bcd696f5456.pdf" } }

Your callback procedure will need to save the documentField to your database with code something like this:

INSERT INTO Invoice (Invoice_ID, Invoice_PDF) VALUES (parasql_next_val('Invoice'), JSON_VALUE(respBody, '$.data.documentField') );

Love AppSynergy? Spread the Word...