@@ -59,6 +59,8 @@ async function makePDF(svg, args) {
5959 }
6060 } ) ;
6161
62+ let pr = Promise . resolve ( ) ;
63+
6264 if ( nodejs ) {
6365 const doc = internals . nodejs_document ;
6466 doc . originalCreateElementNS = doc . createElementNS ;
@@ -80,6 +82,10 @@ async function makePDF(svg, args) {
8082 } ;
8183 return res ;
8284 } ;
85+
86+ pr = import ( 'canvas' ) . then ( handle => {
87+ globalThis . Image = handle . Image ;
88+ } ) ;
8389 }
8490
8591 const orientation = ( svg . width < svg . height ) ? 'portrait' : 'landscape' ;
@@ -116,10 +122,9 @@ async function makePDF(svg, args) {
116122 doc . addFont ( filename , fcfg . n , fcfg . s || 'normal' ) ;
117123 } ) ;
118124
119- let pr = Promise . resolve ( ) ;
120125 if ( need_symbols && ! custom_fonts [ kSymbol ] && settings . LoadSymbolTtf ) {
121126 const handler = new FontHandler ( 122 , 10 ) ;
122- pr = handler . load ( ) . then ( ( ) => {
127+ pr = pr . then ( ( ) => handler . load ( ) ) . then ( ( ) => {
123128 handler . addCustomFontToSvg ( d3_select ( svg . node ) ) ;
124129 doc . addFileToVFS ( kSymbol + '.ttf' , handler . base64 ) ;
125130 doc . addFont ( kSymbol + '.ttf' , kSymbol , 'normal' ) ;
@@ -152,8 +157,10 @@ async function makePDF(svg, args) {
152157 globalThis . document = undefined ;
153158 globalThis . CSSStyleSheet = undefined ;
154159 globalThis . CSSStyleRule = undefined ;
160+ globalThis . Image = undefined ;
155161 internals . nodejs_document . createElementNS = internals . nodejs_document . originalCreateElementNS ;
156- if ( args ?. as_buffer ) return Buffer . from ( res ) ;
162+ if ( args ?. as_buffer )
163+ return Buffer . from ( res ) ;
157164 }
158165
159166 return res ;
0 commit comments