Import JsPDF from "jspdf";
Function printout (domname)
Console.log ("Exporting for you ...")
//title, you can set it at will, or you can put it as a parameter and pass it in for your own play.
Var title =' test ah';
var that = this
Var shareContent = DomName// The (native) DOM object of the package that needs a screenshot.
//Print to see if dom is obtained.
Console.log (shared content)
var width = share content . offsetwidth; //Get dom width
var height = share content . offset height; //Get dom height
var canvas = document . createelement(" canvas "); //Create canvas node
var scale = 2; //Define any magnification that supports decimals.
Canvas.width = width * scale// Define canvas width * zoom, here I have enlarged the canvas by 2 times.
Canvas.height = height * scale// Define canvas height * scale.
canvas.getContext("2d ")。 Scale (scale, scale); //Get the context and set the scale.
html2Canvas(DomName,{
//Allow pictures to be loaded across domains
exactly,
}). Then (function (canvas) (
var context = canvas . get context(" 2d ");
//Important Turn off anti-aliasing
context . moziimagesmoothingenabled = false;
context . webkitimagesmoothingenabled = false;
context . msimagesmoothingenabled = false;
context . imagesmoothingenabled = false;
var img data = canvas . toda taurl(' image/', 1.0); //Converted to base64 format, which can be found online.
var img = new Image();
img.src = imgData
img.onload = function () {
img . width = img . width/2; //Because the magnification is more than 2 times, /2 is needed after the image is generated.
img . height = img . height/2;
img . style . transform = " scale(0.5)";
If (this.width & gtthis.height) {
//This can be automatically adjusted according to the print size.
var doc = new JsPDF("l "," mm", [
This. Width * 0.555,
This. Height * 0.555
]);
} Otherwise {
var doc = new JsPDF("p "," mm", [
This. Width * 0.555,
This. Height * 0.555
]);
}
doc.addImage(
imgData,
“jpeg”,
10,
0,
This. Width * 0.505,
This. Height * 0.545
);
doc . save(title+"-file.pdf ");
Console.log ("countdown 3 seconds export")
};
});
}
//Export method
Export {
print out
}