-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Description
Hi!
I'm trying to print measurements in mm/cm to the Printer with precision/accuracy, but all I get was approximate measures. I think I'm am using wrong conversion scale.
I tried many times and decided to ask for help...Follow the Javascript code:
function svgToPdf(svgElement, margin) {
var width = "210"; //mm
var height = "296"; //mm
var pdf = new jsPDF('p', 'mm', [width, height]); //p-portrait ou l-landscape
svg2pdf(svgElement, pdf, {
xOffset: 0,
yOffset: 0,
scale: 0.264583333 //px to mm //72/96 // this is the ratio of px to pt units
/*
switch (unit) {
case 'pt': k = 1; break;
case 'mm': k = 72 / 25.4; break;
case 'cm': k = 72 / 2.54; break;
case 'in': k = 72; break;
case 'px': k = 96 / 72; break;
case 'pc': k = 12; break;
case 'em': k = 12; break;
case 'ex': k = 6; break;
default:
throw ('Invalid unit: ' + unit);
}
*/
});
return pdf.output('datauristring'); // PDF from as a base64 string
}
function save() {
document.getElementById("pdf").src = svgToPdf(document.getElementById("svgElement"), 0);
// PDF from as a base64 string
}
save();