use*_*816 33 html javascript jquery jspdf
我需要在jspdf.debug.js中更改默认的pdf页面宽度和字体大小.
在哪里以及如何更改jspdf.debug.js中的默认值?
Aid*_*api 68
除了使用其中一种默认格式,您还可以在指定的单位中指定所需的任何大小.
例如:
// Document of 210mm wide and 297mm high
new jsPDF('p', 'mm', [297, 210]);
// Document of 297mm wide and 210mm high
new jsPDF('l', 'mm', [297, 210]);
// Document of 5 inch width and 3 inch high
new jsPDF('l', 'in', [3, 5]);
Run Code Online (Sandbox Code Playgroud)
构造函数的第3个参数可以采用维数的数组.然而,它们与宽度和高度不对应,而是长边和短边(或翻转).
您的第一个参数(landscape或portrait)确定宽度和高度的大小.
在GitHub上的源代码中,您可以看到支持的单位(相对比例pt),您还可以看到默认页面格式(其大小在pt).
Ram*_*esh 25
从文档页面
设置页面类型传递构造函数中的值
jsPDF(orientation, unit, format)创建新的jsPDF文档对象实例参数:
orientation "纵向"或"横向"之一(或快捷键"p"(默认),"l")
unit指定坐标时使用的测量单位.其中一个"pt"(点),"mm"(默认),"cm","in"
格式 'a3','a4'(默认),'a5','字母','合法'之一
设置字体大小
setFontSize(size)设置即将发生的文本元素的字体大小
参数:
{Number} size以磅为单位的字体大小.
Kur*_*gor 17
我的情况是打印水平(横向)摘要部分 - 所以:
}).then((canvas) => {
const img = canvas.toDataURL('image/jpg');
new jsPDF({
orientation: 'l', // landscape
unit: 'pt', // points, pixels won't work properly
format: [canvas.width, canvas.height] // set needed dimensions for any element
});
pdf.addImage(img, 'JPEG', 0, 0, canvas.width, canvas.height);
pdf.save('your-filename.pdf');
});
Run Code Online (Sandbox Code Playgroud)
对于任何试图对此做出反应的人。有一点细微的差别。
// Document of 8.5 inch width and 11 inch high
new jsPDF('p', 'in', [612, 792]);
Run Code Online (Sandbox Code Playgroud)
或者
// Document of 8.5 inch width and 11 inch high
new jsPDF({
orientation: 'p',
unit: 'in',
format: [612, 792]
});
Run Code Online (Sandbox Code Playgroud)
当我尝试 @Aidiakapi 解决方案时,页面很小。对于差异尺寸,请以英寸 * 72 为单位,以获得您需要的尺寸。例如,我想要 8.5,所以 8.5 * 72 = 612。这是针对 jspdf@1.5.3 的。
| 归档时间: |
|
| 查看次数: |
76224 次 |
| 最近记录: |