webodf / ViewerJS

ViewerJS: Document Reader in JavaScript
http://viewerjs.org
1.94k stars 421 forks source link

Display PDFs with viewerjs but avoid file to be donwloaded. #242

Open Processeur opened 6 years ago

Processeur commented 6 years ago

this is not an issue but a solution I found to a problem.

We are a few who desire to publish content but do not want it to be downloaded. As ViewerJS is run from client side, this means that the content has to be accessible from the client whereas there is no way the can load it.

I first tried to put a .htaccess file in my ressources folder to only requests to the files that include ViewerJS in the request. I did not made it works. If someone has a solution, please share because I think it's stil the best choice.

Then It try to find another way to load my pdf in the ViewerJS but still inaccessible from outside and this is what I have done (really simple and may be not the cleanest cay to do it):

1-all my ressources files stored in a folder protected from outside 2-From a php page I copy the desired file in a public folder 3-Once file copied I Launch the viewer accessing the file in public folder 4-Finally delete the file from public folder.

This way everything is fine.

Here is my code:

<?php
shell_exec('cp /var/www/resources/0cb889d87b/book.pdf /var/www/public/users/0cb889d87b/');
echo ('<iframe src = "ViewerJS/#../users/0cb889d87b/book.pdf" width=\'400\' height=\'300\' allowfullscreen webkitallowfullscreen></iframe>');
?>
<?php
shell_exec('(sleep 5 && rm /var/www/public/users/0cb889d87b/book.pdf) > /dev/null &');
?>

the tricky part was to show the viewer before the file was deleted from the pubic folder.

Hope this will help other.

Bye,

Proc.

vmbouras commented 6 years ago

Enable local.css in ViewerJS index and add in local.css the following

download

{ display:none; visibility: hidden; }

Works great for me

Processeur commented 6 years ago

worked like a charm.

THX.

2017-11-16 15:11 GMT+01:00 Vasilios Michael Bouras <notifications@github.com

:

Enable local.css in ViewerJS index and add in local.css the following

download

{ display:none; visibility: hidden; }

Works great for me

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kogmbh/ViewerJS/issues/242#issuecomment-344933851, or mute the thread https://github.com/notifications/unsubscribe-auth/AD6ZWAXrHMSk_munfD98cSL78EwASVgsks5s3EKvgaJpZM4QH7H5 .