Adding a PDF viewer to a PHP document manager
Moderator: General Moderators
-
questorfla
- Forum Newbie
- Posts: 5
- Joined: Wed Apr 06, 2016 12:52 am
Adding a PDF viewer to a PHP document manager
This is not something I have any skills at all with. Flex-paper is the PDF viewer that I think might best suit my needs but I cannot get their product to interface with the download.php module properly. I was not sure where to look for any guidance on this and located this Forum almost by accident. I would appreciate any replies that could get me headed in the right direction.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Adding a PDF viewer to a PHP document manager
From looking at the Flex-paper site, I think you misunderstand what Flex-paper does. My impression is that Flex-paper converts a PDF into HTML5 so it can be displayed an a web page and look identical to the PDF version. So it is not something that can be downloaded. You can simply include() the Flex-paper HTML into a web page using PHP so that it can be viewed.
(#10850)
-
questorfla
- Forum Newbie
- Posts: 5
- Joined: Wed Apr 06, 2016 12:52 am
Re: Adding a PDF viewer to a PHP document manager
I believe you may be correct.
Actually I am pretty sure you are as I have spoken to the nice people there who pointed me toward their desktop convertor. Which unfortuately isn what is needed either. I do have a working viewer now but i am a little stuck at the php call to insert the selected file into the download stream. At least i managed to get to this point (I think?)
$fd = fopen($file_dest, "rb");
Not being a PHP programmer makes things more difficult though.
As i am not sure how to break out the this action to send the selected file to the viewer.
$fd = fopen($file_dest, "rb");
Not being a PHP programmer makes things more difficult though.
As i am not sure how to break out the this action to send the selected file to the viewer.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Adding a PDF viewer to a PHP document manager
I think you'll find the PHP function readfile() or get_file_contents() to be much easier than fopen/fread. Use the header() function to set the MIME/content type to PDF and then call readfile() to send the file to the browser.
(#10850)
-
questorfla
- Forum Newbie
- Posts: 5
- Joined: Wed Apr 06, 2016 12:52 am
Re: Adding a PDF viewer to a PHP document manager
Thanks but the file already goes to the browser.
I need to intercept all document files and send them to a site-side viewer instead to prevent
>>OR at least TRY to prevent
downloading of every document opened
I need to intercept all document files and send them to a site-side viewer instead to prevent
>>OR at least TRY to prevent
downloading of every document opened
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Adding a PDF viewer to a PHP document manager
Explain what "send them to a site-side viewer" means and maybe we can help. What is this site-side viewer?
(#10850)
-
questorfla
- Forum Newbie
- Posts: 5
- Joined: Wed Apr 06, 2016 12:52 am
Re: Adding a PDF viewer to a PHP document manager
PDF.JS is the one I have bee working with (or trying to) as it is open source and comes pre-loaded with all the necessary components and is Open Source enough that I could probably modify the control to remove the download option if i could get it to work at all.
After a lot of trying to follow the logic trail, I finally came to the conclusion that as originally designed the only VIEWING capability was the ones offered by default in the 'Browsers of Olde'. But even after changing the content disposition headers to inline from attachment, Chrome still downloads.
As there is no separate 'viewer" script, I was going to try to use the one in PDF.JS. Or even embed it in the viewer.html.
But so far, no matter what edit I make, the function still go to the same actions. If I can see a way to attache the downloads folder with the class.inc.php scrips I will add them here
The pdf.js code itself is too large too attache but here is the script for the main redistributable. The one i use is slightly customized but same actions
https://mozilla.github.io/pdf.js/gettin ... /#download
https://www.dropbox.com/s/pp6o3ahs147kh ... s.zip?dl=0 < customized
This will actually open any type of document WORD etc
I am very grateful for any assistance. This effort has become a sort of Obsession with me
I absolutely must fine a way to get this to work
After a lot of trying to follow the logic trail, I finally came to the conclusion that as originally designed the only VIEWING capability was the ones offered by default in the 'Browsers of Olde'. But even after changing the content disposition headers to inline from attachment, Chrome still downloads.
As there is no separate 'viewer" script, I was going to try to use the one in PDF.JS. Or even embed it in the viewer.html.
But so far, no matter what edit I make, the function still go to the same actions. If I can see a way to attache the downloads folder with the class.inc.php scrips I will add them here
The pdf.js code itself is too large too attache but here is the script for the main redistributable. The one i use is slightly customized but same actions
https://mozilla.github.io/pdf.js/gettin ... /#download
https://www.dropbox.com/s/pp6o3ahs147kh ... s.zip?dl=0 < customized
This will actually open any type of document WORD etc
I am very grateful for any assistance. This effort has become a sort of Obsession with me
- Attachments
-
- download.zip
- here is the content of the downloads php script.
- (2.34 KiB) Downloaded 195 times
-
questorfla
- Forum Newbie
- Posts: 5
- Joined: Wed Apr 06, 2016 12:52 am
Re: Adding a PDF viewer to a PHP document manager
Another note; I may be totally off mark on this on but:
In its original setup, since the intent WAS to download the files, there is routine included which runs GZIP to compact the file before downloading. The location of the GZIP executable is part of the ini file for the site. But, as this is not Linux,there is no GZIP module. I reading through the PHP routines it appears that this option is set to true whether or not it actually happens. But I have noticed that at the bottom of the page when the action runs, the displayed links point to the file name as still being a .pdf file rather than zipped.
And in any event, they files still download either way.
I only mention this because in settings.inc.php for the downloads section, this "action' of 'zip' is defined and i wondered if there would be a way to replace that with an action to open the file in a viewer.
As I would prefer that there was NO option to download, could an option to VIEW be substituted here?
Everything works perfect up to that point, i i could then select the JS Viewer,i think that would be the perfect solution.
In its original setup, since the intent WAS to download the files, there is routine included which runs GZIP to compact the file before downloading. The location of the GZIP executable is part of the ini file for the site. But, as this is not Linux,there is no GZIP module. I reading through the PHP routines it appears that this option is set to true whether or not it actually happens. But I have noticed that at the bottom of the page when the action runs, the displayed links point to the file name as still being a .pdf file rather than zipped.
And in any event, they files still download either way.
I only mention this because in settings.inc.php for the downloads section, this "action' of 'zip' is defined and i wondered if there would be a way to replace that with an action to open the file in a viewer.
As I would prefer that there was NO option to download, could an option to VIEW be substituted here?
Everything works perfect up to that point, i i could then select the JS Viewer,i think that would be the perfect solution.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Adding a PDF viewer to a PHP document manager
I am confused. I looked at PDF.js and it has a download feature, so you should not need PHP at all. Why are you using PHP? I do not understand what is not working?
(#10850)
Re: Adding a PDF viewer to a PHP document manager
Maybe I'm missing something here but pdf.js runs client-side. The PDF will already have been downloaded. What is it you're trying to accomplish, exactly?