Quy trình Review và Export thường được thực hiện ở bước cuối cùng.
Định nghĩa DrawPDF
const DrawPDF = window.DrawPDF.default;
Nếu bạn đã có chuỗi HTML, sử dụng hàm .parseHtml() để tạo
blueprint chuẩn.
const html = `
Báo Cáo Review
Đây là file PDF được tạo từ quy trình Review & Export.
Mục Trạng Thái
Code Review Passed
Export Test Success
`";
const blueprint = DrawPDF.parseHtml(html);
Blueprint là object JSON chứa cấu trúc và style đã được parse.
console.log(blueprint);
Nếu bạn đã có blueprint data thì không cần parse lại html, bạn có thể sử dụng blueprint data trực tiếp.
const blueprint = {
"pages": [
{
"width": 595.28,
"height": 841.89,
"elements": [
{
"type": "text",
"content": "Báo Cáo Review",
"style": {
"fontSize": 24,
"fontWeight": "bold",
"color": "darkblue"
},
"x": 50,
"y": 50
}
]
}
]
};
Bạn có thể set data vào các biến của blueprint bằng cách sử dụng hàm
setData.
Hàm rút gọn khi download file pdf vừa set:
const pdf = new DrawPDF();
pdf.setData(blueprint);
pdf.download('document-final.pdf');
set data binding to blueprint before create pdf
const pdf = new DrawPDF(); pdf.setData(blueprint); pdf.render(data); pdf.download('document-final.pdf');orconst pdf = new DrawPDF(); pdf.setData(blueprint); pdf.download('document-final.pdf', data);
Sử dụng hàm downloadBlueprint để tạo và tải file PDF từ
blueprint này.
await DrawPDF.downloadBlueprint( blueprint, 'document-final.pdf' );Orawait DrawPDF.downloadBlueprint( blueprint, 'document-final.pdf', data );
Kết quả PDF sẽ được hiển thị hoặc tải về.