我正在尝试使用 Restlet 将提供的发票记录的 PDF 呈现到文件柜中,但我找不到我们正在使用的自定义 PDF 布局表单的 XML 模板。
我们的 PDF 模板文件夹是空的,并且该模板没有出现在我认为应该出现的高级 PDF/HTML 模板中。
该表单出现在交易表单 PDF 布局中:有没有办法访问该模板并在高级 PDF/HTML 模板中创建副本,或者在其当前所在的位置引用它?
这是我的函数,但我不知道要提供什么值
xmlTemplateFilePath
function createPdf(fileName, invoiceId, folderId) {
const f = file.create({
name: fileName + '.pdf',
fileType: file.Type.PDF,
folder: folderId,
isOnline: true
});
const xmlTemplateFile = file.load(xmlTemplateFilePath);
const renderer = render.create();
renderer.templateContent = xmlTemplateFile.getContents();
renderer.addRecord('grecord', record.load({
type: record.Type.INVOICE,
id: invoiceId
}));
const invoicePdf = renderer.renderAsPdf();
f.write(invoicePdf);
f.save();
}
已解决(使用@bknights解决方案)
render.transaction 返回一个文件对象,因此我也能够简化它。
function createPdf(fileName, invoiceId, folderId) {
const invoicePdfFile = render.transaction({
entityId: Number(invoiceId),
printMode: render.PrintMode.PDF,
inCustLocale: true
});
invoicePdfFile.name = fileName + '.pdf';
invoicePdfFile.folder = folderId;
invoicePdfFile.save();
}
渲染标准交易不适用于这样的显式模板。
你会使用
render.transaction
const invoicePdf = render.transaction({
entityId:invoiceId,
//formId: form linked to custom pdf template
printMode:render.PrintMode.PDF,
inCustLocale: true
});
如果您尝试使用特定的 PDF 模板,则必须在事务表单中指定它,然后使用该表单的 ID 作为 formId 参数。