printAndSaveRecord
To generate a PDF from a record or Carbone template, save it in Ninox's internal file system, and return a download link
This function creates a PDF from a specified record in either a Ninox layout or Carbone template, stores it in Ninox's internal file system, and returns a download link to the file.
You can use this link for internal access or save it as a record attachment using the importFile
function.
Caution: This function can only be executed on the client side. For more information, see execution context documentation.
Carbone templates
The printAndSaveRecord
function supports Carbone templates, allowing you to optionally add a JSON input to overwrite record fields in the template. You can also apply advanced configuration through the _options
parameter for features including test print, password protection, and PDF versioning.
Syntax
printAndSaveRecord(nid, string)
printAndSaveRecord(nid, string, JSON)
Parameter
record: The record to be saved as a PDF.
myLayout: The layout or Carbone template used to format the PDF.
data (optional): A JSON object that overwrites the record data in the Carbone template.
_options (optional): Additional configuration options for Carbone templates.
_options
configuration:
testPrint:
boolean
, default isfalse
. Iftrue
, prints a test PDF with a Carbone watermark; this action doesn’t consume Carbone tokens.pdfPassword:
string
. Protects the PDF with a password.pdfVersion:
number
. Specifies the PDF version:0
: Default15
: PDF 1.516
: PDF 1.61
: PDF/A-12
: PDF/A-23
: PDF/A-3
Note: _options
configurations are stackable, allowing you to apply multiple settings in one function call. For example, you can enable both pdfPassword
and pdfVersion
for added customization.
Return
link: A URL to the saved PDF file in Ninox's internal file system.
Examples
printAndSaveRecord(record, myLayout)
printAndSaveRecord(record, myLayout)
This version of the function works for both Ninox layouts and Carbone templates. It generates and saves a PDF for the specified record and returns a link to the file.
Example:
Result:
A link to the generated PDF that follows the Invoices layout: https://dbde0000.ninox.com/AbCD1234/12345xYZzyX/loadfile/Invoices.pdf?
printAndSaveRecord(record, myLayout, data)
printAndSaveRecord(record, myLayout, data)
1. Overwriting record data
To save a record in a Carbone template as a PDF in the internal file system, returning a link to the file. Record data can be overwritten with a JSON object.
Example:
Result:
A link to the generated PDF that includes an entry in the Date field: https://dbde0000.ninox.com/AbCD1234/12345xYZzyX/loadfile/Invoices.pdf?
If no entry is provided, today's date will be added. For example, 08/28/2024
for August 28, 2024.
2. Populate a Carbone template (without _options
)
_options
)Example:
Result:
A link to the generated PDF where the Name and Age placeholders are replaced by provided values: https://dbde0000.ninox.com/AbCD1234/12345xYZzyX/loadfile/Invoices.pdf?
3. Test print with Carbone watermark
Note: Test printing doesn't use Carbone tokens.
Example:
Result:
A link to the generated test PDF, which includes a Carbone watermark: https://dbde0000.ninox.com/AbCD1234/12345xYZzyX/loadfile/Invoices.pdf?
4. Password-protected PDF
Example:
Result:
A link to the generated PDF, which is password-protected with password 1234
:
https://dbde0000.ninox.com/AbCD1234/12345xYZzyX/loadfile/Invoices.pdf?
5. PDF versioning
Example:
Result:
A link to the generated PDF, which is formatted to PDF/A-1 standards: https://dbde0000.ninox.com/AbCD1234/12345xYZzyX/loadfile/Invoices.pdf?
See also
importFile
, which imports a file from a URL and saves it as an attachment of a record.
printRecord
, which prints a record to a PDF in a specified layout and opens it in the default program.
Want to learn more about this topic? Check out the corresponding part of our video tutorial.
Last updated