Node.JS學習筆記(11)_pdf輸出_中文會亂碼
npm install pdfkit
測試1.
const PDFDocument = require('pdfkit');
const fs = require('fs');
let pdfDoc = new PDFDocument;
pdfDoc.pipe(fs.createWriteStream('SampleDocument.pdf'));
pdfDoc.text("My Sample PDF Document");
pdfDoc.end();
測試2.
// Importing required modules
const PDFDocument = require("pdfkit");
const fs = require("fs");
// Creating a new instance of PDFDocument class
const doc = new PDFDocument();
// Piping the output stream to a file
// named "output.pdf"
doc.pipe(fs.createWriteStream("output.pdf"));
// Setting the fill color to green and
// font size to 30
doc.fillColor("green")
.fontSize(30)
.text("我的pdf測試");
// Setting the fill color to black and
// font size to 15
doc.fillColor("black")
.fontSize(15)
.text("It is the best platform for :- ");
// Adding multiple lines of text to
// the document
doc.text("Programming");
doc.text("Data Structures");
doc.text("Web development");
doc.text("Android development");
doc.text("Artificial intelligence, etc.");
// Ending the document
doc.end();
Ref:
https://hexquote.com/create-pdf-documents-using-node-js-pdfkit/
https://stackabuse.com/generating-pdf-files-in-node-js-with-pdfkit/?ref=morioh.com&utm_source=morioh.com
https://javascript.plainenglish.io/how-to-serve-pdfs-via-node-js-2b5a3ba01311
https://techsolutionstuff.com/post/how-to-generate-pdf-file-in-node-js-using-pdfkit
https://www.geeksforgeeks.org/how-to-create-and-manipulate-pdf-documents-in-node-js-with-pdfkit-module/
https://medium.com/@r3850355/%E7%94%A8javascript%E8%87%AA%E5%B7%B1%E5%81%9Apos%E5%87%BA%E5%96%AE%E5%8A%9F%E8%83%BD-ad54b6640477
https://www.twblogs.net/a/5d405048bd9eee51fbf98cb5
字體問題
https://www.jianshu.com/p/9ef9a023af41
https://blog.csdn.net/qq296398300/article/details/70145206
https://cloud.tencent.com/developer/article/1388832?from=15425
https://www.jianshu.com/p/b6469e08af3c
simsun.ttf(宋體)
simsunbd(粗體宋體)
msyh.ttf(微軟雅黑)
msyhbd(粗體微軟雅黑)
msjh.ttf(微軟簡黑)
msjhbd(粗體微軟簡黑)
simhei(黑體)
留言
張貼留言