Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
In an era defined by the seamless exchange of information, the role of the scanned PDFs and documents in our daily lives cannot be understated. PDFs, short for Portable Document Format, have become the go-to standard for sharing and preserving documents across different platforms and devices. As a result, the demand for versatile and feature-rich tools to create, manipulate, and interact with PDFs has skyrocketed.
Enter the Node PDF SDK, a powerful and versatile toolkit that has revolutionized the way developers work with PDF files. With its ability to harness the capabilities of the Node.js environment, this SDK has emerged as a game-changer, making PDF document management more accessible and efficient than ever before. There are many Node PDF APIs out there like adobe pdf services API and many more other PDF APIs, but we will use the best Node PDF SDK out there.
In this article we will discuss a Node-JS PDF SDK and how to use this SDK to meet all your PDF manipulation needs using Node-JS. The PDF SDK we will discuss today is IronPDF for Node.JS, its introduction, details on how to install it, and how to use it to manipulate PDF files.
IronPDF is a powerful and versatile library that empowers developers to work with PDF documents in Node.js applications with ease and efficiency. Whether you need to create, edit, or manipulate PDF files, IronPDF provides a comprehensive set of tools and features to streamline your workflow.
PDF (Portable Document Format) is a widely used file format for document exchange due to its compatibility and consistency across various platforms. With IronPDF for Node.js, you can automate the generation of PDFs, extract data from existing PDFs, and perform various tasks related to access to PDF documents programmatically.
In this section we will discuss how you can set up the environment and install IronPDF for Node-JS.
Before starting make sure you have Node.js installed on your system.
mkdir IronPDF
This will create a new directory in which we can set up our project.
cd IronPDF
This command will go to the newly created directory.npm init -y
This command will create a package.json file, which will store project-related metadata and dependencies and all the environment variables.
Once our initial setup is completed let's install IronPDF using the following command.
npm i @ironsoftware/ironpdf
Now open the project in Visual Studio Code and create a new file named "index.js".
Now open the package.json structured JSON file and add the following JSON data in it to add the npm type module.
"type": "module",
Just like that IronPDF PDF is installed and our environment is ready for running the IronPDF code, document generation and executing operation.
Using IronPDF Node.js SDK to create PDF files and use other PDF services is a piece of cake, and you can create a PDF file with just a few lines of code. There are two most common ways used to create PDF files those are:
In this section we will see how to create PDF files using IronPDF Node.js PDF SDK. Using IronPDF you can convert HTML zip file or HTML content to PDF file.
import {PdfDocument} from "@ironsoftware/ironpdf";
(async () => {
const pdf = await PdfDocument.fromHtml("<h1 style='padding:100px'>This PDF is Created By Using IronPDF Node-JS PDF SDK</h1>");
await pdf.saveAs("pdf-from-html.pdf");
})();
This code demonstrates the use of the IronPDF library in a Node.js application to create a PDF document from a provided HTML string. It imports the PdfDocument
class, generates a PDF document from the HTML content using the fromHtml
method, and then saves a copy of the resulting PDF to a file named "pdf-from-html.pdf." The code leverages an immediately invoked async
function to ensure proper asynchronous handling, allowing the PDF creation and saving operations to complete before finishing execution.
Node.js PDF SDK offers the ability to create PDF files from URLs. This package gives the developers ability to convert web pages into PDF files on the go.
import {PdfDocument} from "@ironsoftware/ironpdf";
(async () => {
const pdf = await PdfDocument.fromUrl("https://www.google.com");
await pdf.saveAs("pdf-from-url.pdf");
})();
This code illustrates the usage of the IronPDF library in a Node.js application to convert a web page, in this case, Google's homepage, into a PDF document. It imports the PdfDocument
class, creates a PDF document by fetching content from the specified URL using the fromUrl
method, and then saves the resulting PDF as "pdf-from-url.pdf" in the current working directory. The code employs an immediately invoked async function to ensure proper asynchronous handling, allowing the PDF conversion and saving operations to complete before the code's execution concludes.
In this section we will merge the two PDF files that we created above and create a new PDF file with just a few lines of code. You can merge multiple PDFs to create dynamic documents
for contracts and agreements, invoices, proposals, reports, forms, branded marketing documents and more.
import {PdfDocument} from "@ironsoftware/ironpdf";
(async () => {
const pdf1 = await PdfDocument.fromFile("pdf-from-html.pdf");
const pdf2 = await PdfDocument.fromFile("pdf-from-url.pdf");
const arrayOfPDFs = [pdf1, pdf2];
console.log(arrayOfPDFs)
const merge_pdf = await PdfDocument.mergePdf(arrayOfPDFs)
await merge_pdf.saveAs("merged_PDF.pdf");
})();
This code employs the IronPDF library in a Node.js application to merge two PDF documents, "pdf-from-html.pdf" and "pdf-from-url.pdf," into a single PDF file named "merged_PDF.pdf." It starts by creating two PdfDocument
instances from existing PDF files and then assembles them into an array called arrayOfPDFs
. Use console log to check the content of the array. Using the PdfDocument.mergePdf
method, the code combines the PDFs from the array into a unified document, which is stored in the merge_pdf
variable. Finally, the merged PDF source file is saved to the current working directory with the filename "merged_PDF.pdf." The code utilizes an immediately invoked async function to manage asynchronous operations effectively, ensuring that the merging and saving tasks are completed before the code execution concludes.
In a digital age where the exchange of information is ubiquitous, PDF documents have emerged as a cornerstone for sharing and preserving content across diverse platforms and devices. The Node PDF SDK, with its capacity to harness the power of Node.js, has become a pivotal tool in the realm of PDF document management, offering a versatile and efficient approach to handling PDF files. This article has focused on IronPDF for Node-JS, outlining its introduction, installation, and practical usage for PDF manipulation.
With a range of features at its disposal, including PDF creation, HTML-to-PDF conversion, PDF editing, form handling, and PDF merging, IronPDF empowers developers to work seamlessly with PDFs in a cross-platform environment. The installation process is straightforward, and creating, editing, or merging PDF files is made easy through simple yet powerful code examples. This Node PDF SDK has redefined the landscape of PDF document management, making it an indispensable tool for developers looking to streamline their PDF-related workflows.
To know more about IronPDF for Node.js please refer to the following link. The complete sample of source code can be found here at this link. Users can opt for a free trial license to test out all the key features of IronPDF for Node.js library before deciding to purchase a commercial license.
9 .NET API products for your office documents