On-demand incremental viewing of remote secured & linarized PDF on Android, iOS, WinRT,

Q: Can the following options/features be implemented with PDFTron Android PDF library?

  1. Set password to a PDF file on sd card so that if user takes out the card from phone and use in computer he will not be able to open the pdf content (only android application knows the password)

  2. File downloaded from server is password protected pdf. Can password be supplied programmatically by the android app without the user having to enter the password (app and server knows the password)

  3. To optimize for mobile download, each newspaper page is downloaded as individual pdf file to sd card on android phone. Swipe to next page can this be implemented in this mode of download ?


A:

Yes, you can encrypt/secure any PDF as shown in EncTest sample (http://www.pdftron.com/pdfnet/samplecode.html#EncTest, also available as part of PDFNet SDK Sample).

For example:

PDFDoc doc=new PDFDoc((input_path + “fish.pdf”));
doc.initSecurityHandler();
SecurityHandler new_handler=new SecurityHandler();
new_handler.changeUserPassword(“mypass”);

// Set Permissions
new_handler.setPermission (SecurityHandler.e_print, true);
new_handler.setPermission (SecurityHandler.e_extract_content, false);
doc.setSecurityHandler(new_handler);

doc.save(“secured.pdf”, SDFDoc.e_linearized, null);
doc.close();

Note that with PDFNet also offers more advanced ways to protect content (including custom filters - e.g. see custom filter sample that comes as part of Android/iOS SDK). You can also prevent any disk caching… etc.

  1. Can password be supplied programmatically by the android app without the user having
    to enter the password

Yes. For example:
PDFDoc doc=new PDFDoc((input_path + “fish.pdf”));
doc.initStdSecurityHandler(“mypass”); …

For full sample code see EncTest sample (http://www.pdftron.com/pdfnet/samplecode.html#EncTest).

if you are using PDFVIewCtrl to open remote files (see below) you can use PDFViewCtrl.OpenURLAsync(“http://www.pdftron.com/my.pdf”, “cache_file”, “mypass”);

  1. To optimise for mobile download, each newspaper page is downloaded as individual PDF

PDFNet supports on-demand / incremental download of web optimized PDF out of the box (via PDFViewCtrl.OpenURLAsync()).

For more info on linearization (a.k.a fast web view), please see:
https://groups.google.com/d/msg/pdfnet-sdk/3j1wVxz_OVw/q-z-YJbc2eoJ

This eliminates need for various hacks to enable smooth online document viewing. For example, there is no need to split PDF into many files (e.g. per-page). The file size does not bloat since shared resources such as fonts, images, are not replicated among files. There are no hiccups during viewing and everything works auto-magically… PDFNet viewers also support saving partial download sessions. This means that your users can view partial content offline and continue with download when internet connection resumes.

To test this try the viewer sample app – and specifically PDFViewCtrl.openUrl().

If you are set on using single page PDFs, you can still use PDFNet for viewing but is a bit more work. You would need to manage file download, manage the addition of downloaded pages manually. For this, you might want to use the Tool, which has the onPageTurning() callback. In this callback you can add/remove pages, for example (see PDFPage sample for concrete code), and then update the layout after the modifications calling PDFViewCtrl.updatePageLayout(). For a start on the Tool interface, please check this forum post

(https://groups.google.com/d/msg/pdfnet-sdk/fG-20n1gcPU/4Zslh603PZ8J) and our documentation (http://www.pdftron.com/pdfnet/mobile/Javadoc/index.html).