Preview document in content panel of a new app

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.

So, my problem is that since I upgraded PHP from 7.0 to 7.3, the pdf or text documents can’t be displayed in the content panel. For some weird reason the jpg/png images are displayed correctly, but this won’t help me, because the majority of the documents will be pdf and plain text. The panel remains blank with no errors in Nextcloud log or in the browsers’s JavaScript console. I changed browsers: Firefox, Chrome, I tried in Linux and Windows: it’s all the same. Indeed, when upgrading PHP I also upgraded the VPS’s operating system from Debian 9 to Debian 10, so other packages were upgraded in addition to PHP, but my guess is that PHP is the one responsible for not displaying the documents.

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 !