A library of JavaScript for producing PDFs: Resolving Unicode and Chinese issues
Based on the canvas and jspdf libraries, the JavaScript-enabled PDF generation utility is implemented.
Reference:
Http://javascript.ruanyifeng.com/htmlapi/canvas.html
1. Use canvas to write Chinese to the canvas, and then convert the canvas into a picture to solve the Chinese problem.
<!DOCTYPE HTML><HTML><Head></Head><Body><CanvasID= "MyCanvas"width= "$"Height= "$"></Canvas><DivID= "Mydiv"></Div><Scripttype= "Text/javascript">varCanvas=document.getElementById ("MyCanvas");if(canvas.getcontext) {varCTX=Canvas.getcontext ("2d");//Set FontCtx.font= "Bold 20px Arial";//Set Alignmentctx.textalign= " Left";//Set Fill ColorCtx.fillstyle= "#008600";//set the font content and position on the canvasCtx.filltext ("Oh, yes!", Ten, -);//Draw Hollow WordsCtx.stroketext ("Oh , yes!", Ten, -);//Save to PNGvarImage= NewImage (); IMAGE.SRC=Canvas.todataurl ("Image/png");//create ' img ' element in memoryvarNodeimage=Document.createelement ("img"); Nodeimage.src=image.src;//append element to HTMLvarNodediv=document.getElementById ("mydiv"); Nodediv.appendchild (nodeimage);};</Script></Body></HTML>
2. Embed the Chinese image into the PDF using the Jspdf image embedding feature to enable the front-end generation of the Chinese PDF.
Http://parall.ax/products/jspdf
A library of JavaScript for producing PDFs: Resolving Unicode and Chinese issues