简体   繁体   English

Jspdf(imgage to pdf)不将整个图像转换为 pdf

[英]Jspdf (imgage to pdf) not converting whole image to 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/这是我目前用来将图像转换为 base64 字符串然后转换为 pdf 的代码,它适用于小图像,但我需要制作一个 pdf,其中图像很大,它使 pdf 但这里只有一部分图像是我想要的图像链接 pdf:- https://drive.google.com/file/d/1X3G3gGsTUKvAtBh78iHMh_G4oy2-O73D/

// 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.默认值只是页面上图像的开始,通过声明页面宽度和高度,一页可以是该环境的 URL 长度限制,因此请注意它通常可以是 1.5 MB。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM