diff --git a/lib/phantomscript.js b/lib/phantomscript.js index 2fe422589..2f3a6513f 100644 --- a/lib/phantomscript.js +++ b/lib/phantomscript.js @@ -254,11 +254,31 @@ function executeInPage(data) { mermaid.init(); svg = document.querySelector('svg') - svgValue = xmlSerializer.serializeToString(svg) - // make sure the entire view area is calculated before exiting - // this solves an issue where the svg is not done rendering when the image is created - svg.getBBox(); + var boundingBox = svg.getBoundingClientRect(); // the initial bonding box of the svg + + // resizing the body to fit the svg + document.body.setAttribute( + 'style' + , 'width: ' + (boundingBox.width * 1.5) + '; height: ' + (boundingBox.height * 1.5) + ';' + ) + // resizing the svg via css for consistent display + svg.setAttribute( + 'style' + , 'width: ' + (boundingBox.width * 1.5) + '; height: ' + (boundingBox.height * 1.5) + ';' + ) + + // set witdth and height attributes used to set the viewport when rending png image + svg.setAttribute( + 'width' + , boundingBox.width * 1.5 + ) + svg.setAttribute( + 'height' + , boundingBox.height * 1.5 + ) + + svgValue = xmlSerializer.serializeToString(svg) //console.log(document.body.outerHTML);