Technical FAQs
As more and more companies embrace digitization of paper documents, they’re looking for ways to minimize the virtual storage space necessary for these new files. They’re already benefiting from increased office space and improved workflow efficiency, but they also need data compression techniques to make access to digital information quicker and less costly.
One standard method is mixed raster content compression (MRC), which greatly reduces the size of stored PDF documents. Since the vast majority of data being digitized and archived is in PDF format, MRC compression is an ideal tool for converting high volumes of paper documents into compressed, searchable files.
MRC: The Basics
Mixed raster compression works by breaking down an image (typically a full page of a PDF document) into its various components: mostly text and color image files. This is done in order to utilize the most thorough compression algorithm available for each part of the page.
As a result, even though the color images are highly compressed into their core elements (background, color, grayscale, etc.) they retain vivid detail and can be displayed subsequently with essentially no loss of quality, and any text from the original page remains searchable.
Putting High-Grade Compression to Use
A real estate firm, for instance, can use MRC compression to efficiently store a database of home listings, each with potentially dozens of color images and a searchable street address, with little to no compromise in file fidelity.
Consider these numbers: MRC can compress a 20 MB .TIFF color image file (which is part of a source PDF) to anywhere between 96 and 170 KB, based on the level of compression desired. This range suggests, of course, a tradeoff between file size and image quality, but is a significant reduction from the source image in any case – with differences in the displayed file barely discernible.
The most recent MRC tools make its integration into existing applications simple as well, usually involving just adding a few lines of code to these make such dramatic compression ratios a reality. For all the talk of companies creating fully digitized records archives, MRC compression is one technique that’s making it more feasible than ever.
Let Us Help
If you’d like to learn more about mixed raster content compression, including how our ImageGear features highly refined MRC functionality, contact us and our experts will get in touch. We’re here to help developers make applications that put organizations on the forefront of digital content management.
In this tutorial, you’ll learn how to configure a Java project for a console application. You’ll also learn how to open a PDF and save as a new file.
-
- Make sure that you have installed JDK and ImageGear for Java PDF properly. See System Requirements and Installation. You will need to copy a sample.pdf file inside the directory where you will be creating the tutorial sample.
- Create a new Java file, and name it (e.g., MyFirstIGJavaPDFProject.java). Insert the following code there:
import com.accusoft.imagegearpdf.*; public class MyFirstIGJavaPDFProject { private PDF pdf; private Document document; static { System.loadLibrary("IgPdf"); } // Application entry point. public static void main(String[] args) { boolean linearized = false; String inputPath = "sample.pdf"; String outputPath = "sample_output.pdf";; MyFirstIGJavaPDFProject app = new MyFirstIGJavaPDFProject(); app.loadAndSave(inputPath, outputPath, linearized); } // Load and save the PDF file. private void loadAndSave(String inputPath, String outputPath, boolean linearized) { try { this.initializePdf(); this.openPdf(inputPath); this.savePdf(outputPath, linearized); } catch (Throwable ex) { System.err.println("Exception: " + ex.toString()); } finally { this.terminatePdf(); } } // Initialize the PDF session. private void initializePdf() { this.pdf = new PDF(); this.pdf.initialize(); } // Open input PDF document. private void openPdf(String inputPath) { this.document = new Document(); this.document.openDocument(inputPath); } // Save PDF document to the output path. private void savePdf(String outputPath, boolean linearized) { SaveOptions saveOptions = new SaveOptions(); // Set LINEARIZED attribute as provided by the user. saveOptions.setLinearized(linearized); this.document.saveDocument(outputPath, saveOptions); } // Close the PDF document and terminate the PDF session. private void terminatePdf() { if (this.document != null) { this.document.closeDocument(); this.document = null; } if (this.pdf != null) { this.pdf.terminate(); this.pdf = null; } } }
- Now, let’s go over some of the important areas in the sample code with more detail. The com.accusoft.imagegearpdf namespace:
- Allows you to load and save native PDF documents
- Allows rasterization of PDF pages by converting them to bitmaps and adding raster pages to a PDF document
- Provides multi-page read and write support for the entire document
To enable the com.accusoft.imagegearpdf namespace in your project, specify the following directive:
import com.accusoft.imagegearpdf.*;
To initialize and support processing of PDF files we need:
// Initialize the PDF session. private void initializePdf() { this.pdf = new PDF(); this.pdf.initialize(); }
- There is one main object that is used in this sample code: The Document that holds the entire loaded document.
private Document document; … this.document = new Document(); this.document.openDocument(inputPath);
- You can save the loaded document using:
SaveOptions saveOptions = new SaveOptions(); // Set LINEARIZED attribute as provided by the user. saveOptions.setLinearized(linearized); this.document.saveDocument(outputPath, saveOptions);
See About Linearized PDF Files for more information.
- Now, you can build and run your sample. Please make sure that you have a PDF file named sample.pdf in the same directory where your sample source resided, or change the inputPath in the sample code so that it points to any existing PDF file.
- Now, open the terminal in the directory containing your source file and run the following commands:
- Compile
javac -classpath $HOME/Accusoft/ImageGearJavaPDF1-64/java/IgPdf.jar MyFirstIGJavaPDFProject.java
After running this command, you should see a file named MyFirstIGJavaPDFProject.class in your current directory.
- Build
jar cfe MyFirstIGJavaPDFProject.jar MyFirstIGJavaPDFProject MyFirstIGJavaPDFProject.class
After running this command, you should see a file named MyFirstIGJavaPDFProject.jar in your current directory.
- Set the environment variable (you only have to do this one time)
export LD_PRELOAD=$HOME/Accusoft/ImageGearJavaPDF1-64/lib/libIGCORE18.so
- run
java -classpath $HOME/Accusoft/ImageGearJavaPDF1-64/java/IgPdf.jar:. MyFirstIGJavaPDFProject
- Compile
After running your sample, you should see a new PDF file, named sample_output.pdf, in your current directory.