javascript - 试图用suitescript中的模板制作pdf
问题描述
我正在使用套件脚本 2.1。
我的目标是发送一个对象,其中包含 N/render 模块所需的数据,以便从填充了我的 Map/Reduce 脚本中所有数据的模板中获取 PDF 文件。
我的预期结果是收到一封包含 PDF 及其所有内容的电子邮件发送到我的邮箱。我确实设法发送了一封带有 hello world 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();
推荐阅读
- javascript - 如何使用javascript同时触发输入键和按钮
- c# - 替换静态类以打包方法和变量
- c# - NetTopologySuite Distance 在 .net Core 3 中返回奇怪的结果
- google-apps-script - GoogleSheets - 有没有办法将用户信息从“显示编辑历史”提取到单元格?
- angular - 我们如何在 Angular 中设置从右到左的 Kendo UI?
- vb.net - 如何防止每个 MS Word 页面中的最后一句中断到下一页?
- ios - 在 swift 中使用 JSONSerialization 和 JSONDecoder 有什么区别?
- c# - 如何更改服务器端 Blazor 中的重新连接覆盖
- ios - 使用拆分视图控制器变灰的菜单项 - Catalyst
- javascript - waitFor() 找不到页面上显示的元素