@@ -9,8 +9,6 @@ declare const jspdf: { jsPDF: any };
99declare const openSansRegularFont : string ;
1010declare const openSansBoldFont : string ;
1111
12- // Module-level variable to track the previous preview URL for cleanup
13- let previousPreviewUrl : string | null = null ;
1412
1513/** Register Open Sans (Regular + Bold) with a jsPDF instance. */
1614function registerFonts ( doc : any ) : void {
@@ -855,37 +853,16 @@ export function downloadPdf(data: InvoiceData): void {
855853}
856854
857855/**
858- * Generate the PDF blob, create an object URL, and set it as the src
859- * on the #pdf-preview iframe. Revokes the previous URL to prevent
860- * memory leaks .
856+ * Generate the PDF and set it as the src on the #pdf-preview iframe
857+ * using a data URL. This avoids the blob URL approach which causes
858+ * Firefox/Waterfox to download the PDF instead of displaying it inline .
861859 */
862860export function updatePreview ( data : InvoiceData ) : void {
863- const blob = generatePdfBlob ( data ) ;
864- const url = URL . createObjectURL ( blob ) ;
861+ const doc = generatePdf ( data ) ;
862+ const dataUrl = doc . output ( 'dataurlstring' ) as string ;
865863
866864 const iframe = document . getElementById ( 'pdf-preview' ) as HTMLIFrameElement | null ;
867865 if ( iframe ) {
868- iframe . src = url ;
869- // Once loaded, force the iframe's internal document to fill available space
870- iframe . onload = ( ) => {
871- try {
872- const doc = iframe . contentDocument ;
873- if ( doc ?. documentElement ) {
874- doc . documentElement . style . height = '100%' ;
875- doc . documentElement . style . overflow = 'hidden' ;
876- }
877- if ( doc ?. body ) {
878- doc . body . style . height = '100%' ;
879- doc . body . style . overflow = 'hidden' ;
880- doc . body . style . margin = '0' ;
881- }
882- } catch ( _ ) { /* cross-origin — ignore */ }
883- } ;
884- }
885-
886- // Revoke the previous URL to prevent memory leaks
887- if ( previousPreviewUrl ) {
888- URL . revokeObjectURL ( previousPreviewUrl ) ;
866+ iframe . src = dataUrl ;
889867 }
890- previousPreviewUrl = url ;
891868}
0 commit comments