[GH-ISSUE #1132] Offer a local PDF viewer like PDF.js #727

Open
opened 2026-03-02 16:01:03 +03:00 by kerem · 3 comments
Owner

Originally created by @logoff on GitHub (Jan 1, 2024).
Original GitHub issue: https://github.com/prasathmani/tinyfilemanager/issues/1132

Hello.

I use your project behind a secure environment, so my URLs are not publicly available. I would like to have a local preview, not based on Google or Microsoft. For instance, for PDF documents, I recommend implementing a 'local' option using https://github.com/mozilla/pdf.js.

Thanks!

Originally created by @logoff on GitHub (Jan 1, 2024). Original GitHub issue: https://github.com/prasathmani/tinyfilemanager/issues/1132 Hello. I use your project behind a secure environment, so my URLs are not publicly available. I would like to have a local preview, not based on Google or Microsoft. For instance, for PDF documents, I recommend implementing a `'local'` option using https://github.com/mozilla/pdf.js. Thanks!
Author
Owner

@karu73 commented on GitHub (Feb 28, 2024):

this would be much appreciated

<!-- gh-comment-id:1968873785 --> @karu73 commented on GitHub (Feb 28, 2024): this would be much appreciated
Author
Owner

@allmycookies commented on GitHub (Feb 11, 2025):

You can render the pdf files with Chrome, Edge and maybe Firefox localy.

Change in the next line of "if ($is_onlineViewer) {"

from:

if ($online_viewer == 'google') { echo '<iframe src="https://docs.google.com/viewer?embedded=true&hl=en&url=' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height:460px;"></iframe>'; } else if ($online_viewer == 'microsoft') { echo '<iframe src="https://view.officeapps.live.com/op/view.aspx?src=' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height:460px;"></iframe>'; } else if ($online_viewer == 'local') { echo '<iframe src="' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height:460px;"></iframe>'; }

to (with some height modification):

if ($online_viewer == 'google') { echo '<iframe src="https://docs.google.com/viewer?embedded=true&hl=en&url=' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height: calc(100vh - 322px);"></iframe>'; } else if ($online_viewer == 'microsoft') { echo '<iframe src="https://view.officeapps.live.com/op/view.aspx?src=' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height: calc(100vh - 322px);"></iframe>'; } else if ($online_viewer == 'local') { echo '<iframe src="' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height: calc(100vh - 322px);"></iframe>'; }

and in your config you have to set $online_viewer = 'local';

If not working, check your Browser PDF Settings. May set to view pdf in browser, not to download them.

<!-- gh-comment-id:2650665433 --> @allmycookies commented on GitHub (Feb 11, 2025): You can render the pdf files with Chrome, Edge and maybe Firefox localy. Change in the next line of "`if ($is_onlineViewer) {`" from: `if ($online_viewer == 'google') { echo '<iframe src="https://docs.google.com/viewer?embedded=true&hl=en&url=' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height:460px;"></iframe>'; } else if ($online_viewer == 'microsoft') { echo '<iframe src="https://view.officeapps.live.com/op/view.aspx?src=' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height:460px;"></iframe>'; } else if ($online_viewer == 'local') { echo '<iframe src="' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height:460px;"></iframe>'; }` to (with some height modification): `if ($online_viewer == 'google') { echo '<iframe src="https://docs.google.com/viewer?embedded=true&hl=en&url=' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height: calc(100vh - 322px);"></iframe>'; } else if ($online_viewer == 'microsoft') { echo '<iframe src="https://view.officeapps.live.com/op/view.aspx?src=' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height: calc(100vh - 322px);"></iframe>'; } else if ($online_viewer == 'local') { echo '<iframe src="' . fm_enc($file_url) . '" frameborder="no" style="width:100%;min-height: calc(100vh - 322px);"></iframe>'; }` and in your config you have to set `$online_viewer = 'local';` If not working, check your Browser PDF Settings. May set to view pdf in browser, not to download them.
Author
Owner

@allmycookies commented on GitHub (Feb 11, 2025):

Or if you want more options download the prebuild pdf.js from https://mozilla.github.io/pdf.js/getting_started/#download unzip it in an folder named pdfjs on the same path as your tfm and add another Line after the last </iframe>'; }:

else if ($online_viewer == 'pdfjs') { echo '<iframe src="pdfjs/web/viewer.html?file=' . urlencode(fm_enc($file_url)) . '" frameborder="no" style="width:100%;min-height: calc(100vh - 322px);"></iframe>'; }
Some layout modifications

  • near line 1767 changed
    <div class="row"><div class="col-12"><ul class="list-group w-50 my-3" data-bs-theme="<?php echo FM_THEME; ?>">
    to
    <div class="row"><div class="row"><div class="col-12 col-md-4 mt-3"><ul class="list-group w-100 my-3" data-bs-theme="<?php echo FM_THEME; ?>">
  • near line 1849 changed the DIV Class bevor
    if ($is_onlineViewer) { from class="row mt-3" to class="col-12 col-md-8 mt-3" an added above another </div> to close the <div class="row">. It should looks like </div></div><div class="col-12 col-md-8 mt-3"><?php if ($is_onlineViewer) {

In that case you can change the calc in height from 322px to 90px and the viewer will be next to the meta-info.

<!-- gh-comment-id:2650880527 --> @allmycookies commented on GitHub (Feb 11, 2025): Or if you want more options download the prebuild pdf.js from `https://mozilla.github.io/pdf.js/getting_started/#download` unzip it in an folder named pdfjs on the same path as your tfm and add another Line after the last `</iframe>'; }`: ` else if ($online_viewer == 'pdfjs') { echo '<iframe src="pdfjs/web/viewer.html?file=' . urlencode(fm_enc($file_url)) . '" frameborder="no" style="width:100%;min-height: calc(100vh - 322px);"></iframe>'; } ` Some layout modifications - near line 1767 changed `<div class="row"><div class="col-12"><ul class="list-group w-50 my-3" data-bs-theme="<?php echo FM_THEME; ?>">` to `<div class="row"><div class="row"><div class="col-12 col-md-4 mt-3"><ul class="list-group w-100 my-3" data-bs-theme="<?php echo FM_THEME; ?>">` - near line 1849 changed the DIV Class bevor `if ($is_onlineViewer) { ` from `class="row mt-3"` to `class="col-12 col-md-8 mt-3`" an added above another `</div>` to close the `<div class="row">`. It should looks like `</div></div><div class="col-12 col-md-8 mt-3"><?php if ($is_onlineViewer) {` In that case you can change the calc in height from 322px to 90px and the viewer will be next to the meta-info.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tinyfilemanager#727
No description provided.