Q: Is it possible to turn of Flate compression for all or part of a
drawing? We want to be able to do a clear text search on strings in the
PDF file, but can't do that if the strings are compressed.
----
A:
Yes, using PDFNet it is possible to decompress all Flate streams (or
any other compressed streams) in the new or any existing document. This
can be implemented along the lines of JBIG2 sample project
(http://www.pdftron.com/net/samplecode.html#JBIG2).
Of course instead of processing only Image streams you can process any
Flate stream. For example:
Doc* cos_doc = pdf_doc.GetSDFDoc();
int num_objs = cos_doc->XRefSize();
for(int i=1; i<num_objs; ++i) {
Obj* obj = cos_doc->GetObj(i);
if(obj && !obj->IsFree() && obj->IsStream()) {
// You could check here is the Filter is Flate.
// If not you could skip to another object (see jbig sample
proj)...
AutoPtr<Filter> filter(obj->GetDecodedStream());
FilterReader reader(*filter);
Obj* decstm = cos_doc->CreateIndirectStream(reader);
// Copy all dictionary entries from obj to decstm
....
decstm->Erase("Filter");
cos_doc->Swap(i, decstm ->GetObjNum());
}
}
pdf_doc.Save("decompressed.pdf", Doc::SaveOptions::e_remove_unused, 0);