Fix viewer export (#5713)

This commit is contained in:
Reece Browne 2026-02-13 12:16:52 +00:00 committed by GitHub
parent 7c3c7937b3
commit e01734fb7d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 4 deletions

View File

@ -173,11 +173,14 @@ export default function RightRail() {
if (currentView === 'pageEditor') {
return t('rightRail.exportAll', 'Export PDF');
}
if (currentView === 'viewer') {
return terminology.download;
}
if (selectedCount > 0) {
return terminology.downloadSelected;
}
return terminology.downloadAll;
}, [currentView, selectedCount, t]);
}, [currentView, selectedCount, t, terminology]);
return (
<div ref={sidebarRefs.rightRailRef} className="right-rail" data-sidebar="right-rail">

View File

@ -585,6 +585,11 @@ const EmbedPdfViewerContent = ({
key={currentFile && isStirlingFile(currentFile) ? currentFile.fileId : (effectiveFile.file instanceof File ? effectiveFile.file.name : effectiveFile.url)}
file={effectiveFile.file}
url={effectiveFile.url}
fileName={
previewFile ? previewFile.name :
(currentFile && isStirlingFile(currentFile) ? currentFile.name :
(effectiveFile?.file instanceof File ? effectiveFile.file.name : undefined))
}
enableAnnotations={shouldEnableAnnotations}
showBakedAnnotations={isAnnotationsVisible}
enableRedaction={shouldEnableRedaction}

View File

@ -60,6 +60,7 @@ const DOCUMENT_NAME = 'stirling-pdf-viewer';
interface LocalEmbedPDFProps {
file?: File | Blob;
url?: string | null;
fileName?: string;
enableAnnotations?: boolean;
enableRedaction?: boolean;
isManualRedactionMode?: boolean;
@ -71,7 +72,7 @@ interface LocalEmbedPDFProps {
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 [pdfUrl, setPdfUrl] = useState<string | null>(null);
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 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 [
createPluginRegistration(DocumentManagerPluginPackage, {
initialDocuments: [{
@ -177,13 +189,13 @@ export function LocalEmbedPDF({ file, url, enableAnnotations = false, enableReda
// Register export plugin for downloading PDFs
createPluginRegistration(ExportPluginPackage, {
defaultFileName: 'document.pdf',
defaultFileName: exportFileName,
}),
// Register print plugin for printing PDFs
createPluginRegistration(PrintPluginPackage),
];
}, [pdfUrl, enableAnnotations, showBakedAnnotations]);
}, [pdfUrl, enableAnnotations, showBakedAnnotations, fileName, file, url]);
// Initialize the engine with the React hook - use local WASM for offline support
const { engine, isLoading, error } = usePdfiumEngine({