@@ -29,10 +29,11 @@ commander
2929 . option ( '-c, --configFile [configFile]' , 'JSON configuration file for mermaid. Optional' )
3030 . option ( '-C, --cssFile [cssFile]' , 'CSS file for the page. Optional' )
3131 . option ( '-s, --scale [scale]' , 'Puppeteer scale factor, default 1. Optional' )
32+ . option ( '-f, --pdfFit' , 'Scale PDF to fit chart' )
3233 . option ( '-p --puppeteerConfigFile [puppeteerConfigFile]' , 'JSON configuration file for puppeteer. Optional' )
3334 . parse ( process . argv )
3435
35- let { theme, width, height, input, output, backgroundColor, configFile, cssFile, puppeteerConfigFile, scale } = commander
36+ let { theme, width, height, input, output, backgroundColor, configFile, cssFile, puppeteerConfigFile, scale, pdfFit } = commander
3637
3738// check input file
3839if ( ! input ) {
@@ -127,17 +128,24 @@ const deviceScaleFactor = parseInt(scale || 1, 10);
127128 await page . setViewport ( { width : clip . x + clip . width , height : clip . y + clip . height , deviceScaleFactor } )
128129 await page . screenshot ( { path : output , clip, omitBackground : backgroundColor === 'transparent' } )
129130 } else { // pdf
130- const clip = await page . $eval ( 'svg' , svg => {
131- const react = svg . getBoundingClientRect ( )
132- return { x : react . left , y : react . top , width : react . width , height : react . height }
133- } )
134- await page . pdf ( {
135- path : output ,
136- printBackground : backgroundColor !== 'transparent' ,
137- width : ( Math . ceil ( clip . width ) + clip . x * 2 ) + 'px' ,
138- height : ( Math . ceil ( clip . height ) + clip . y * 2 ) + 'px' ,
139- pageRanges : '1-1' ,
140- } )
131+ if ( pdfFit ) {
132+ const clip = await page . $eval ( 'svg' , svg => {
133+ const react = svg . getBoundingClientRect ( )
134+ return { x : react . left , y : react . top , width : react . width , height : react . height }
135+ } )
136+ await page . pdf ( {
137+ path : output ,
138+ printBackground : backgroundColor !== 'transparent' ,
139+ width : ( Math . ceil ( clip . width ) + clip . x * 2 ) + 'px' ,
140+ height : ( Math . ceil ( clip . height ) + clip . y * 2 ) + 'px' ,
141+ pageRanges : '1-1' ,
142+ } )
143+ } else {
144+ await page . pdf ( {
145+ path : output ,
146+ printBackground : backgroundColor !== 'transparent'
147+ } )
148+ }
141149 }
142150 await browser . close ( )
143151} ) ( )
0 commit comments