How to render multiple records on one PDF in Advan...
# ask-stanley-ai
a
How to render multiple records on one PDF in Advanced PDF Templates
c
AI generated answer (using internal Slack threads):
To render multiple records on one PDF in Advanced PDF Templates, you can use the following methods: 1. Using a Loop and Concatenating PDFs: You can render each record in a loop and concatenate the PDFs. This method is useful if you don't mind the records being on separate pages. Here is a sample code snippet:
Copy code
javascript
var renderer = render.create();
for (var i = 0; i < records.length; i++) {
    renderer.addRecord('record', record.load({
        type: 'estimate',
        id: records[i].id
    }));
    renderer.setTemplateById(templateId);
    var pdf = renderer.renderAsPdf();
    // Concatenate pdfs here
}
2. Using a Primary Template and Subtemplates: You can create a primary template and pass your array of records to it. Then, inside the primary template, you can use subtemplates to render each record. Here is a sample code snippet:
Copy code
javascript
var renderer = render.create();
renderer.addQuery({
    templateName: 'itemSearch',
    query: itemQuery,
});
renderer.setTemplateById(templateId);
var pdf = renderer.renderAsPdf();
3. Using a Single Advanced PDF Template with Conditional Statements: You can create a single advanced PDF template that contains your multiple designs. Then, you can use specific IF conditions to determine which design to print based on the record data. Remember to replace the
templateId
and
records[i].id
with your actual template ID and record IDs. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.859253
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.835510254
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.833862305
Please provide your feedback on this answer.