PDF Generation
You can use AppSynergy's PDF Generator to convert dynamically generated HTML from your database data into a PDF document.
This is often used for generating customer-facing documents like proposals, quotes, invoices, etc.
This feature works by calling an AppSynergy API.
Please see Making RESTful API calls
for details.
Example
This example uses two stored procedures, one to generate the PDF (the request procedure), and one to save the
PDF into your database (the callback procedure).
You can create and manage stored procedures via Tools > Stored Routines.
Request Procedure - Generating the PDF
Simply call parasql_http() as shown below.
Replace YOUR_API_KEY with an actual API key you create via Tools > API Keys.
In the example below the HTML is dynamically generated via a stored function called Invoice_GetHTML();
you can see its code here.
BEGIN
CALL parasql_http(
'POST',
'https://www.appsynergy.com/api?action=HTML2PDF&apiKey=YOUR_API_KEY',
JSON_OBJECT(
'filename', 'MyInvoice.pdf',
'html', Invoice_GetHTML(12345), -- call a function to generate the HTML
'makePublic', true
),
'MyCallback', -- name of your callback procedure
NULL,
NULL
);
END
Callback Procedure - Save the generated PDF
Your callback procedure must take the following parameters:
respCode INTEGER, respBody JSON, respHeaders JSON, callbackData JSON
BEGIN
INSERT INTO Invoice (Invoice_ID, Invoice_PDF)
VALUES (parasql_next_val('Invoice'), JSON_VALUE(respBody, '$.data.documentField') );
END
API Specification
Request
POST https://www.appsynergy.com/api?action=HTML2PDF&apiKey=YOUR_API_KEY
{
"html": "<html><body><h1>Hello World</h1></body></html>",
"filename": "HelloWorld.pdf",
"makePublic": false
}
- html - must be in XHTML format (i.e. all elements must be closed;
for example <br> is not valid but <br/> is valid).
Most of CSS 2.1 is supported.
- filename - the human readable filename for the generated PDF document.
- makePublic - makes the generated PDF file accessible to the public if true.
The default is false.
Response
{
"status": "OK",
"errorMessage": "",
"errorCode": "",
"data": {
"documentField": "HelloWorld.pdf;1048;1598992707098;database/files/a655f610-febd-4f6a-b11d-6bcd696f5456.pdf"
}
}
- data.documentField - the generated PDF document.
This value can be stored directly into any document field in your database.