Skip to content

How to print measurements to the printer with accuracy #1695

@Solangetatiana

Description

@Solangetatiana

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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions