Skip to content

Commit

Permalink
Fix path to image resources
Browse files Browse the repository at this point in the history
When "./js/pdfjs/web/images/" is resolved and pretty URLs are enabled
the result is "{SERVER}/apps/files_pdfviewer/js/pdfjs/web/images/",
which works as expected. However, if pretty URLs are not enabled the
absolute path becomes
"{SERVER}/index.php/apps/files_pdfviewer/js/pdfjs/web/images/" instead.
As the images are static files they are not served by "index.php", so
they can not be found and therefore are not rendered in the PDF.

To solve that now the path is generated in PHP and provided through the
template, similarly to how it is done, for example, for the path to the
cmap files.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Jan 8, 2025
1 parent 7ccf117 commit 2702111
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/workersrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function initializeCustomPDFViewerApplication() {
PDFViewerApplicationOptions.set('cMapUrl', head.getAttribute('data-cmapurl'))
PDFViewerApplicationOptions.set('sandboxBundleSrc', head.getAttribute('data-sandbox'))
PDFViewerApplicationOptions.set('enablePermissions', true)
PDFViewerApplicationOptions.set('imageResourcesPath', './js/pdfjs/web/images/')
PDFViewerApplicationOptions.set('imageResourcesPath', head.getAttribute('data-imageresourcespath'))
PDFViewerApplicationOptions.set('enableScripting', head.getAttribute('data-enableScripting') === true)

if (hideDownload === '1') {
Expand Down
3 changes: 2 additions & 1 deletion templates/viewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
<head data-workersrc="<?php p($urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/build/pdf.worker.js')) ?>?v=<?php p($version) ?>"
data-enableScripting="<?php p($enableScripting ? true : false) ?>"
data-sandbox="<?php p($urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/build/pdf.sandbox.js'))?>"
data-cmapurl="<?php p($urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/web/cmaps/')) ?>">
data-cmapurl="<?php p($urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/web/cmaps/')) ?>"
data-imageresourcespath="<?php p($urlGenerator->linkTo('files_pdfviewer', 'js/pdfjs/web/images/')) ?>">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="google" content="notranslate">
Expand Down

0 comments on commit 2702111

Please sign in to comment.