如何在PDFBOX中绘制填充的多边形?

时间:2019-08-29 06:01:51

标签: java pdfbox

我想绘制一个填充的多边形。我已经研究了文档和方法:

fillPolygon(float[] x, float[] y)
Deprecated. 
Use moveTo(float, float) and lineTo(float, float) methods instead.

我找不到其他方法来填充pdfbox中的多边形。

1 个答案:

答案 0 :(得分:2)

源自PDFBox源代码:

public void fillPolygon(PDPageContentStream cs, float[] x, float[] y) throws IOException
{
    if (x.length != y.length)
    {
        throw new IllegalArgumentException("Error: some points are missing coordinate");
    }
    for (int i = 0; i < x.length; i++)
    {
        if (i == 0)
        {
            cs.moveTo(x[i], y[i]);
        }
        else
        {
            cs.lineTo(x[i], y[i]);
        }
    }
    cs.closePath();
    cs.fill();
}
相关问题