mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 11:23:10 +02:00
Fix viewer export (#5713)
This commit is contained in:
@@ -173,11 +173,14 @@ export default function RightRail() {
|
|||||||
if (currentView === 'pageEditor') {
|
if (currentView === 'pageEditor') {
|
||||||
return t('rightRail.exportAll', 'Export PDF');
|
return t('rightRail.exportAll', 'Export PDF');
|
||||||
}
|
}
|
||||||
|
if (currentView === 'viewer') {
|
||||||
|
return terminology.download;
|
||||||
|
}
|
||||||
if (selectedCount > 0) {
|
if (selectedCount > 0) {
|
||||||
return terminology.downloadSelected;
|
return terminology.downloadSelected;
|
||||||
}
|
}
|
||||||
return terminology.downloadAll;
|
return terminology.downloadAll;
|
||||||
}, [currentView, selectedCount, t]);
|
}, [currentView, selectedCount, t, terminology]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={sidebarRefs.rightRailRef} className="right-rail" data-sidebar="right-rail">
|
<div ref={sidebarRefs.rightRailRef} className="right-rail" data-sidebar="right-rail">
|
||||||
|
|||||||
@@ -585,6 +585,11 @@ const EmbedPdfViewerContent = ({
|
|||||||
key={currentFile && isStirlingFile(currentFile) ? currentFile.fileId : (effectiveFile.file instanceof File ? effectiveFile.file.name : effectiveFile.url)}
|
key={currentFile && isStirlingFile(currentFile) ? currentFile.fileId : (effectiveFile.file instanceof File ? effectiveFile.file.name : effectiveFile.url)}
|
||||||
file={effectiveFile.file}
|
file={effectiveFile.file}
|
||||||
url={effectiveFile.url}
|
url={effectiveFile.url}
|
||||||
|
fileName={
|
||||||
|
previewFile ? previewFile.name :
|
||||||
|
(currentFile && isStirlingFile(currentFile) ? currentFile.name :
|
||||||
|
(effectiveFile?.file instanceof File ? effectiveFile.file.name : undefined))
|
||||||
|
}
|
||||||
enableAnnotations={shouldEnableAnnotations}
|
enableAnnotations={shouldEnableAnnotations}
|
||||||
showBakedAnnotations={isAnnotationsVisible}
|
showBakedAnnotations={isAnnotationsVisible}
|
||||||
enableRedaction={shouldEnableRedaction}
|
enableRedaction={shouldEnableRedaction}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ const DOCUMENT_NAME = 'stirling-pdf-viewer';
|
|||||||
interface LocalEmbedPDFProps {
|
interface LocalEmbedPDFProps {
|
||||||
file?: File | Blob;
|
file?: File | Blob;
|
||||||
url?: string | null;
|
url?: string | null;
|
||||||
|
fileName?: string;
|
||||||
enableAnnotations?: boolean;
|
enableAnnotations?: boolean;
|
||||||
enableRedaction?: boolean;
|
enableRedaction?: boolean;
|
||||||
isManualRedactionMode?: boolean;
|
isManualRedactionMode?: boolean;
|
||||||
@@ -71,7 +72,7 @@ interface LocalEmbedPDFProps {
|
|||||||
redactionTrackerRef?: React.RefObject<RedactionPendingTrackerAPI>;
|
redactionTrackerRef?: React.RefObject<RedactionPendingTrackerAPI>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function LocalEmbedPDF({ file, url, enableAnnotations = false, enableRedaction = false, isManualRedactionMode = false, showBakedAnnotations = true, onSignatureAdded, signatureApiRef, annotationApiRef, historyApiRef, redactionTrackerRef }: LocalEmbedPDFProps) {
|
export function LocalEmbedPDF({ file, url, fileName, enableAnnotations = false, enableRedaction = false, isManualRedactionMode = false, showBakedAnnotations = true, onSignatureAdded, signatureApiRef, annotationApiRef, historyApiRef, redactionTrackerRef }: LocalEmbedPDFProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [pdfUrl, setPdfUrl] = useState<string | null>(null);
|
const [pdfUrl, setPdfUrl] = useState<string | null>(null);
|
||||||
const [, setAnnotations] = useState<Array<{id: string, pageIndex: number, rect: any}>>([]);
|
const [, setAnnotations] = useState<Array<{id: string, pageIndex: number, rect: any}>>([]);
|
||||||
@@ -95,6 +96,17 @@ export function LocalEmbedPDF({ file, url, enableAnnotations = false, enableReda
|
|||||||
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
|
||||||
const viewportGap = rootFontSize * 3.5;
|
const viewportGap = rootFontSize * 3.5;
|
||||||
|
|
||||||
|
// Determine export filename - use provided fileName, or extract from file/url
|
||||||
|
let exportFileName = 'document.pdf';
|
||||||
|
if (fileName) {
|
||||||
|
exportFileName = fileName;
|
||||||
|
} else if (file && 'name' in file) {
|
||||||
|
exportFileName = file.name;
|
||||||
|
} else if (url) {
|
||||||
|
const urlPath = url.split('/').pop() || 'document.pdf';
|
||||||
|
exportFileName = urlPath.split('?')[0]; // Remove query params
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
createPluginRegistration(DocumentManagerPluginPackage, {
|
createPluginRegistration(DocumentManagerPluginPackage, {
|
||||||
initialDocuments: [{
|
initialDocuments: [{
|
||||||
@@ -177,13 +189,13 @@ export function LocalEmbedPDF({ file, url, enableAnnotations = false, enableReda
|
|||||||
|
|
||||||
// Register export plugin for downloading PDFs
|
// Register export plugin for downloading PDFs
|
||||||
createPluginRegistration(ExportPluginPackage, {
|
createPluginRegistration(ExportPluginPackage, {
|
||||||
defaultFileName: 'document.pdf',
|
defaultFileName: exportFileName,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// Register print plugin for printing PDFs
|
// Register print plugin for printing PDFs
|
||||||
createPluginRegistration(PrintPluginPackage),
|
createPluginRegistration(PrintPluginPackage),
|
||||||
];
|
];
|
||||||
}, [pdfUrl, enableAnnotations, showBakedAnnotations]);
|
}, [pdfUrl, enableAnnotations, showBakedAnnotations, fileName, file, url]);
|
||||||
|
|
||||||
// Initialize the engine with the React hook - use local WASM for offline support
|
// Initialize the engine with the React hook - use local WASM for offline support
|
||||||
const { engine, isLoading, error } = usePdfiumEngine({
|
const { engine, isLoading, error } = usePdfiumEngine({
|
||||||
|
|||||||
Reference in New Issue
Block a user