JSPDF(IMGAGE到PDF)不将整个图像转换为PDF

发布于 2025-01-25 21:29:25 字数 855 浏览 2 评论 0 原文

var pdff ;
function encodeImageFileAsURL(element) {
  var file = element.files[0];
  var reader = new FileReader();
  reader.onloadend = function() {
    console.log(reader.result)
    pdff = reader.result;
    pdf();
  }
  reader.readAsDataURL(file);
}
function pdf() {
    var doc = new jsPDF();
var img = new Image();
img.src = pdff;
var width = doc.internal.pageSize.getWidth;
var height = doc.internal.pageSize.getHeight;



 doc.addImage(img, 'JPG', 0, 0, width, height);
    doc.save('imkk.pdf'); // downloads pdf 
}

这是我当前正在使用的代码将image转换为base64字符串,然后是PDF,它可以与小图像一起使用,但是我需要制作一个PDF,其中图像很大,它使PDF制成PDF,但仅使用一部分图像我想要的pdf中的图像链接: -

var pdff ;
function encodeImageFileAsURL(element) {
  var file = element.files[0];
  var reader = new FileReader();
  reader.onloadend = function() {
    console.log(reader.result)
    pdff = reader.result;
    pdf();
  }
  reader.readAsDataURL(file);
}
function pdf() {
    var doc = new jsPDF();
var img = new Image();
img.src = pdff;
var width = doc.internal.pageSize.getWidth;
var height = doc.internal.pageSize.getHeight;



 doc.addImage(img, 'JPG', 0, 0, width, height);
    doc.save('imkk.pdf'); // downloads pdf 
}

This is the code I am using currently to convert image to base64 string and then to pdf, it works with small images but I need to make a pdf in which the image is large it makes the pdf but only with a portion of image here is the image link that I want in pdf :- https://drive.google.com/file/d/1X3G3gGsTUKvAtBh78iHMh_G4oy2-O73D/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

留一抹残留的笑 2025-02-01 21:29:25
// You need to make your image into a Data URL and declare page size

var imgData = 'data:image/jpeg;base64,/9j/.............../an/9k='
var width = 8.33
var height = 125

var doc = new jsPDF({ unit: 'in', format: [width, height],})
doc.addImage(imgData, 'JPG', 0, 0, width, height)
doc.save('imkk.pdf')

默认值仅是页面上图像的开始,通过声明页面宽度和高度,一个页面可以是该环境的URL长度限制,因此请注意,通常可以是1.5 MB。

// You need to make your image into a Data URL and declare page size

var imgData = 'data:image/jpeg;base64,/9j/.............../an/9k='
var width = 8.33
var height = 125

var doc = new jsPDF({ unit: 'in', format: [width, height],})
doc.addImage(imgData, 'JPG', 0, 0, width, height)
doc.save('imkk.pdf')

The default will just be the start of image on the page, by declaring page width and height that one page can be whatever the URL length limit is for that environment, so note it can often be 1.5 MB.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文