Stelle PDFs auf iPhone und iPad seitenweise dar und nutze das Legacy-Build von pdf.js.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7b2d0c298e
commit
07e46c77f1
6 files changed
+100
-10
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { DocumentView } from "./DocumentView.jsx";
|
||||
import { useContext, useEffect, useRef, useState } from "react";
|
||||
import { SessionContext } from "../session.js";
|
||||
import { documentToText, downloadMailPart, fetchExternal, fetchFile, fetchMailPart, isDirty, markDirty, textToDocument, api } from "../api.js";
|
||||
@@ -7,7 +8,7 @@ import { ErrorNote } from "./widgets.jsx";
|
||||
import { UnitDetail } from "./correspondence.jsx";
|
||||
import { dateCaption, DateField, DirectionChoice, DirectionColumn, directionValue, directionWord, formatDate, mailFacts, sourceLabel } from "./content.jsx";
|
||||
import { NavIcon } from "./icons.jsx";
|
||||
import workerSrc from "pdfjs-dist/build/pdf.worker.min.mjs?url";
|
||||
import workerSrc from "pdfjs-dist/legacy/build/pdf.worker.min.mjs?url";
|
||||
|
||||
const SCALES = [0.75, 1, 1.25, 1.5, 2];
|
||||
|
||||
@@ -173,7 +174,7 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
|
||||
setMedia("pdf");
|
||||
try {
|
||||
const bytes = await blob.arrayBuffer();
|
||||
const pdfjs = await import("pdfjs-dist");
|
||||
const pdfjs = await import("pdfjs-dist/legacy/build/pdf.mjs");
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;
|
||||
const doc = await pdfjs.getDocument({ data: bytes }).promise;
|
||||
if (!alive) {
|
||||
@@ -243,7 +244,7 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
|
||||
setMedia("pdf");
|
||||
try {
|
||||
const bytes = await blob.arrayBuffer();
|
||||
const pdfjs = await import("pdfjs-dist");
|
||||
const pdfjs = await import("pdfjs-dist/legacy/build/pdf.mjs");
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = workerSrc;
|
||||
const doc = await pdfjs.getDocument({ data: bytes }).promise;
|
||||
if (!alive) {
|
||||
@@ -308,7 +309,8 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
|
||||
const canvas = canvasRef.current;
|
||||
const context2d = canvas?.getContext("2d");
|
||||
if (!canvas || !context2d) return;
|
||||
const viewport = pdfPage.getViewport({ scale });
|
||||
const base = pdfPage.getViewport({ scale: 1 });
|
||||
const viewport = pdfPage.getViewport({ scale: Math.min(scale, Math.sqrt(12_000_000 / (base.width * base.height))) });
|
||||
canvas.width = viewport.width;
|
||||
canvas.height = viewport.height;
|
||||
const render = pdfPage.render({ canvasContext: context2d, viewport });
|
||||
@@ -584,7 +586,7 @@ export function ReadingPane({ binding, context, backLabel, onClose, onReload, ca
|
||||
<img className="reader-image" alt={element.title} src={blobUrl} style={{ width: `${Math.round(scale * 100)}%` }} />
|
||||
) : null}
|
||||
{!isMail && media === "pdf" && pdf ? <canvas ref={canvasRef} className="reader-canvas" /> : null}
|
||||
{!isMail && media === "pdf-frame" && blobUrl ? <iframe className="reader-frame" title={element.title} src={blobUrl} /> : null}
|
||||
{!isMail && media === "pdf-frame" && blobUrl ? <DocumentView title={element.title} url={blobUrl} /> : null}
|
||||
{!isMail && media === "other" && blobUrl ? (
|
||||
<div className="reader-pane__state">
|
||||
<p>Die Datei ist geladen, aber hier nicht als Seite darstellbar.</p>
|
||||
|
||||
Reference in new issue
Block a user