我想将画布转换为PDF。我想把它写成cron。由于Javascript不能在cron中工作,我想在php中完成它。
画布json对象是
{"objects":[{"type":"text","originX":"center","originY":"center","left":531.22,"top":249,"width":115,"height":31.2,"fill":"e2ddcf","stroke":null,"strokeWidth":5,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1.14,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","text":"MOJE TŁO","fontSize":24,"fontWeight":"normal","fontFamily":"Times New Roman","fontStyle":"normal","lineHeight":1.3,"textDecoration":"","textAlign":"left","path":null,"textBackgroundColor":"","useNative":true},{"type":"image","originX":"center","originY":"center","left":63,"top":304,"width":66,"height":66,"fill":"rgb(0,0,0)","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeLineJoin":"miter","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":340.06,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","src":"src_to_picture","filters":[]}],"background":"cyan","backgroundImage":"src_to_my_picture","backgroundImageOpacity":1,"backgroundImageStretch":true}
请帮助。
编辑:使用带有canvas.todataurl的json对象的jspdf很容易完成。但我想知道如何在没有js
的情况下做到这一点canvas.loadFromJSON(JSON.parse(jsonobject)
var imgPdfData = canvas.toDataURL("image/jpeg", 1.0);
var pdf=new jsPDF("p", "mm", "a4");
var width = pdf.internal.pageSize.width;
var height = pdf.internal.pageSize.height;
pdf.addImage(imgPdfData, 'png', 5, 5,width-10,height-10);