@admin , how to use merge insert one or many external pdf to document? have any example?
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:

-
How to use the pdf utils?posted in general forum
I want use the pdf utils pass value to Header or Footer. I added the tag <div> {{{pdfAddPageItem :ClientName}}}</div> to my main template, but I got an errors as below:
Error: Error while executing templating engine. Syntax error Unmatched or missing {{/pdfAddPageItem}}, in template: ... at C:\jsreportapp\node_modules\jsrender\jsrender-node.js:223:27 at Object.<anonymous> (C:\jsreportapp\node_modules\jsrender\jsrender-node.js:2879:2) at Module._compile (module.js:653:30) at Object.Module._extensions..js (module.js:664:10) at Module.load (module.js:566:32) at tryModuleLoad (module.js:506:12) at Function.Module._load (module.js:498:3) at Module.require (module.js:597:17) at require (internal/module.js:11:18) at Object.<anonymous> (C:\jsreportapp\node_modules\jsreport-jsrender\lib\jsrenderEngine.js:6:16) From previous event: at executeScript (C:\jsreportapp\node_modules\jsreport-core\lib\util\executeScript.js:41:49) at Reporter.executeScript (C:\jsreportapp\node_modules\jsreport-core\lib\reporter.js:343:12) at invokeRender (C:\jsreportapp\node_modules\jsreport-core\lib\render\render.js:60:36) at module.exports (C:\jsreportapp\node_modules\jsreport-core\lib\render\render.js:150:11) at <anonymous>below was my studio version information:
about version: 2.11.0 Release notes engines: handlebars, jsrender, none recipes: chrome-image, chrome-pdf, docx, html, html-to-xlsx, html-with-browser-client, pptx, static-pdf, text, xlsx assets: 1.7.0 authentication: 2.6.1 authorization: 2.4.0 base: 2.0.2 browser-client: 2.2.2 child-templates: 1.4.0 chrome-pdf: 1.10.0 cli: 2.2.5 data: 2.4.0 debug: 2.1.3 docx: 2.9.0 express: 2.8.1 freeze: 2.0.0 fs-store: 2.9.1 handlebars: 2.1.0 html-to-xlsx: 2.8.3 import-export: 2.1.1 jsrender: 2.1.1 licensing: 2.2.3 pdf-utils: 1.11.0 pptx: 0.7.0 public-templates: 2.2.0 reports: 2.5.1 resources: 2.1.0 sample-template: 2.6.1 scheduling: 2.5.0 scripts: 2.6.0 static-pdf: 0.4.0 studio: 2.10.1 studio-theme-dark: 0.3.0 tags: 2.5.0 templates: 2.4.0 text: 2.0.0 unoconv: 0.3.0 version-control: 1.6.0 xlsx: 2.5.0How to fix the errors?
-
RE: Checkbox can't works on the nested dockListposted in general forum
@bjrmatos regarding the image, shall I upgrade the jsreport version?
-
RE: Checkbox can't works on the nested dockListposted in general forum
@bjrmatos , 1.- I using docxList should be correct, different type the Answer different, if type==1or type==2 it was a list, if type==0 if was a simple text.
I have using the #each instead of the #dockList, works well, My custom have buy the jsreport licence , could you please provide a full docx helper guidline for me? I look at the docx recipe api, but it have less description and helper(https://jsreport.net/learn/docx), we will convert all pdf report to docx. maybe we will display all forms in the docx. -
RE: Checkbox can't works on the nested dockListposted in general forum
Please look at my example here: https://playground.jsreport.net/w/Xushlin/FmFNHLl9
-
Checkbox can't works on the nested dockListposted in general forum
It can't works when I created a complex docx template with the docxCheckbox.
I created a docx file like this:
{{#docxList Extension}}{{Number}}.{{Name}} {{Description}}{{#if (compare Type 1)}} {{#docxList Answer}}{{Item}}{{/docxList}} {{/if}}{{#if (compare Type 0)}}{{Answer}} {{/if}}{{#if (compare Type 2)}} {{#docxList Answer}}{{Item}}{{/docxList}} {{/if}} {{/docxList}}simple data:
"Extension": [ { "Answer": [ { "Item": "Installerade Skydd", "Checked": true }, { "Item": "Skyddsutrustning", "Checked": true }, { "Item": "Belysning", "Checked": true } ], "Number": 1, "Type": 1, "Name": "Skyddsanordningar:", "Description": null }, { "Answer": [ { "Item": "Bruksanvisning", "Checked": true }, { "Item": "Varningsskyltar, märkning", "Checked": true }, { "Item": "Varningsanordningar", "Checked": false }, { "Item": "Särskild utbildning", "Checked": false } ], "Number": 2, "Type": 1, "Name": "Information och varning:", "Description": null }, { "Answer": [ { "Item": "Manöverdon", "Checked": false }, { "Item": "Nödstopp, Säkerhetsbrytare", "Checked": false }, { "Item": "Styrsätt", "Checked": false } ], "Number": 3, "Type": 1, "Name": "Manöver", "Description": null }, { "Answer": [ { "Item": "Stabilitet", "Checked": false }, { "Item": "Rörliga delar", "Checked": true }, { "Item": "Brott, lösa föremål", "Checked": true } ], "Number": 4, "Type": 1, "Name": "Mekaniska risker", "Description": null }, { "Answer": [ { "Item": "Elektriska risker installationer", "Checked": false }, { "Item": "Kopplingsutrustning", "Checked": false }, { "Item": "EMC - emission", "Checked": false } ], "Number": 5, "Type": 1, "Name": "Elektriska risker", "Description": null }, { "Answer": "This is a simple text", "Number": 7, "Type": 0, "Name": "Elektriska risker", "Description": null } ] }The result:

if I insert the docxCheckbox it will can't works, the docx template like this:
{{Description}}{{#if (compare Type 1)}} {{#docxList Answer}}☐{{Item}}{{/docxList}} {{/if}}{{#if (compare Type 0)}}{{Answer}} {{/if}}{{#if (compare Type 2)}} {{#docxList Answer}}{{Item}}{{/docxList}} {{/if}} {{/docxList}}Is it may docx content format incorrect? how can I fix it?
-
RE: How to formating the \n and \t in the docx?posted in general forum
@jan_blaha , It works for me. thanks.
-
How to formating the \n and \t in the docx?posted in general forum
I have a description like this: 1).somethingA \n, 2).somethingB \n, 3), somethingC
I want it displayed like this:
1).somethingA
2).somethingB
3).somethingCHow to do it?
-
RE: How to use the if condiation sentence in the docx template?posted in general forum
@bjrmatos , thansks, works well for me now.
-
RE: How to use the if condiation sentence in the docx template?posted in general forum
@bjrmatos
My template like this:
{{#docxList Projects}}
{{ClientName}} {{ClientAddress}}
{{ZipCode}}, {{ClientCity}}
{{ClientEmail}}
{{ClientPhone}}{{#docxList CheckLists}}
{{#if Level==1}}
{{NodeNumber}} {{ChecklistName}} Utförd av: Datum:
{{else}}
{{NodeNumber}} {{ChecklistName}}
{{/if}}
{{/docxList}}
{{/docxList}}I get a error as below:
{"message":"Error while executing docx recipe. Error while executing templating engine. Parse error on line 12:\n...Pr><w:t>{{#if Level==1}}</w:t></w:r><w:b\n-----------------------^\nExpecting 'OPEN_SEXPR', 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'EQUALS'","stack":"Error: Error while executing docx recipe. Error while executing templating engine. Parse error on line 12:\n...Pr><w:t>{{#if Level==1}}</w:t></w:r><w:b\n-----------------------^\nExpecting 'OPEN_SEXPR', 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'EQUALS'\n at module.exports (C:\jsreportapp\node_modules\jsreport-core\lib\util\createError.js:11:13)\n at Reporter.createError (C:\jsreportapp\node_modules\jsreport-core\lib\reporter.js:328:12)\n at Object.execute (C:\jsreportapp\node_modules\jsreport-docx\lib\recipe.js:62:20)\n at <anonymous>\n at process._tickCallback (internal/process/next_tick.js:189:7)\ncaused by: Error: Error while executing templating engine. Parse error on line 12:\n...Pr><w:t>{{#if Level==1}}</w:t></w:r><w:b\n-----------------------^\nExpecting 'OPEN_SEXPR', 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'EQUALS'\n at Object.callbackRequests.(anonymous function) (C:\jsreportapp\node_modules\script-manager\lib\worker-servers.js:250:31)\n at process.<anonymous> (C:\jsreportapp\node_modules\script-manager\lib\worker-servers.js:195:30)\n at emitTwo (events.js:131:20)\n at process.emit (events.js:214:7)\n at emit (internal/child_process.js:762:12)\n at _combinedTickCallback (internal/process/next_tick.js:142:11)\n at process._tickDomainCallback (internal/process/next_tick.js:219:9)"}How to fix this error?
-
How to use the if condiation sentence in the docx template?posted in general forum
How to use the if condiation sentence in the docx template? example:
if(condiation==1){ {{displayA}} }else if(condiation==2){ {{displayB}} }else{ {{displayOthers}} }