Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
This post will utilize IronPDF, a library tool that can compress PDFs in Node.js at different levels. A few lines of code are sufficient to create, open, read, and compress PDF files with IronPDF, a robust PDF library. To know more about data compression level, refer to this Wiki page.
Node.js is a cross-platform, open-source JavaScript runtime environment that allows JavaScript code to be executed outside of a web browser. It enables programmers to create scalable, quick, and efficient network applications by enabling server-side JavaScript execution. Because Node.js is lightweight and ideal for developing real-time applications that manage numerous concurrent connections, it employs an event-driven, non-blocking I/O paradigm.
Web servers, APIs, streaming apps, real-time chat apps, Internet of Things (IoT) devices, and more are among the many applications that are frequently built with Node.js. All things considered, Node.js has become increasingly popular because of its effectiveness, speed, and compatibility with JavaScript for both front-end and back-end development, providing a single language for full-stack development.
compressSize
method.compressSize
function.The main purpose of the .NET library IronPDF is to create, edit, and handle PDF documents within .NET applications. IronPDF may not have direct, native support for Node.js, and it is primarily meant to be used with the .NET Framework like C# or VB.NET.
It's crucial to remember that the benefits would mostly depend on the particular needs of your project as well as IronPDF's capability, compatibility, and ease of interaction with Node.js. For the most up-to-date and accurate information regarding Node.js compatibility and integration, always make sure to study the most recent documentation, official sources, or updates from IronPDF. To know more about IronPDF refer to these documentation pages.
Access the Command Prompt or Terminal: Open your command line interface. Depending on your operating system, you can access it:
Set up the package: To install a package, use the npm install command and the package name. To install a package called @ironsoftware/ironpdf
, for instance, enter the following command:
npm install @ironsoftware/ironpdf
npm install @ironsoftware/ironpdf
The name of the actual package you want to install should be substituted as per your requirements.
Install IronPDF
PDF files can be effectively compressed with IronPDF. Keeping the images in the PDF file as small as possible is crucial. The process of optimization can be initiated by using the compressSize
method on the PDF object.
const { PdfDocument } = require('@ironsoftware/ironpdf');
// Define an asynchronous function to perform PDF compression
const pdfprocess = async () => {
console.log('Start compression Process'); // Notify the start of the process
// Load the existing PDF document from the specified path
const pdf = await PdfDocument.fromFile("Demo.pdf");
// Compress images in the PDF with a quality parameter (1-100)
await pdf.compressSize(60);
// Save the compressed PDF with the specified name
await pdf.saveAs("Result_60.pdf");
// Further compress images, scaling them down based on visible size
await pdf.compressSize(90, true);
// Save the further scaled and compressed PDF
await pdf.saveAs("Result_90.pdf");
console.log('End compression Process'); // Notify the end of the process
};
// Execute the PDF compression function
pdfprocess();
In the above code, first, import the IronPDF library. With the help of the method fromFile
available in the PdfDocument
class, load the existing PDF file. Then hold the data in an object variable which allows performing various types of operations. A compressSize
method is used and passes two parameters: image quality and image scale which will optimize PDFs. Use the saveAs
method to save the PDF file to the specified location.
The console output
Result:
The result of compressed PDF files
The quality setting is critical when resizing JPEG images. The least amount of loss occurs when the quality level is 100%, but 1% results in very low-quality output. Images with a quality rating of 90% or greater are typically considered high-quality, 80%-90% as medium-quality, and 70%-80% as low quality. Reducing the quality below 70% could lead to lower-quality photographs but significantly reduces the total file size of the PDF publication.
To find the perfect file size to image quality ratio that suits your requirements, it is advisable to experiment with different quality settings. The degree of quality loss will ultimately depend on the sort of input image, with some images likely to lose clarity more noticeably than others. To learn more about this, click this sample page for more detailed compression settings.
To minimize risks and ensure data protection, the IronPDF library provides strong security features. It is compatible with any popular browser and isn't limited to a particular one. To satisfy the diverse needs of developers, the library offers multiple licensing alternatives, such as a complimentary developer license and supplementary development licenses that can be acquired.
A perpetual license, upgrade options, a year of software maintenance, and a 30-day money-back guarantee are included in the $749 Lite bundle. Users can evaluate the product in practical application settings for a watermarked trial period. Please visit the provided licensing page to learn more about IronPDF's costs, licensing, and trial version. To know other products offered by Iron Software refer to the official webpage.
Node.js is a cross-platform, open-source JavaScript runtime environment that allows JavaScript code to be executed outside of a web browser. It enables programmers to create scalable, quick, and efficient network applications by enabling server-side JavaScript execution.
To compress PDFs, first download the Node.js package. Create or import a PDF, then apply the `compressSize` method to minimize the size. Finally, export the compressed PDF file.
IronPDF is a .NET library designed to create, edit, and handle PDF documents within .NET applications. It may not have direct, native support for Node.js but can be used with Node.js applications.
IronPDF offers features like converting HTML files to PDFs, incorporating text, images, tables, forms, watermarks, encryption, and more. It is compatible with .NET technologies.
To install IronPDF for Node.js, open your command line interface and use the npm install command: `npm install @ironsoftware/ironpdf`.
The `compressSize` method in IronPDF is used to optimize and compress images within a PDF by adjusting the image quality and scale.
Yes, IronPDF is compatible with any popular browser and is not limited to a particular one.
IronPDF offers multiple licensing options including a complimentary developer license, perpetual licenses, and upgrade options. A 30-day money-back guarantee is also available.
It is recommended to use Visual Studio Code as the IDE, along with Node.js and a package manager like npm or Yarn.