代码在这里:
function generatefromtable() {
//var imagedata = 'aa.jpg'
// var doc = new jsPDF();
var data = [], fontSize = 12, height = 5, doc;
//var doc = new jsPDF();
doc = new jsPDF('p', 'pt', 'A4', true);
doc.setFont("times", "normal");
doc.addPage()
doc.text(20, 20, 'this page for our compony details or docture details');
//doc.Image();
// doc.addImage(imagedata,'jpg',15,40,180,160)
//doc.text(100,10,"hello");
doc.setLineWidth(1)
doc.line(20, 30, 500, 30)
doc.setTextColor(0, 0, 255)
doc.setFont('courier')
doc.setFontType('bolditalic')
doc.setFontSize(22);
// doc.text(0, 20, "Patient Daily Report");
doc.setTextColor(100)
doc.setFontSize(fontSize);
data = [];
data = doc.tableToJson('tbl');
height = doc.drawTable(data, {
xstart : 10,
ystart : 10,
tablestart : 50,
marginleft : 5,
xOffset : 5,
yOffset : 15
});
doc.setTextColor(0, 0, 255)
doc.text(250, height + 20, 'Patient Daily Report');
doc.save("Patient_Daily_Report.pdf");
}
function generatefromtable() {
//var imagedata = 'aa.jpg'
// var doc = new jsPDF();
var data = [], fontSize = 12, height = 5, doc;
//var doc = new jsPDF();
doc = new jsPDF('p', 'pt', 'A4', true);
doc.setFont("times", "normal");
doc.addPage()
doc.text(20, 20, 'this page for our compony details or docture details');
//doc.Image();
// doc.addImage(imagedata,'jpg',15,40,180,160)
//doc.text(100,10,"hello");
doc.setLineWidth(1)
doc.line(20, 30, 500, 30)
doc.setTextColor(0, 0, 255)
doc.setFont('courier')
doc.setFontType('bolditalic')
doc.setFontSize(22);
// doc.text(0, 20, "Patient Daily Report");
doc.setTextColor(100)
doc.setFontSize(fontSize);
data = [];
data = doc.tableToJson('tbl');
height = doc.drawTable(data, {
xstart : 10,
ystart : 10,
tablestart : 50,
marginleft : 5,
xOffset : 5,
yOffset : 15
});
doc.setTextColor(0, 0, 255)
doc.text(250, height + 20, 'Patient Daily Report');
doc.save("Patient_Daily_Report.pdf");
}
答案 0 :(得分:0)
考虑下面的例子。
var pdf = new jsPDF('p','pt','a4');
var img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4Y+dDAb93fjD4HtO4qLlXU0ej2pdETsO11xEdV8cP2hExkSA2d3NHkA0Q0CIxSEyKmjyf/2Q==';
pdf.addImage(imgData, 'J
PEG', 20, 20, 20, 26);
pdf.text(50, 40, "Header");
pdf.addHTML(document.body,40,100,function() {
pdf.save('web.pdf');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<body>
<p id="to-pdf">HTML content...</p>
</body>
希望它可以帮到你。