Gábor
Gábor

Reputation: 10214

How to create uncompressed PDF file?

An unorthodox question for sure. :-) 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 (eg. 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?

Upvotes: 1

Views: 1286

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

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.

Upvotes: 4

Related Questions