PDFKit npm 與 IronPDF for Node.js 比較
在這個介紹中,我將深入探討 IronPDF 和 PDFKit 這兩個 JavaScript PDF 庫的知名產品。這兩者都是 Node.js 專案的不錯選擇,但它們各有優劣。
閱讀更多
Node.js PDF庫
import {PdfDocument} from "@ironsoftware/ironpdf";
(async () => {
// Create a PDF from an HTML string
const pdf = await PdfDocument.fromHtml("<h1>Hello World</h1>");
// Export the PDF to a file
await pdf.saveAs("output.pdf");
// Advanced Example with HTML Assets
// Load external HTML assets: Images, CSS, and JavaScript.
const htmlContentWithAssets = "<img src='icons/iron.png'>";
const advancedPdf = await PdfDocument.fromHtml(htmlContentWithAssets);
// Save the PDF with loaded assets
await advancedPdf.saveAs("html-with-assets.pdf");
})();
import {PdfDocument} from "@ironsoftware/ironpdf";
(async () => {
// Render the HTML file
const pdf = await PdfDocument.fromHtml("example.html");
// Export the PDF document
await pdf.saveAs("output.pdf");
})();
import {PdfDocument} from "@ironsoftware/ironpdf";
(async () => {
// Render the web URL to PDF
const pdf = await PdfDocument.fromUrl("https://ironpdf.com/");
// Export the PDF document
await pdf.saveAs("url.pdf");
})();
import {PdfGenerator} from "@ironsoftware/ironpdf";
import fs from 'fs';
(async () => {
// Specify the directory path
const directoryPath = './images';
// Read the contents of the directory
fs.readdir(directoryPath, (err, files) => {
if (err) {
console.error('Error reading directory:', err);
return;
}
// Filter file names to include only .jpg and .jpeg extensions
const jpegFiles = files.filter((file) =>
file.toLowerCase().endsWith('.jpg') || file.toLowerCase().endsWith('.jpeg')
);
// Construct full file paths for the filtered files
const filePaths = jpegFiles.map((file) => `${directoryPath}/${file}`);
// Converts the images to a PDF and save it.
const pdf = PdfGenerator.imageToPdf(filePaths).then(
(returnedPdf)=> {
returnedPdf.saveAs("composite.pdf");
});
// Also see PdfDocument.rasterizeToImageFiles() method to flatten a PDF to images or thumbnails
});
})();
想將 IronPDF 部署到現實專案中免費使用嗎?
您的試用金鑰應該在郵件中。試用表格已提交
成功地.
如果不是,請聯繫
support@ironsoftware.com
想將 IronPDF 部署到現實專案中免費使用嗎?
您的試用金鑰應該在郵件中。試用表格已提交
成功地.
如果不是,請聯繫
support@ironsoftware.com
想將 IronPDF 部署到現實專案中免費使用嗎?
您的試用金鑰應該在郵件中。試用表格已提交
成功地.
如果不是,請聯繫
support@ironsoftware.com
想將 IronPDF 部署到現實專案中免費使用嗎?
您的試用金鑰應該在郵件中。試用表格已提交
成功地.
如果不是,請聯繫
support@ironsoftware.com
免費開始
不需要信用卡
在生產環境中測試無浮水印。
在任何需要的地方都能運作。
獲得30天完全功能的產品。
幾分鐘內即可啟動並運行。
試用產品期間完全訪問我們的支援工程團隊
免費開始
不需要信用卡
在生產環境中測試無浮水印。
在任何需要的地方都能運作。
獲得30天完全功能的產品。
幾分鐘內即可啟動並運行。
試用產品期間完全訪問我們的支援工程團隊
功能齊全的產品,立即獲取序號