NetSuite Restlet PDF file encoding issue

穿精又带淫゛_ 提交于 2019-12-12 04:07:53

问题


My code correctly creates a file in document repository as well as attach it to a record in NetSuite. However, the file type is 'Other Binary File' when it should be a PDF. I read that for PDF we must encode in base 64 but even then it doesn't generate the 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
}

回答1:


You will have to generate your PDF using BFO. Here's a quick example that generates a PDF with the string "test" inside:

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);
}



回答2:


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.

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.

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').

Also, check out nlapiXMLToPDF(). This function lets you define your content in an XML string and generate a PDF from it.



来源:https://stackoverflow.com/questions/36154650/netsuite-restlet-pdf-file-encoding-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!