Hi ,
I have a scenario where in I need to create the doc definition inside loop . The problem is once the doc definition is created there is no way you can append it. How can this be achieved ? Every time I loop I am getting a json object which needs to be added to the PDF file.
Regards,
Nishant
Please find the code snippet.
for (var i = 0; i < checkedValues.length; i++) {
{{#questionList}}
if((checkedValues[i]).localeCompare({{questionId}}) == 0 ){
var docDefinition = {
content: [
{
text: 'Problem statement',
style: 'header'
},
'{{questionString}}',
{
text: 'Detailed description',
style: 'header'
},
'{{detailedDescription}}',
{
text: 'Community',
style: 'header'
},
'{{community}}',
{
text: 'Category',
style: 'header'
},
'{{category}}',
{
text: 'Comments',
style: 'header'
},
{
ol: [
{{#commentList}}
'{{commentString}}',
{{/commentList}}
]
}
],
styles: {
header: {
fontSize: 12,
bold: true
}
}
}
}
{{/questionList}}
}
pdfMake.createPdf(docDefinition).download();
Why don't you just add to the content afterwards?
I have an if condition which needs to hold true before I add it to the content . I cannot have the condition executed in between the content.
Von meinem iPhone gesendet
Am 09-Mar-2015 um 18:38 schrieb Johannes Thönes [email protected]:
Why don't you just add to the content afterwards?
—
Reply to this email directly or view it on GitHub.
Uhm, why don't you create a content = [] and push your content everytime your condition is true ...
(note: use strict comparisons === instead of ==)
if (true) {
content.push({text: "hello world"});
}
Then you end-up something like:
content = [{text: "hello world"},{"more text"}];
Then finally you can add content to docDefinition like:
var docDefinition = {
content: content,
styles: {
header: {
fontSize: 12,
bold: true
}
}
}
pdfMake.createPdf(docDefinition).download();
@Wabbala WOW!! IT WORKS!
Most helpful comment
Uhm, why don't you create a
content = []and push your content everytime your condition is true ...(note: use strict comparisons
===instead of==)Then you end-up something like:
Then finally you can add content to docDefinition like: