gpt4 book ai didi

javascript - 如何使用 jsPDF 保存大图像?

转载 作者:行者123 更新时间:2023-11-30 20:06:17 28 4
gpt4 key购买 nike

我想通过 jsPDF 将大图像转换为 pdf。我的问题是为大图像做这件事。我想保持图像分辨率。我的图像大小以像素为单位,但我无法将大小设置为 jsPDF。我这样做:

var pdf = new jsPDF();
var imgData = 'data:image/png;base64,iV...';

pdf.setFontSize(40);
pdf.text(35, 25, "Octonyan loves jsPDF");
pdf.addImage(imgData, 'JPEG', 15, 40, 180, 180);
pdf.save();

jsFiddle 处运行.

代码创建 pdf 但不保护图像分辨率。

最佳答案

使用 new jsPDF('l', 'px', [pdfHeight, pdfWidth]); 第一个参数(横向或纵向)第二个是单位

这是 Jsfiddle

var imgData = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAERAAAATkCAMAAAA9GWtEAAAAllBMVEUAoujtHCQAoq2pHCTMZMupeuhfoujtHG3MHCQAjo6pTW01ZEo1oug1jsvtNo4AosvtHEpfTSSFNiQAem2FjujtTa3MNkpfeq2pNiQ1jujMV63MPG2FesuFTW3tNm0AjsupdsupaK01eo7MTY5fbXqFTUqpP0pfhMsAjq2pWY5fTUpfjug1ga01em2FZG2Fb601oq2pTa1nLp1vAAAi9klEQVR42uzBgQAAAACAoP2pF6kCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGD24EAAAAAAAMj/tRFUVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVYU9OBAAAAAAAPJ/bQRVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVWEPDgQAAAAAgPxfG0FVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV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NYahPOLj6ewAAAABJRU5ErkJggg==';
var button = document.createElement('button');
var img = document.createElement('img');
img.src = imgData;
img.onload = function(){
button.onclick = function(){
var pdf = new jsPDF();
var left = 15, top = 40;

var width = pdf.internal.pageSize.getWidth();
var maxWidth = (width - left*2);
var newWidth = img.naturalWidth < maxWidth ? img.naturalWidth : maxWidth;
var newHeight = img.naturalHeight*newWidth/img.naturalWidth;

var left = 15, top = 40;
var pdf = new jsPDF('l', 'px', [img.naturalHeight+top*2, img.naturalWidth+left*2]);

pdf.setFontSize(40);
pdf.text(35, 25, "Octonyan loves jsPDF");
pdf.addImage(imgData, 'JPEG', left, top, img.naturalWidth, img.naturalHeight);
pdf.save();
};
button.innerText = 'Create PDF and Download It'
document.body.appendChild(button);
}
<script src="https://rawgit.com/MrRio/jsPDF/master/dist/jspdf.min.js"></script>

关于javascript - 如何使用 jsPDF 保存大图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52903666/

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