2020-11-27javascript
提起NS,在程序員這一塊應該不怎麼被人知道,算是比較小衆的一門技術了,畢竟Netsuite興起的時間算不上早,進入中國的時間更晚,除了從事這一塊的程序員,可能都沒有見過,剛好我是從事這塊的。寫這個的目的一是記錄一些本身的職業生涯,二是概括一些知識點吧。css
/** * @NApiVersion 2.x * @NScriptType Suitelet * @NModuleScope SameAccount */ define([ 'N/file', 'N/render', '../third/handlebars.min.js' ], function(file, render, cuxHandlebars) { /** * Definition of the Suitelet script trigger point. * * @param {Object} * context * @param {ServerRequest} * context.request - Encapsulation of the incoming request * @param {ServerResponse} * context.response - Encapsulation of the Suitelet response * @Since 2015.2 */ function onRequest(context) { var response = context.response; var request = context.request; var data = {}; model = file.load({ id : "../xml/barcode_model.xml" }).getContents(); var pdfXml = renderPage(model, data); var pdfFile = render.xmlToPdf({ xmlString : pdfXml }); response.writeFile({ file : pdfFile, isInline : true }); } /** * handlebars編譯並加載對象 * * @param html * @param page_object * @returns */ function renderPage(html, page_object) { var template = cuxHandlebars.compile(html); return template(page_object); } return { onRequest : onRequest }; });
xml中的代碼 xml中實現條形碼的標籤是barcode,一共有這幾個屬性 bar-width的範圍是「0.6-1」主要用於控制條形碼的長度,該屬性能夠不寫,默認爲1,也能夠經過style的width屬性設置條形碼的寬度,經測試只對code128系列碼生效, codetype="code128"用於控制條形碼的類型,showtext="true",該屬性爲布爾類型,用於控制是否展現條形碼下面文本,true爲展現,false爲不展現。html
<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd"> <pdf lang="ZH_CN"> <!--HAND PDF/HTML Template --> <head> <macrolist> </macrolist> <style type="text/css"> span { font-size:12pt; } </style> </head> <body width="10cm" height="10cm" padding="0.1cm 0.1cm 0.1cm 0.1cm"> <!--表體 --> <table width="100%"> <tr height="20px"> <td align="center" valign="middle"> <span>code128碼</span> </td> </tr> <tr height="20px"> <td align="center" valign="middle"> <barcode style="height:30px;" codetype="code128" showtext="true" value="123sku" /> </td> </tr> <tr height="30px"> <td align="center" valign="middle"> <barcode style="height:20px;" bar-width="0.7" codetype="code128" showtext="true" value="123sku" /> </td> </tr> <tr height="30px"> <td align="center" valign="middle"> <barcode style="height:30px;" codetype="code128" showtext="true" value="123sku" /> </td> </tr> <tr height="30px"> <td align="center" valign="middle"> <barcode style="height:30px;" codetype="code128" showtext="true" value="123sku" /> </td> </tr> </table> </body> </pdf>
展現效果 下面分別展現了xml中的實現效果java
<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd"> <pdf lang="ZH_CN"> <!--HAND PDF/HTML Template --> <head> <macrolist> </macrolist> <style type="text/css"> span { font-size:12pt; } </style> </head> <body width="10cm" height="10cm" padding="0.1cm 0.1cm 0.1cm 0.1cm"> <!--表體 --> <table width="100%"> <tr height="70px"> <td align="center" valign="middle"> <barcode style="height:60px;" codetype="ean13" showtext="true" value="6926742738053" /> </td> </tr> <tr height="70px"> <td align="center" valign="middle"> <barcode style="height:60px;" codetype="ean13" showtext="false" value="6926742738053" /> </td> </tr> </table>
</body> </pdf>
<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd"> <pdf lang="ZH_CN"> <!--HAND PDF/HTML Template --> <head> <macrolist> </macrolist> <style type="text/css"> span { font-size:12pt; } </style> </head> <body width="10cm" height="10cm" padding="0.1cm 0.1cm 0.1cm 0.1cm"> <table width="100%"> <tr height="70px"> <td align="center" valign="middle"> upca碼 <barcode style="height:60px;" codetype="upca" showtext="true" value="692674273806" /> </td> </tr> <tr height="70px"> <td align="center" valign="middle"> <barcode style="height:60px;" codetype="upca" showtext="false" value="692674273806" /> </td> </tr> </table> </body> </pdf>
展現效果程序員
barcode標籤能實現的不單單是這幾種條形碼,經過正確的value和codetype屬性能夠實現如下類型全部圖碼。less