mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
PDFs show on phones, drawn with PDF.js
Android shows nothing for a PDF in a frame and iPhones only its first page. On touch screens the document viewer now draws every page with PDF.js 6.5.438 (vendored in public/pdfjs/<version>/, loaded only there); desktop browsers keep their own viewer in the frame. - Pages are drawn as they come near the screen and let go once far from it, so a long manual doesn't use up a phone's memory. - Only the parts of the file those pages need are downloaded: uploaded files now send Accept-Ranges, and PDF.js's background fetch of the whole file is off. - JBIG2/JPEG 2000 scans decode (wasm, with JS fallbacks). Checked on an Android 14 emulator with Chromium 160 (which reports pdfViewerEnabled but can't show a PDF in a frame). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2e8d789975
commit
66fa5f4423
38 files changed
+1236
-1
No files matched your search
@@ -0,0 +1,8 @@
|
||||
# Uploaded files already answer Range requests (206), but don't say so. The
|
||||
# PDF viewer on phones (PDF.js) needs "Accept-Ranges: bytes" to fetch only
|
||||
# the parts of a PDF for the pages being looked at, instead of all of it.
|
||||
Rails.application.config.to_prepare do
|
||||
ActiveStorage::DiskController.after_action(only: :show) do
|
||||
response.headers["Accept-Ranges"] = "bytes" if response.successful?
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
# PDF.js (pdfjs-dist from npm, Apache-2.0) draws PDFs in the document viewer
|
||||
# on phones, which can't show them in a frame. Its files live in
|
||||
# public/pdfjs/<version>/ undigested, because it loads its decoders and fonts
|
||||
# by name; the version in the path keeps the year-long cache safe.
|
||||
# To update: copy build/pdf.min.mjs, build/pdf.worker.min.mjs, LICENSE, iccs/,
|
||||
# standard_fonts/ and wasm/ (minus quickjs) into a new folder and change this.
|
||||
Rails.application.config.x.pdfjs_path = "/pdfjs/6.5.438/"
|
||||
@@ -3924,6 +3924,12 @@ en:
|
||||
not_entries: 'Not logbook entries (forms, tags…), so nothing was transcribed from: %{pages}.'
|
||||
unreadable: 'Too hard to read: %{pages}.'
|
||||
js:
|
||||
pdf:
|
||||
loading: Loading the PDF…
|
||||
page: Page %{page} of %{pages}
|
||||
page_failed: This page couldn't be shown.
|
||||
failed: This PDF can't be shown here.
|
||||
open: Open it
|
||||
airports:
|
||||
not_found: Not in the airport database
|
||||
wb:
|
||||
|
||||
Reference in new issue
Block a user