gpt4 book ai didi

canvas - PDF 中的图像被截断 : How to make a canvas fit entirely in a PDF page?

转载 作者:行者123 更新时间:2023-12-04 13:11:08 29 4
gpt4 key购买 nike

当使用 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/29578721/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com