Error trying to use custom filter with PDFViewCtrl


I am trying to implement a custom filter to do decryption of the PDF during reading (on the fly) but I get a Doc root not found exeption when trying to view the PDF.

PDFDoc doc = new PDFDoc(my_custom_filter); PDFViewCtrl.setDoc(doc); // exception


Try the following first. Once you can pass both of these tests, you can use your filter with PDFDoc constructor.

  1. Implement your custom filter, but just for a plain, unencrypted PDF, and pass to the PDFDoc constructor. This verifies that you got the basic interface down.

  2. Add your decryption, but instead of passing your filter to PDFDoc, just simulate reading first.

Filter filter = new YourCustomFilter(filename_in);
FilterReader fReader = new FilterReader(filter);
OutputStream os = new FileOutputStream(filename_out);

byte[] buffer = new byte[64 * 1024]; // 64 KB chunks
long bytesRead = 0;
int totalBytes = 0;

while((bytesRead = > 0) {
totalBytes += bytesRead;
os.write(buffer, 0, (int) bytesRead);


Once this code is done, the file filename_out should be binary identical to the plain text version of filename_in. This also means there should not be any padding at the beginning, end, or anywhere else.