We are using the pdfMake javascript framework to render HTML to a PDF document.
我们使用pdfMake javascript框架将HTML呈现为PDF文档。
Given that a simple working document definition object is rendered thusly:
鉴于如此呈现一个简单的工作文档定义对象:
var docDefinition = {
content: { stack: [
{ text: 'foo', style: 'normal', margin: [0,1,0,0] },
{ text: 'bar', style: 'bold', margin: [0,1,0,0] }
]}
}
And given that objectives
is an array of HTML elements, we are attempting to parse said elements and return the stack
definition via a function. Like so:
鉴于目标是一个HTML元素数组,我们试图解析所述元素并通过函数返回堆栈定义。像这样:
var docDefinition = {
content: { stack: parseSection(objectives) }
}
Here is a greatly simplified summary of the function:
这是一个非常简化的函数摘要:
function parseSection(section){
var stack = []
...
str1 = "{ text:'" + fooVar + "',style: 'normal', margin: [0,1,0,0] }"
str2 = "{ text:'" + barVar + "',style: 'bold', margin: [0,1,0,0] }"
stack.push( str1 )
stack.push( str2 )
...
return stack
})
Problem is, pdfMake will render as strings verbatim str1 and str2 rather than process the definitions.
问题是,pdfMake将作为字符串逐字渲染str1和str2,而不是处理定义。
What else can we do (or what else can we look for) to deliver the stack definition as an array (object?) that pdfMake's document definition can understand and render correctly?
我们还能做什么(或者我们还能找到什么)将堆栈定义作为数组(对象?)传递,pdfMake的文档定义可以正确理解和呈现?
1 个解决方案
#1
0
You are passing a string. Construct and return objects instead. Like so:
你正在传递一个字符串。而是构造和返回对象。像这样:
function parseSection(section){
var stack = []
obj1 = {
text: fooVar,
style: 'normal',
margin: [0,1,0,0]
}
obj2 = {
text: barVar,
style: 'bold',
margin: [0,1,0,0]
}
stack.push( obj1 )
stack.push( obj2 )
return stack
})
#1
0
You are passing a string. Construct and return objects instead. Like so:
你正在传递一个字符串。而是构造和返回对象。像这样:
function parseSection(section){
var stack = []
obj1 = {
text: fooVar,
style: 'normal',
margin: [0,1,0,0]
}
obj2 = {
text: barVar,
style: 'bold',
margin: [0,1,0,0]
}
stack.push( obj1 )
stack.push( obj2 )
return stack
})