简体   繁体   English

NetSuite Restlet PDF 文件编码问题

[英]NetSuite Restlet PDF file encoding issue

My code correctly creates a file in document repository as well as attach it to a record in NetSuite.我的代码在文档存储库中正确创建了一个文件,并将其附加到 NetSuite 中的记录。 However, the file type is 'Other Binary File' when it should be a PDF.但是,当它应该是 PDF 时,文件类型是“其他二进制文件”。 I read that for PDF we must encode in base 64 but even then it doesn't generate the PDF.我读到,对于 PDF,我们必须以 base 64 进行编码,但即便如此,它也不会生成 PDF。 Anyone see an issue?有人看到问题吗?

var fileobj = nlapiCreateFile(docname, doctype, doccontent)
        fileobj.setName(docname)
        fileobj.setFolder(folderid)
        fileobj.setIsOnline(true)
        fileobj.setEncoding('UTF-8')
        var fileid = nlapiSubmitFile(fileobj)

Passed in data:传入数据:

{
  "filecontent" : "test", 
  "filename" : "PO Doc Test",
  "filetype" : "PDF",
  "folderid" : 521,
  "recordtype": "purchaseorder",
  "recordid": 13832
}

You will have to generate your PDF using BFO.您必须使用 BFO 生成 PDF。 Here's a quick example that generates a PDF with the string "test" inside:这是一个生成包含字符串“test”的 PDF 的快速示例:

function createPDFFile(docname, folderid)
{
    var xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE pdf PUBLIC \"-//big.faceless.org//report\" \"report-1.1.dtd\">\n<pdf>\n<body font-size=\"18\">test</body>\n</pdf>";

    var fileobj= nlapiXMLToPDF(xml);

    fileobj.setName(docname);
    fileobj.setFolder(folderid);
    fileobj.setIsOnline(true);
    fileobj.setEncoding('UTF-8');

    var fileid = nlapiSubmitFile(fileobj);
}

In my test of your code, changing the filename from PO Doc Test to PO Doc Test.pdf creates a file in the file cabinet with a PDF File type rather than Other Binary File.在我对您的代码的测试中,将文件名从PO Doc Test更改为PO Doc Test.pdf会在文件柜中创建一个 PDF 文件类型而不是其他二进制文件的文件。

While this creates a file that NetSuite recognizes as type PDF File, it appears that test isn't valid PDF file content, so the resulting file can't be opened by Acrobat reader.虽然这会创建一个 NetSuite 识别为 PDF 文件类型的文件,但该test似乎不是有效的 PDF 文件内容,因此 Acrobat 阅读器无法打开生成的文件。

The docs say that when trying to create binary files like PDFs, the content must be base64 encoded so you should wrap your content in nlapiEncrypt(content, 'base64') .文档说,当尝试创建像 PDF 这样的二进制文件时,内容必须是 base64 编码的,因此您应该将内容包装在nlapiEncrypt(content, 'base64')

Also, check out nlapiXMLToPDF() .另外,请查看nlapiXMLToPDF() This function lets you define your content in an XML string and generate a PDF from it.此函数可让您在 XML 字符串中定义内容并从中生成 PDF。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM