How to create an uncompressed PDF file?

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 util

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.


Share this article

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now