Compress PDF
PDF compression programmatically using Aspose.PDF Library in various programming languages
How to compress PDF files with the Aspose.PDF library
Aspose.PDF supports compression of PDF. The way in which the majority of PDF file size can be reduced is by reducing the size of embedding images within the PDF Document. Additionaly we can linearize document in order to open the first page as quickly as possible:
Invoking this method doesn’t actually saves the document. On the contrary the document only is prepared to have optimized structure, call then Save
to get optimized document.
Steps to reduce size PDF File
You need Aspose.PDF library to try the code in your environment.
- Open a PDF document using Document object.
- Call the method for optimization on the document object, which removes unnecessary objects and compresses images in the PDF file
- Save the optimized document to the new path using the Save() method.
Example for C#: Compress PDF Document
How to Optimize PDF Document for the Web with Aspose.PDF for Java
Linearization is a process of making a PDF file suitable for online browsing using a web browser. A linearized PDF file is structured in a way that allows the first page of the PDF file to be displayed in a user web browser before the entire file is downloaded from the web server. This makes the web viewing faster and the user does not need to wait for the entire PDF to load to start viewing the document. Using method Optimize we can:
- open the first page as quickly as possible;
- display next page or follow by link to the next page as quickly as possible
- display the page incrementally as it arrives when data for a page is delivered over a slow channel (display the most useful data first);
- permit user interaction, such as following a link, to be performed even before the entire page has been received and displayed.
Steps to reduce size PDF File via Java
- Open a PDF document using Document object.
- Call the
Optimize
method on the document object, which removes unnecessary objects and compresses images in the PDF file - Save the optimized document to the new path using the Save() method.
Example for Java: Compress PDF Document for Web
How to Removing or Flattening Annotations with Aspose.PDF for C++
Adding annotations to your PDF document naturally increases its size. Annotations can be removed if they are not needed. They may be flattened if necessary, but do not require further modification. Both methods will decrease the file size. Using method Flatten we can:
- open the document as quickly as possible;
- display page as single enitity
Steps to reduce size PDF File via C++
- Create a document object named document that opens the input PDF file using the MakeObject function.
- Loop through each page object in the document object using a for-each loop and a range-based iterator named page.
- Loop through each annotation object in the page object using a for-each loop and a range-based iterator named annotation.
- Call the Flatten method on the annotation object to merge it with the page content and remove any interactivity.
- Call the Save method on the document object to save the updated PDF file.
Example for C++: Flatten PDF Document
About Aspose.PDF API
A PDF Processing Library to create cross-platform applications with the ability to generate, modify, convert, render, secure and print documents without using Adobe Acrobat. It supports converting various file formats into PDF including HTML and converting PDF documents into various output formats. Developers can easily render all HTML content in a single Page PDF as well as convert HTML files with SVG graphic tags to Tagged PDF files. .NET PDF API offers compression, table creation, graph & image functions, hyperlinks, stamp and watermarking tasks, extended security controls & custom font handling.