@admin , how to use merge insert one or many external pdf to document? have any example?
Xushlin
@Xushlin
Posts made by Xushlin
-
RE: How can I insert external pdf to report?posted in general forum
-
RE: How can I insert external pdf to report?posted in general forum
@admin, thanks, I have look at the https://jsreport.net/learn/pdf-utils#usage-in-script, it will appended after source that mean it appended the external PDF to last, but I want insert the Pdf to report middle. have any other ways?
-
How can I insert external pdf to report?posted in general forum
My customer have a requirement that want insert many external PDF to jsreport.
the sample data like this:
"Projects": [ { "title":"Title 1", "pdfUrl": "https://projectportalstorageprod.blob.core.windows.net/pdf/Ebbepark%20Takavvattning%20test%20aaab_support@projektportalen.se_20241217101008.pdf" }, { "title":"Title 2", "pdfUrl": "https://projectportalstorageprod.blob.core.windows.net/pdf/Ebbepark%20Takavvattning%20test%20aaab_support@projektportalen.se_20241217101008.pdf" } ] }and the template like this:
<head> <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no" /> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> </head> <body> {{#each Projects}} <div style="color:black;"> <h3>Title: {{this.title}}</h3> </div> <div> <p>Base64 content:</p> <p>{{#if this.pdfBase64}}{{this.pdfBase64}}{{else}}No Base64 Data Found{{/if}}</p> </div> <div> {{#pdfMerge}} {{#merge}} {{pdfRaw this.pdfBase64}} {{/merge}} {{/pdfMerge}} </div> {{/each}} </body> </html>js code:
const axios = require('axios'); async function beforeRender(req, res) { const projects = req.data.Projects; const pdfPromises = projects.map(async (project) => { try { console.log(`Downloading PDF for: ${project.title}, URL: ${project.pdfUrl}`); const response = await axios.get(project.pdfUrl, { responseType: 'arraybuffer' }); console.log(`Status Code for ${project.title}:`, response.status); console.log(`Downloaded PDF Size for ${project.title}:`, response.data.length); const pdfBase64 = Buffer.from(response.data).toString('base64'); console.log(`Generated Base64 Length for ${project.title}:`, pdfBase64.length); return { title: project.title +'Michael xu', pdfBase64: pdfBase64 }; } catch (error) { console.error(`Failed to download PDF for: ${project.title}, Error: ${error.message}`); return { title: project.title + 'ddd', pdfBase64: null }; } }); const pdfData = await Promise.all(pdfPromises); req.data.Projects = pdfData; }I get result:

the report can not render the base64 to PDF content.
How can I fix this case?
-
RE: How to fix lost line breaks when using unoconv to convert DOCX to PDF?posted in general forum
@admin, thanks, good solution. works for me now.
-
How to fix lost line breaks when using unoconv to convert DOCX to PDF?posted in general forum
How to fix lost line breaks when using unoconv to convert DOCX to PDF?
I used Docx template preview with Docx works well. but convert to PDF it lost line breaks.1.Word template like this:
{{preserveLineBreaks Description}}
2.preserveLineBreaks function like this:function escapeXml(unsafe) { return unsafe.replace(/[<>&'"]/g, function (c) { switch (c) { case '<': return '<'; case '>': return '>'; case '&': return '&'; case '\'': return '''; case '"': return '"'; } }); } function preserveLineBreaks(d) { if(d){ return new Handlebars.SafeString(escapeXml(d).replace(/\n/g, '<w:br/>')); } }3.Preview as word it works well and result as below:

- But it lost line break when I enabled unoconv and preview as PDF, and the reslut as below:

- How to fix this issues?
- But it lost line break when I enabled unoconv and preview as PDF, and the reslut as below:
-
How to call the sub folder's tempalte via API?posted in general forum
Re: Organizing templates in folders under data
How to via API invoke the tempate of the sub folder? how to translate the template paramaters?
example:
templates/
|---subFolders/
------ foo1
------ foo2
---foo1
---foo2How to call the templates/subFolers/foo1 in the API?
-
RE: How to render a content contain '&' in the docx?posted in general forum
My template have a custom break line fuction. template like this:
{{preserveLineBreaks foo}}the function as below:
function preserveLineBreaks(d) { return new Handlebars.SafeString(d.replace(/\n/g, '<w:br/>')) } please see the example here: https://playground.jsreport.net/w/Xushlin/6FhQQRdP -
How to render a content contain '&' in the docx?posted in general forum
I render a docx template error when a field string contain a character '&' .
how to fix this problem?
blow is error picture:
