Tích hợp đơn giản với mọi ngôn ngữ lập trình. Chỉ cần gửi HTML, nhận về PDF.
Chọn ngôn ngữ lập trình bạn đang sử dụng
// Vanilla JavaScriptconst apiKey = 'YOUR_API_KEY';const html = '<h1>Xin chào!</h1><p>Nội dung PDF của bạn</p>';const response = await fetch('https://pdf.toolapp.name.vn/api/generate-pdf', { method: 'POST', headers: { 'Content-Type''application/json', 'x-api-key': apiKey }, body: JSON.stringify({ html })});if (response.ok) { const blob = await response.blob(); // Download file const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'document.pdf'; a.click(); URL.revokeObjectURL(url);}POST /api/generate-pdfContent-Type: application/jsonx-api-key: YOUR_API_KEY{
"html": "<h1>Nội dung HTML</h1>"
}File PDF binary (Content-Type: application/pdf)
X-RateLimit-Limit - Giới hạn thángX-RateLimit-Remaining - Lượt còn lạiX-Response-Time - Thời gian xử lý401 - Thiếu API key403 - API key không hợp lệ429 - Hết lượt sử dụng500 - Lỗi server@page để định nghĩa khổ giấy<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<style>
@page { size: A4; margin: 15mm; }
body { font-family: Arial, sans-serif; font-size: 14px; }
.header { text-align: center; margin-bottom: 30px; }
.title { font-size: 24px; color: #2563eb; }
table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid #ddd; padding: 10px; }
th { background: #3b82f6; color: white; }
</style>
</head>
<body>
<div class="header">
<h1 class="title">TIÊU ĐỀ TÀI LIỆU</h1>
</div>
<!-- Nội dung của bạn -->
</body>
</html>Sử dụng @page trong CSS để điều khiển kích thước, hướng và lề của trang PDF.
size: A4;Khổ A4 dọc (210mm × 297mm)size: A4 landscape;Khổ A4 ngang (297mm × 210mm)size: A3;Khổ A3 (297mm × 420mm)size: A5;Khổ A5 (148mm × 210mm)size: letter;Letter US (216mm × 279mm)size: 100mm 150mm;Kích thước tùy chỉnh (W × H)margin: 15mm;Lề đều 4 phíamargin: 10mm 20mm;Trên/dưới, trái/phảimargin: 10mm 15mm 20mm;Trên, trái/phải, dướimargin: 10mm 15mm 20mm 15mm;Trên, phải, dưới, tráimargin-top: 20mm;Chỉ lề trênmargin-bottom: 25mm;Chỉ lề dướiHóa đơn A4 dọc:
@page {
size: A4;
margin: 15mm;
}Báo cáo A4 ngang:
@page {
size: A4 landscape;
margin: 10mm 20mm;
}Sử dụng margin boxes để thêm số trang, tiêu đề, footer vào vùng lề của PDF.
@top-leftGóc trên trái@top-centerGiữa trên (tiêu đề)@top-rightGóc trên phải@bottom-leftGóc dưới trái@bottom-centerGiữa dưới@bottom-rightGóc dưới phảicounter(page)Số trang hiện tạicounter(pages)Tổng số trangcontent - Nội dung hiển thịfont-size - Cỡ chữfont-family - Font chữfont-weight - Độ đậmcolor - Màu chữSố trang góc dưới phải:
@page {
size: A4;
margin: 15mm;
@bottom-right {
content: "Trang " counter(page)
"/" counter(pages);
font-size: 9pt;
font-family: "Times New Roman", serif;
}
}Tiêu đề + số trang:
@page {
size: A4;
margin: 20mm 15mm;
@top-center {
content: "BÁO CÁO DOANH THU";
font-size: 10pt;
font-weight: bold;
color: #2563eb;
}
@bottom-center {
content: counter(page);
font-size: 9pt;
}
}Header trái/phải + Footer:
@page {
size: A4;
margin: 20mm;
@top-left {
content: "Công ty ABC";
font-size: 9pt;
}
@top-right {
content: "Ngày: 12/01/2025";
font-size: 9pt;
}
@bottom-right {
content: "Trang " counter(page);
font-size: 9pt;
}
}Hợp đồng với footer công ty:
@page {
size: A4;
margin: 25mm 20mm 30mm 20mm;
@bottom-center {
content: "Công ty TNHH XYZ - "
"ĐT: 028.1234.5678";
font-size: 8pt;
color: #666;
}
@bottom-right {
content: counter(page) "/"
counter(pages);
font-size: 8pt;
}
}