How can I compress Cos/SDF stream?


I am using pdfdoc.CreateIndirectStream(reader) to embed a new data
stream in PDF, however the embedded stream is not compressed.

How can I compress Cos/SDF stream?

To create a compressed stream you can pass FlateEncode filter as a
second parameter in CreateIndirectStream. For example:

// In C#
Obj stm = doc.CreateIndirectStream(mystm, new

// In C++
AutoPtr<Filters::Filter> flate(new
Filters::FlateEncode(AutoPtr<Filters::Filter> (0)));
Obj* stm = doc.CreateIndirectStream(reader, flate);

Please make sure that you are using the latest PDFNet version.