Error trying to use custom filter with PDFViewCtrl.

34 views
Skip to first unread message

Ryan

unread,
Feb 27, 2017, 7:53:18 PM2/27/17
to PDFTron PDFNet SDK
Question:

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

Answer:

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 = fReader.read(buffer)) > 0) {
    totalBytes
+= bytesRead;
    os
.write(buffer, 0, (int) bytesRead);
}

os
.flush();
os
.close();

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.
Reply all
Reply to author
Forward
0 new messages