PDF 中的图像被截断:如何使画布完全适合 PDF 页面? [英] Image in PDF cut off: How to make a canvas fit entirely in a PDF page?

查看:34
本文介绍了PDF 中的图像被截断:如何使画布完全适合 PDF 页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 jspdf 库在 PDF 中放置画布时,图像会被截断.

When placing the canvas in the PDF using the jspdf library makes the image cut off.

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

有人知道如何使画布适合吗?

Does anyone have any ideas how to make the canvas fit?

推荐答案

也尝试设置图像的宽度和高度(无论如何,似乎很少有关于 addImage 的文档):

Try setting the width and height of the image as well (in any case, there is little documentation for addImage it seems):

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

这篇关于PDF 中的图像被截断:如何使画布完全适合 PDF 页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆