How to create an uncompressed PDF file?

Tags: compressioncompression leveliText 5

During development testing, I'd prefer to create uncompressed, non-binary PDF files with iTextSharp so that I can check their internals easily. I can always convert the finished PDF with various utilities but that takes an extra step that would be comfortable to avoid. There are some places (e.g. PdfImage) where I can decide about compression level but I couldn't find anything about the compression used to output the individual PDF objects into the stream. Do you think this is possible with iTextSharp?

Posted on StackOverflow on May 15, 2014 by Gábor

You have two options:

[1.] Disable compression for all your documents at once:

Please take a look at the Document class. You'll find:

public static bool Compress = true;

If you change this static bool to false, PDF syntax streams won't be compressed.

Of course: images will are de facto compressed. For instance: if you add a JPEG to your document, you are adding an image that is already compressed, and iText won't uncompress it.

[2.] Disable compression for a single document at a time:

Please take a look at the PdfWriter class. You'll find:

protected internal int compressionLevel = PdfStream.DEFAULT_COMPRESSION;

If you change the value of compressionLevel to PdfStream.NO_COMPRESSION before opening the ´document´, your PDF syntax streams won't be compressed.