JsPDF 按钮箭头

问题描述 投票:0回答:1

我试图使用 jsPDF 构建一个按钮箭头,但在文档或 stackoverflow 上找不到任何内容。所以我创建了一个函数,它完全按照我想要的方式创建一个函数,我想在下面的答案中与您分享。

jspdf
1个回答
0
投票
function createArrow(doc, x, y, w, l, c, s) {
    const coef = w * 0.175 / 0.5;
    doc.setLineWidth(w);
    doc.setDrawColor(c);
    doc.line(x - l, y - l, x + coef, y + coef, s);
    doc.line(x + coef, y - coef, x - l, y + l, s);
}

const doc = new jsPDF('p', 'mm', [223, 157]);
      doc.createArrow(20, 20, 0.5, 1.2, '#000000', 'FD');
      doc.output('dataurlnewwindow');

在这里我想解释一下这是如何工作的。该函数接受 7 个参数:

1. doc = document
2. x   = top of the angle x axis
3. y   = top of the angle y axis
4. w   = width of the arrow
5. l   = length of the arrow
6. c   = color of the arrow
7. s   = style of the arrow (S - stroke, F - fill, FD - fill then stroke)

如果您想知道

coef
的用途是什么,它可以固定角度的顶部,如果不进行一点调整,在两条线的简单相交处看起来效果会不太好。

© www.soinside.com 2019 - 2024. All rights reserved.