2017-04-07 14 views
0

我正在使用jsreport(通过npm)使用phantom-pdf配方从HTML呈现PDF。jsreport with phantom-pdf recipe:如何设置格式,边距,方向等基本设置?

渲染是通过HTTPS调用开始:

https://127.0.0.1/api/report

...和POST数据是这样的一个字符串:

{ 
"template": { 
    "content": /*...my HTML content template to render...*/, 
    "recipe": "phantom-pdf", 
    "engine": "handlebars" 
    }, 
"data": /*json string with data to pass to the template*/ 
} 

我知道有基本的设置为幻影pdf(边距,格式,宽度,高度,方向,printDelay,waitForJS),但我不明白在哪里把他们: - 在HTML模板? - 在jsreport的dev.conig.json文件中? - 在一个单独的文件?

...以及如何?

预先感谢您!

回答

1

您可以将这些设置作为API请求主体的一部分发送给template.phantom属性。

{ 
    "template": { 
    "content": /*...my HTML content template to render...*/, 
    "recipe": "phantom-pdf", 
    "engine": "handlebars", 
    "phantom": { "margin": "5cm" } 
    }, 
    "data": { "foo": "Hello" } 
} 
+0

谢谢。如果我想用模板存储这些设置,我该怎么办? –

+0

我不明白这个问题。您只需在jsreport studio中按下保存按钮,并保存这些设置。 –

+0

那是因为我不能使用jsreport studio。我必须手动编辑模板文件。谢谢 –