我已经在估算表格上创建了一个按钮以打印高级PDF。
但是,我在日志中得到以下错误
java.lang.java.lang.StringIndexOutOfBoundsException:字符串索引超出范围:0
我已经读过某个地方,它可能与模板中的图像有关,但是我尝试将其取出并仍然出现错误。
有人对我有这个想法吗?
生成/渲染PDF的代码为:
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope Public
*/
define([
'SuiteScripts/Directory/Library.js'
, 'N/render'
, 'N/record'
],
function (Library, render, record)
{
/**
* Main entry function
*
* @param {Object} context
* @returns {Void}
*/
function PrintPriceIncreaseQuote(context)
{
var renderer = null;
try
{
if (context.request.method == 'GET')
{
renderer = createRenderer(context);
printTemplate(context.response, renderer);
}
}
catch (e)
{
Library.errorHandler('PrintPriceIncreaseQuote', e);
}
}
/**
* Create renderer
*
* @param {Object} context
* @returns {Object} renderer
*/
function createRenderer(context)
{
var renderer = null;
var recordId = 0;
try
{
recordId = context.request.parameters.id;
//Create the renderer object
renderer = render.create();
renderer.setTemplateByScriptId('CUSTTMPL_125_4099_SB7_165');
renderer.addRecord({templateName: 'record',
record: record.load({
type: record.Type.ESTIMATE,
id: recordId
})
});
}
catch (e)
{
Library.errorHandler('createRenderer', e);
}
return renderer;
}
/**
* Print merged template
*
* @param {Object} response
* @param {Object} renderer
* @returns {Void}
*/
function printTemplate(response, renderer)
{
var pdfFile = null;
try
{
pdfFile = renderer.renderAsPdf();
response.writeFile({file: pdfFile, isInline: true});
}
catch (e)
{
Library.errorHandler('printTemplate', e);
}
}
return {
onRequest: PrintPriceIncreaseQuote
};
});
'''/**
答案 0 :(得分:0)
我尝试了您的代码,它与我的XML / PDF模板配合得很好。检查XML DOM结构。