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