@@ -5,23 +5,29 @@ import { renderNoteHTML } from "../../utils/note";
55export async function savePDF ( noteId : number ) {
66 const html = await renderNoteHTML ( Zotero . Items . get ( noteId ) ) ;
77 disablePrintFooterHeader ( ) ;
8- const args = {
9- _initPromise : Zotero . Promise . defer ( ) ,
10- browser : undefined as any ,
11- url : `chrome://${ config . addonRef } /content/printTemplate.xhtml` ,
12- } ;
13- const win = Zotero . getMainWindow ( ) . openDialog (
14- `chrome://${ config . addonRef } /content/printWrapper.xhtml` ,
15- `${ config . addonRef } -printWrapper` ,
16- `chrome,centerscreen,resizable,status,width=900,height=650,dialog=no` ,
17- args ,
18- ) ! ;
19- await args . _initPromise . promise ;
20- args . browser ?. contentWindow . postMessage (
8+
9+ const { HiddenBrowser } = ChromeUtils . importESModule (
10+ "chrome://zotero/content/HiddenBrowser.mjs" ,
11+ ) ;
12+ const browser = new HiddenBrowser ( {
13+ useHiddenFrame : false ,
14+ } ) ;
15+
16+ await browser . load (
17+ `chrome://${ config . addonRef } /content/printTemplate.xhtml` ,
18+ {
19+ requireSuccessfulStatus : true ,
20+ } ,
21+ ) ;
22+ await browser . waitForDocument ( ) ;
23+
24+ browser . contentWindow . postMessage (
2125 { type : "print" , html, style : Zotero . Prefs . get ( "note.css" ) || "" } ,
2226 "*" ,
2327 ) ;
24- win . print ( ) ;
28+
29+ browser . print ( ) ;
30+
2531 showHint ( "Note Saved as PDF" ) ;
2632}
2733
0 commit comments