jspdf 默认 'a4' 格式的像素宽度和长度是多少?
What is pixel width and length for jspdf's default 'a4' format?
jspdf 'a4' 格式的像素大小是多少?
我想在 pdf 中添加图像,这样它将占据文档的整个宽度。
new jsPDF('p', 'pt', 'a4');
new jsPDF('p', 'pt', [ 595.28, 841.89])
在 GitHub 上的源代码中,您可以看到 supported units (relative proportions to pt), and you can also see the default page formats(它们的 大小在 pt 中)。
希望这对您有所帮助,
劳拉
A4 像素尺寸:793.706 x 1,122.52
像素
使用此辅助函数将 jsPDF 点转换为其他单位(基于@lmerlo 的回答和原始来源)
function convertPointsToUnit(points, unit) {
// Unit table from https://github.com/MrRio/jsPDF/blob/ddbfc0f0250ca908f8061a72fa057116b7613e78/jspdf.js#L791
var multiplier;
switch(unit) {
case 'pt': multiplier = 1; break;
case 'mm': multiplier = 72 / 25.4; break;
case 'cm': multiplier = 72 / 2.54; break;
case 'in': multiplier = 72; break;
case 'px': multiplier = 96 / 72; break;
case 'pc': multiplier = 12; break;
case 'em': multiplier = 12; break;
case 'ex': multiplier = 6;
default:
throw ('Invalid unit: ' + unit);
}
return points * multiplier;
}
jspdf 'a4' 格式的像素大小是多少? 我想在 pdf 中添加图像,这样它将占据文档的整个宽度。
new jsPDF('p', 'pt', 'a4');
new jsPDF('p', 'pt', [ 595.28, 841.89])
在 GitHub 上的源代码中,您可以看到 supported units (relative proportions to pt), and you can also see the default page formats(它们的 大小在 pt 中)。
希望这对您有所帮助,
劳拉
A4 像素尺寸:793.706 x 1,122.52
像素
使用此辅助函数将 jsPDF 点转换为其他单位(基于@lmerlo 的回答和原始来源)
function convertPointsToUnit(points, unit) {
// Unit table from https://github.com/MrRio/jsPDF/blob/ddbfc0f0250ca908f8061a72fa057116b7613e78/jspdf.js#L791
var multiplier;
switch(unit) {
case 'pt': multiplier = 1; break;
case 'mm': multiplier = 72 / 25.4; break;
case 'cm': multiplier = 72 / 2.54; break;
case 'in': multiplier = 72; break;
case 'px': multiplier = 96 / 72; break;
case 'pc': multiplier = 12; break;
case 'em': multiplier = 12; break;
case 'ex': multiplier = 6;
default:
throw ('Invalid unit: ' + unit);
}
return points * multiplier;
}