View Any PDF in WebViewer
Having extolled the virtues of Juan Antonio's base64 extension in previous posts (Create PDF, Upload any File) I set about seeing what could be done about viewing PDFs from assets and the sdcard using a similar method.
create a suitable html file with webviewstring capabilities
select a pdf file from either assets or sdcard
convert the pdf to a base64 string
view the pdf in an AI2 app
In my example there is a bit more to it than that. PDFJS can only render one page at a time, so one must have a way of changing pages, which I did by getting the number of pages from the html page once the pdf was initially rendered, then sending that value back to the app, controlling the page display from there. Also, scaling needed controlling in order to be able to zoom in and out of the pdf
I will show all the blocks below but need to show the important ones that actually do the work for the display of the pdf.
First off the base64 conversion
and then the call to show the html
and now all the blocks used in the example aia project