使用 jspdf 库将 Canvas 放入 PDF 时,会导致图像被截断。
html2canvas(myContainer, {background: 'red'}).then (canvas) ->
imgData = canvas.toDataURL('image/jpeg', 1.0)
window.open(imgData) # this is just a test that opens the image in a new tab and it displays nicely, the entire image
pdf = new jsPDF("l", "pt", "b1") # tried a variety of formats but no luck
pdf.addImage(imgData, 'JPEG', 0, 0)
pdf.save('file.pdf') # the generated pdf that contains the image gets trimmed
有人知道如何使 Canvas 适合吗?
最佳答案
尝试设置图像的宽度和高度(无论如何,addImage 的文档似乎很少):
var pdf = new jsPDF("l", "mm", "a4");
var imgData = canvas.toDataURL('image/jpeg', 1.0);
// due to lack of documentation; try setting w/h based on unit
pdf.addImage(imgData, 'JPEG', 10, 10, 180, 150); // 180x150 mm @ (10,10)mm
关于canvas - PDF 中的图像被截断 : How to make a canvas fit entirely in a PDF page?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41288854/