PHPRUNNER: menambah PDF viewer di aplikasi web Anda
In recent Using Google Docs Viewer to preview documents online article we reviewed the use of Google Docs Viewer for document preview purposes. While this is a viable approach two main concerns arise:
- dependency on third party service
- security issues
In this article we'll show how you can use ViewerJS library in your PHPRunner projects. Before you do that feel free to check the live demo.
Here are integration steps:
1. Download ViewerJS library (use first download link). Unzip ViewerJS folder to source folder of your project. This is how it supposed to look if installed properly.
2. Setup one of fields as document upload. You can use either basic upload or multiple-files upload. Set 'View as' type of this field to 'Custom' and use the following code.
In this code $mftable is the name of the table, $mfield is the name of the field that stores documents.
Some additional bits of info. This sample code will display PDF files only, other files simply be downloaded to the end user device. This code is designed to open document preview in new window. If you like to open it in the same window remove target=_blank from the code.