PDFOne .NET
Powerful all-in-one PDF library for .NET
Compatibility
VS 2008 VS 2005 CLR 2.0

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 Developer Tools
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.

XtremePDFConverter VCL

A Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents.

PDFOne .NET

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

XtremeDocumentStudio .NET

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

PDFOne (for Java™)

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

XtremeFontEngine (for Java)

Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts

Our Office Productivity Applications
Free PDF Reader

A free, fast, and portable application for viewing, printing and converting PDF documents.

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

This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).