尝试在suitescript中创建一个模板的pdf



我正在使用suitescript 2.1。

我的目标是发送一个对象,该对象包含N/render模块所需的数据,以便从包含我的Map/Reduce脚本中所有数据的模板中获取PDF文件。

我期望的结果是收到一封包含PDF及其所有内容的电子邮件发送到我的邮箱。我确实发了一封电子邮件,里面有一个你好世界的pdf文件。我想问题出在我设置模板的方式上,但我不能确定。这是我得到的错误:

execute on com.sun.proxy.$Proxy954.setTemplate failed due to: Cannot convert '{id: accessor, size: accessor, url: accessor, path: accessor, fileType: accessor, isText: accessor, encoding: accessor, name: accessor, f...'(language: JavaScript, type: NetSuiteObject) to Java type 'java.lang.String': Invalid or lossy primitive coercion.

这是我的函数:

function generatePdfFileFromRawXml(jsonObj) {
const templateId = file.load({
id: './QuotesMonthPDF.template.xml',
});
const renderer = render.create();
renderer.templateContent = templateId;
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: 'JSON',
data: jsonObj,
});

这是我的模板目前模板没有字段,我正在测试它是否工作

<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<head>
<link name="NotoSans" type="font" subtype="truetype" src="${nsfont.NotoSans_Regular}" src-bold="${nsfont.NotoSans_Bold}" src-italic="${nsfont.NotoSans_Italic}" src-bolditalic="${nsfont.NotoSans_BoldItalic}" bytes="2" />
<#if .locale == "zh_CN">
<link name="NotoSansCJKsc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKsc_Regular}" src-bold="${nsfont.NotoSansCJKsc_Bold}" bytes="2" />
<#elseif .locale == "zh_TW">
<link name="NotoSansCJKtc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKtc_Regular}" src-bold="${nsfont.NotoSansCJKtc_Bold}" bytes="2" />
<#elseif .locale == "ja_JP">
<link name="NotoSansCJKjp" type="font" subtype="opentype" src="${nsfont.NotoSansCJKjp_Regular}" src-bold="${nsfont.NotoSansCJKjp_Bold}" bytes="2" />
<#elseif .locale == "ko_KR">
<link name="NotoSansCJKkr" type="font" subtype="opentype" src="${nsfont.NotoSansCJKkr_Regular}" src-bold="${nsfont.NotoSansCJKkr_Bold}" bytes="2" />
<#elseif .locale == "th_TH">
<link name="NotoSansThai" type="font" subtype="opentype" src="${nsfont.NotoSansThai_Regular}" src-bold="${nsfont.NotoSansThai_Bold}" bytes="2" />
</#if>
<style type="text/css">table { font-size: 9pt; table-layout: fixed; width: 100%; }
th { font-weight: bold; font-size: 8pt; vertical-align: middle; padding: 5px 6px 3px; background-color: #e3e3e3; color: #333333; padding-bottom: 10px; padding-top: 10px; }
td { padding: 4px 6px; }
b { font-weight: bold; color: #333333; }
</style>
</head>
<body padding="0.5in 0.5in 0.5in 0.5in" size="Letter">
</body>
</pdf>

问题出在这一行:

renderer.templateContent = templateId;

正确的方法是:

renderer.templateContent = templateId.getContents();

相关内容

最新更新