PDFOne .NET
Powerful all-in-one PDF library for .NET
Compatibility
VS 2005/2008/2010/2012/2013

PDF File Size Optimization With PDFOne .NET (Part 1)

Multiple images in a PDF document can greatly increase file size. See an example of how PDFOne .NET implements intelligent PDF file optimization.
By M. V. Niranjan

Sometimes, images can be the main reason why the file size of a PDF document is very big. The amount of text may be small but the moment a company logo or masthead is added to the pages, the file size zooms!

PDFOne .NET employs numerous optimization techniques to reduce PDF file size. Some of these techniques are provided as part of the PDF format (mainly as compression techniques) while others are PDFOne .NET's very own.

In this article, I will show you how PDFOne .NET optimizes the file size when images are rendered multiple times in a document.

Imagine a PDF document that uses the same image in multiple locations with different positioning, orientation, cropping and other settings. Now, PDFOne .NET can ascertain that the images are the same, irrespective of what name, path or stream type (file or memory) they are found with, and then intelligently create just one resource for those images in the PDF document.

In the following code snippet, a file called "sample.bmp" is used to draw an image. Another file "Copy of sample.bmp," which is just "sample.bmp" with a different file name, is used to draw another image in a different location. PDFOne .NET can identify that these two images are the same and use a single resource for both images when it creates the PDF document.

// Draw image from "sample.bmp"
page1.WriteText("Normal image", 1, 4);
RectangleF r = new RectangleF(1, 2.5f, 4.7f, 1.47f);
page1.DrawImage("sample.bmp", r.X, r.Y);
page1.DrawRectangle(page1.Pen, r, false, true);

// Draw image from a copy of "sample.bmp"
page1.WriteText("Stretched image", 1, 7);
r = new RectangleF(1, 5.5f, 7, 1.5f);
page1.DrawImage("Copy of sample.bmp", r, true, false);
page1.DrawRectangle(page1.Pen, r, false, true);

// Draw image from a copy of "sample.bmp"
// placed in a different folder
page1.WriteText("Centered image within a big rectangle", 1, 10);
r = new RectangleF(1, 8.5f, 7, 1.5f);
page1.DrawImage("New Folder\\Yet another Copy of sample.bmp",
                r, false, true);
page1.DrawRectangle(page1.Pen, r, false, true);

Even when you use the same image from a different path with a different file name, PDFOne .NET identifies them to be the same!

In the following screenshots, you see two PDF documents that use the same image in different ways. If you check the files (available in the downloads section), their sizes are almost the same. The fact that one document has only one image and the other has several does not seem to make much of a difference to the file size.

PDF Document With A Single Image

PDF Document With Multiple Images Using A Single Resource

A C# project is provided in the download section. You can create these PDF files on your machine and compare the file sizes.

---oO0Oo---

Downloads

---o0O0o---

Our .NET Developer Tools
XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2017 Gnostice Information Technologies Private Limited. All rights reserved.