mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-02-07 11:19:38 +03:00
[Feature Request] Preview for PDF Attachments #571
Open
opened 2026-02-04 21:08:10 +03:00 by OVERLORD
·
37 comments
No Branch/Tag Specified
development
further_theme_development
l10n_development
release
llm_only
vectors
v25-11
docker_env
drawio_rendering
user_permissions
ldap_host_failover
svg_image
prosemirror
captcha_example
fix/video-export
v25.12.3
v25.12.2
v25.12.1
v25.12
v25.11.6
v25.11.5
v25.11.4
v24.11.4
v25.11.3
v25.11.2
v25.11.1
v25.11
v25.07.3
v25.07.2
v25.07.1
v25.07
v25.05.2
v25.05.1
v25.05
v25.02.5
v25.02.4
v25.02.3
v25.02.2
v25.02.1
v25.02
v24.12.1
v24.12
v24.10.3
v24.10.2
v24.10.1
v24.10
v24.05.4
v24.05.3
v24.05.2
v24.05.1
v24.05
v24.02.3
v24.02.2
v24.02.1
v24.02
v23.12.3
v23.12.2
v23.12.1
v23.12
v23.10.4
v23.10.3
v23.10.2
v23.10.1
v23.10
v23.08.3
v23.08.2
v23.08.1
v23.08
v23.06.2
v23.06.1
v23.06
v23.05.2
v23.05.1
v23.05
v23.02.3
v23.02.2
v23.02.1
v23.02
v23.01.1
v23.01
v22.11.1
v22.11
v22.10.2
v22.10.1
v22.10
v22.09.1
v22.09
v22.07.3
v22.07.2
v22.07.1
v22.07
v22.06.2
v22.06.1
v22.06
v22.04.2
v22.04.1
v22.04
v22.03.1
v22.03
v22.02.3
v22.02.2
v22.02.1
v22.02
v21.12.5
v21.12.4
v21.12.3
v21.12.2
v21.12.1
v21.12
v21.11.3
v21.11.2
v21.11.1
v21.11
v21.10.3
v21.10.2
v21.10.1
v21.10
v21.08.6
v21.08.5
v21.08.4
v21.08.3
v21.08.2
v21.08.1
v21.08
v21.05.4
v21.05.3
v21.05.2
v21.05.1
v21.05
v21.04.6
v21.04.5
v21.04.4
v21.04.3
v21.04.2
v21.04.1
v21.04
v0.31.8
v0.31.7
v0.31.6
v0.31.5
v0.31.4
v0.31.3
v0.31.2
v0.31.1
v0.31.0
v0.30.7
v0.30.6
v0.30.5
v0.30.4
v0.30.3
v0.30.2
v0.30.1
v0.30.0
v0.29.3
v0.29.2
v0.29.1
v0.29.0
v0.28.3
v0.28.2
v0.28.1
v0.28.0
v0.27.5
v0.27.4
v0.27.3
v0.27.2
v0.27.1
v0.27
v0.26.4
v0.26.3
v0.26.2
v0.26.1
v0.26.0
v0.25.5
v0.25.4
v0.25.3
v0.25.2
v0.25.1
v0.25.0
v0.24.3
v0.24.2
v0.24.1
v0.24.0
v0.23.2
v0.23.1
v0.23.0
v0.22.0
v0.21.0
v0.20.3
v0.20.2
v0.20.1
v0.20.0
v0.19.0
v0.18.5
v0.18.4
v0.18.3
v0.18.2
v0.18.1
v0.18.0
v0.17.4
v0.17.3
v0.17.2
v0.17.1
v0.17.0
v0.16.3
v0.16.2
v0.16.1
v0.16.0
v0.15.3
v0.15.2
v0.15.1
v0.15.0
v0.14.3
v0.14.2
v0.14.1
v0.14.0
v0.13.1
v0.13.0
v0.12.2
v0.12.1
v0.12.0
v0.11.2
v0.11.1
v0.11.0
v0.10.0
v0.9.3
v0.9.2
v0.9.1
v0.9.0
v0.8.2
v0.8.1
v0.8.0
v0.7.6
v0.7.5
v0.7.4
v0.7.3
0.7.2
v.0.7.1
v0.7.0
v0.6.3
v0.6.2
v0.6.1
v0.6.0
v0.5.0
Labels
Clear labels
🎨 Design
📖 Docs Update
🐛 Bug
🐛 Bug
:cat2:🐈 Possible duplicate
💿 Database
☕ Open to discussion
💻 Front-End
🐕 Support
🚪 Authentication
🌍 Translations
🔌 API Task
🏭 Back-End
⛲ Upstream
🔨 Feature Request
🛠️ Enhancement
🛠️ Enhancement
🛠️ Enhancement
❤️ Happy feedback
🔒 Security
🔍 Pending Validation
💆 UX
📝 WYSIWYG Editor
🌔 Out of scope
🔩 API Request
:octocat: Admin/Meta
🖌️ View Customization
❓ Question
🚀 Priority
🛡️ Blocked
🚚 Export System
♿ A11y
🔧 Maintenance
> Markdown Editor
pull-request
Mirrored from GitHub Pull Request
No Label
🔨 Feature Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: starred/BookStack#571
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ghost on GitHub (Feb 18, 2018).
Feature Request
Hey Everybody,
i am very happy to see the rapid progress about the App - great Work
But i miss the function, that I can get a preview of attached pdf-Files, before I downloading it.
It would be very nice, when these feature where implement in the next versions of Bookstack.
@lommes commented on GitHub (Feb 19, 2018):
@Yoginth
I think you got the question wrong. It is not about the generation of PDF-files.
@ITforHome
Can you please give some details on how the preview should look?
Currently the attachements are only downloaded. In case of PDF there are severall possibilities to implement a "preview". There can be a real preview in form of a generated image including only the first page of the pdf, change the 'Content-Type' for this download (as suggested by @Yoginth) so the browser uses the defined preview(plugin) or embedd a preview using pdfjs or something. In the last 2 cases the file technically is already downloaded to your computer.
@lommes commented on GitHub (Feb 19, 2018):
@Yoginth yes and no.
File attachments are handled by AttachmentController.php (not by the PageController) and Downloads by the get-method. If you change the Content-Type for all filetypes this will most likely result in errors when you attach and later download a zip, exe, ... file.
@ghost commented on GitHub (Feb 20, 2018):
@Yoginth
i have changed the Content-Type to
'Content-Type' => 'application/octet-stream'in the PageController.php file, but is not working. When i click on an attached pdf-File, i can only downloaded it, but i can't get a preview.@lommes
i have changed the Content-Txpe to
'Content-Type' => 'application/pdf'in the AttachmentController.php file, but is not working too. When i also click on an attached pdf-File, i can only downloaded it, no preview.General:
In my question i mean any attached pdf-File NO the generated PDF-File of a page in Bookstack
@ghost commented on GitHub (Feb 24, 2018):
When I open the Bookstack App on Mobile Safari or Chrome I get a preview about attached PDF-Files when I click on it.
@albertmatyi commented on GitHub (Mar 27, 2018):
I've created a small hack (quick solution for own deployment) to be able to view pdf attachments as embedded documents in a page.
"Installation"
Add the following script to the CUSTOM HTML HEAD content on the Settings pane.

Usage
<p> <canvas data-pdfurl="https://wiki.justrocket.de/attachments/3"></canvas> </p>where 3 is the id of the attachment (hover the attachment link to see the number)
@shatteredsword commented on GitHub (Jul 10, 2018):
@albertmatyi your solution works great! thank you!
@albertmatyi commented on GitHub (Jul 18, 2018):
Created a more userfriendly version.
Code & Readme at: https://gist.github.com/albertmatyi/7c23a679a4a81c61c3628f6c15480b76
@rwjuk commented on GitHub (Jun 7, 2019):
For anyone coming across this and wanting to view PDF attachments in the browser, change the return statement of
app/Http/Controllers/AttachmentController.phpto this:@aldo-o commented on GitHub (Apr 7, 2020):
Where? There are a lot of functions in that file.
P.S. Not a php developer so excuse my stupidity.
@ssddanbrown commented on GitHub (Apr 7, 2020):
@aldoblack I think it's intended to be a replacement of this line:
https://github.com/BookStackApp/BookStack/blob/v0.28.3/app/Http/Controllers/AttachmentController.php#L198
Note, Such changes to core files are not officially supported and may cause complications, or be lost, when you upgrade.
@aldo-o commented on GitHub (Apr 8, 2020):
I understand. Thank You very much.
@sprklinginfo commented on GitHub (May 12, 2021):
Tried out the solution by @albertmatyi. The pdf is successfully embedded on the page. Big thanks to @albertmatyi. But it also causes errors if you want to export that page as a pdf later.
Inspired by the solution, I tweaked it to have the pdf displayed in a popup window (an online pdf viewer) while the page itself only has a button for the popup window so it won't affect the export. Here is the readme and code: https://gist.github.com/sprklinginfo/624c4c431a0f802556071ec459b6ca76
@ssddanbrown commented on GitHub (Jun 13, 2021):
Just to note on this, Within BookStack v21.05.2 it's now possible to open up attachments in an "inline" (Not forced download) via Ctrl+Click of the attachment (Or Cmd+click on Mac). Alternatively, an attachment link of this type can be manually formed by adding an
?open=truequery parameter to the link.@shatteredsword commented on GitHub (Jun 14, 2021):
ctrl+click doesn't work if the filesize is over the default upload size limit for some reason, which is weird
@christianhz01 commented on GitHub (Feb 6, 2022):
Good evening @ssddanbrown ,
is there still an integrated solution planned here in the future or should users use @albertmatyi solution?
I think this would be an important feature for many people...
Christian
@shatteredsword commented on GitHub (Feb 10, 2022):
my current hacked version of this feature is adding this to the source code of the page i want the PDF to be on (assuming the pdf is uploaded somewhere on the site as an attachment:
<embed src="http://mysite.mydomain.com/attachments/12?open=true" type="application/pdf" width="100%" height="500px"></embed>What it looks like:
Screenshots
In Firefox:

In Chrome:

@ssddanbrown commented on GitHub (Feb 10, 2022):
Here's the above made into a bookmarklet:
Usage
Tested that on Firefox. This is all a hack and any of these workarounds may break upon update.
@nmpeckham commented on GitHub (Mar 10, 2022):
Updated script by @albertmatyi for Bookstack v22.02:
@christianhz01 commented on GitHub (Mar 12, 2022):
@nmpeckham Hi, I just tested it in version 22.02.3, the function is also given. Unfortunately, no button icon is displayed (Edge and Firefox on the latest version). With me there is simply a teaching stelle (which can be clicked). But thanks for the work!
@BertCurbit commented on GitHub (Mar 22, 2022):
I can confirm this works in version 22.02.3. The button is back
@christianhz01 commented on GitHub (Mar 27, 2022):
@nmpeckham Hi,
the butten is unfortunately still not there :(
@ssddanbrown commented on GitHub (Aug 3, 2022):
Here's an altered version of the above scripts that I recently amended for a BookStack user, that was using the above hacks. Think I tested it in v22.06. This script is not official nor supported:
View Code
@BertCurbit commented on GitHub (Aug 3, 2022):
Thanks for this but...
I just updated to 22.07.1 (cleared cache) and inserted this code in the 'Custom HTML Head Content' section but I can't see the PDF button in edit mode. Is there something else that I should do?
@ssddanbrown commented on GitHub (Aug 3, 2022):
@BertCurbit To confirm, do you see a little page icon next to the link toolbar icon?
@BertCurbit commented on GitHub (Aug 3, 2022):
@ssddanbrown Oh my... I was looking for the button with PDF text in it, like the previous version. But now it's just a blank page icon that I completely overlooked. It looks way better now and works perfectly. Thanks for this!
@airwolfhd commented on GitHub (Nov 23, 2022):
Is there a way to have this working offline? I have tried placing the pdf.min.js file inside the public folder in bookstack and pointing to it.
For example
<script src="https://192.168.0.10/pdf.min.js"></script>I can reach this file at this address from a browser however embedded PDFs are not working. They work fine when I bring bookstacks online and point to the cdnjs address.
@airwolfhd commented on GitHub (Nov 26, 2022):
I eventually got it working by also having a second file named pdf.worker.min.js along side pdf.min.js.
@mvdgeijn commented on GitHub (Feb 12, 2023):
I'm trying to implement this, but I don't know where to add the code. I inserted it in the settings table using the app-custom-head key. The code is added in the header, but no icon is added to the tinymce toolbar.
@dan-r95 commented on GitHub (Apr 27, 2023):
This issue hints at a potential fix https://github.com/BookStackApp/BookStack/issues/3586#issuecomment-1190485991 (worked for me).
@DarkZoneSD commented on GitHub (Sep 5, 2023):
Does someone have a working version of this script on the BookStack Version 23.06.2? Currently trying to implement it for use and i only get a grey window inside the page, i expected it to be like that in the editor, but its also not showing on the view page.
The download button points to the right .pdf though so it should be a working .pdf file.
@BabyLoves commented on GitHub (Oct 9, 2023):
Anyone can help?
@GriwMF commented on GitHub (Nov 26, 2023):
this https://github.com/BookStackApp/BookStack/issues/705#issuecomment-1203691993 works like a charm in my case.
P.S. Would be nice to have it by default in BookStack
@cloverenergy commented on GitHub (Dec 7, 2023):
FWIW having the exact same issue.
Any yes "built in" PDf support would be great.
@UvinduS commented on GitHub (Jan 5, 2024):
I did some change to @ssddanbrown's code. I think now it's working.
@ddkhanh commented on GitHub (Mar 28, 2024):
Based on @UvinduS 's code, I did some change to use another pdf-viewer for better interactive (text selection, copy, zoom, navigation)
https://github.com/ddkhanh/bookstack-pdf-viewer/
@DNF-SaS commented on GitHub (May 3, 2025):
The ability to view PDFs inline would be a really cool feature +1
@dirkdrutschmann commented on GitHub (Jan 7, 2026):
Check out
https://github.com/pronomix-gmbh/bookstack_file_attachment_preview