💻 Review & Export Code

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;
        
      

1. Parse HTML to Blueprint

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ụcTrạng Thái
Code ReviewPassed
Export TestSuccess
`"; const blueprint = DrawPDF.parseHtml(html);

2. (Optional) Review Blueprint

Blueprint là object JSON chứa cấu trúc và style đã được parse.

console.log(blueprint);

3. If have blueprint data

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');
or

const pdf = new DrawPDF();
pdf.setData(blueprint);
pdf.download('document-final.pdf', data);

4. Export PDF

Sử dụng hàm downloadBlueprint để tạo và tải file PDF từ blueprint này.

await DrawPDF.downloadBlueprint(
    blueprint, 
    'document-final.pdf'
);
Or
await DrawPDF.downloadBlueprint(
    blueprint, 
    'document-final.pdf',
    data
);
Thử Nghiệm:
Nhấn nút bên dưới để giả lập quy trình Export một mẫu có sẵn.

📄 Review Preview

Kết quả PDF sẽ được hiển thị hoặc tải về.

Ready...