I have a unique challenge with an SVG file of a flat displayed in my browser - I need to print it out at a specific scale. I've been using SVG.js to manipulate the content, but I'm struggling to find the right combination of viewport and viewbox settings to achieve my desired outcome.
What I do know is the size of the original SVG source file. Using x and y coordinates, I've calculated a distance to determine the correct "screen scale" that will match 1cm on the plan with a certain number of pixels.
For printing purposes, I must adhere to specific scales like 1/50. So, I attempted to determine the actual size of the flat by applying the screen scale and the SVG file size. Then I applied the 1/50 (0.02) scale to the total size. Finally, I tried to estimate the number of pixels based on a 72dpi resolution.
Below is the code I've been working with:
var svgNode = SVG(planNode);
var totalWidthCm = (svgNode.width().replace('px', '') * screenScale * printScaleVal);
var totalHeightCm = (svgNode.height().replace('px', '') * screenScale * printScaleVal);
var totalWidthPx = totalWidthCm * 0.393701 * 72;
var totalHeightPx = totalHeightCm * 0.393701 * 72;
svgNode.height(totalHeightPx + 'px');
svgNode.width(totalWidthPx + 'px');
svgNode.viewbox('0', '0', '1000', '600');
The resulting SVG output:
<svg xmlns:cc="http://creativecommons.org/ns#" xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg" version="1.1" width="495.79113386880005px" height="387.87611496479997px"
preserveAspectRatio="xMinYMin slice" id="plan" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:svgjs="http://svgjs.dev/svgjs" viewBox="0 0 496 388">
.....
</svg>
Unfortunately, I'm still unsure how to adjust the viewport and viewbox settings to display the scaled flat accurately for printing on A4 or A3 paper sizes.
To any SVG experts reading this, your help would be greatly appreciated! :D