I developed an app. The main page is made up of a navigation panel on the left, similar to that of the Tasks app, and a content panel on the right. In the navigation panel I can use the file picker to choose a file hosted in Nextcloud. When I choose a file, it is opened and displayed in the content panel from the right. It’s about pdf files but also plain text files or jpg/png images.
To achieve this, in the ‘/appfolder/templates/content’ directory, the ‘index.php’ file has the following content:
<?php script('app_name', 'pdfobject.min'); script('app_name', 'script'); style('app_name', 'style'); /** @var array $_ */ ?> <div id="docpreview"></div>
Then in the ‘/appfolder/js’ directory, the ‘script.js’ file displays the file to be previewed using the ‘PDFObject.js’ utility like this:
var docUrl = OC.generateUrl( "/remote.php/webdav/App_Name/temp_folder/"+filename ); PDFObject.embed( docUrl, $('#docpreview') );
This is the only way I could display a file in the content panel. I tried with iframe, embed, object, etc. but due to security features, they don’t work. I also tried using the complete server URL of the file without the ‘/remote.php/webdav’ part. It doesn’t work eaither. So, using PDFObject and the URL with ‘/remote.php/webdav’ I could make it work. My problem is that everything worked fine with PHP 7.0 but since I upgraded to PHP 7.3 it doesn’t work anymore. Probably because the ‘remote.php’ file is run differently. I can choose the document but it won’t be displayed in the content panel no matter what I do: I changed Nginx configurations in all the ways possible (I use the standard Nginx config for Nextcloud). I even tried different versions of Nextcloud: it doesn’t work with Nextcloud 14, 15, 16 , 17.
Please suggest how can I solve this problem. How can I preview a pdf or plain text document using PDFObject or any other means ? It would be great to be able to preview odt/docx documents, but I want to display at least pdf and plain text documents. Your suggestions will be much appreciated. Thank you !