iText - 没有边框的 roundRectangle
iText - roundRectangle with no border
有无边框的roundRectangle可以吗?以下代码创建 roundRectangles 和边框大小为 0f 和 1f 的矩形。对于 roundRectangle,当 lineWidth 设置为 0f 时,仍然有一个可见的边框,但是对于边框为 0f 的矩形来说,情况并非如此。
这是我使用的代码:
magazine = new Document(PageSize.LETTER,0,0,0,0);
pdfw = PdfWriter.getInstance(magazine, new FileOutputStream("out.pdf"));
magazine.open();
canvas = pdfw.getDirectContent();
canvas.rectangle(0,0,600,750);
canvas.setColorFill(BaseColor.ORANGE);
canvas.fillStroke();
canvas.setColorStroke(BaseColor.BLACK);
canvas.setColorFill(BaseColor.GRAY);
canvas.setLineWidth(1f);
llx = 100;
lly = 100;
wid = 100;
hei = 100;
canvas.roundRectangle(llx,lly, wid, hei, 10);
canvas.fillStroke();
llx = 100;
lly = 210;
wid = 100;
hei = 100;
canvas.rectangle(llx,lly, wid, hei);
canvas.fillStroke();
canvas.setColorStroke(BaseColor.BLACK);
canvas.setColorFill(BaseColor.WHITE);
canvas.setLineWidth(0f);
llx = 210;
lly = 100;
wid = 100;
hei = 100;
canvas.roundRectangle(llx,lly, wid, hei, 10);
canvas.fillStroke();
llx = 210;
lly = 210;
wid = 100;
hei = 100;
canvas.rectangle(llx,lly, wid, hei );
canvas.fillStroke();
当您在 PDF 中绘制线条和形状时,您会使用 路径构造运算符。下面的方法引入了一个re
(矩形)运算符来构造一个矩形。
canvas.rectangle(0,0,600,750);
iText 也提供了方便的方法。例如:下面的方法引入了一系列m
(移动到),l
(线到),c
(曲线到),...运算符:
canvas.roundRectangle(llx,lly, wid, hei, 10);
构建路径后,您可以使用 路径绘制运算符 实际绘制一些东西。 iText 有不同的 fill()
、stroke()
和 fillStroke()
变体。
您正在使用此方法:
canvas.fillStroke();
这意味着您使用填充颜色填充路径并使用描边颜色描边路径。在您的问题中,您表示只想填充路径(您想为圆角矩形内的内容着色);你不想抚摸它(你不想画圆角矩形的边框)。
这很容易实现。只需将 fillStroke()
替换为 fill()
:
canvas.fill();
现在您将只填充圆角矩形而不描边它的边框。
mkl 评论:
A line width of 0 shall denote the thinnest line that can be rendered at device resolution: 1 device pixel wide.
这是正确的。将线宽更改为 0 意味着在调用 stroke()
时不绘制线是一种常见的误解。如果你不想看到一条线,解决办法很简单:不要划它。
有无边框的roundRectangle可以吗?以下代码创建 roundRectangles 和边框大小为 0f 和 1f 的矩形。对于 roundRectangle,当 lineWidth 设置为 0f 时,仍然有一个可见的边框,但是对于边框为 0f 的矩形来说,情况并非如此。
这是我使用的代码:
magazine = new Document(PageSize.LETTER,0,0,0,0);
pdfw = PdfWriter.getInstance(magazine, new FileOutputStream("out.pdf"));
magazine.open();
canvas = pdfw.getDirectContent();
canvas.rectangle(0,0,600,750);
canvas.setColorFill(BaseColor.ORANGE);
canvas.fillStroke();
canvas.setColorStroke(BaseColor.BLACK);
canvas.setColorFill(BaseColor.GRAY);
canvas.setLineWidth(1f);
llx = 100;
lly = 100;
wid = 100;
hei = 100;
canvas.roundRectangle(llx,lly, wid, hei, 10);
canvas.fillStroke();
llx = 100;
lly = 210;
wid = 100;
hei = 100;
canvas.rectangle(llx,lly, wid, hei);
canvas.fillStroke();
canvas.setColorStroke(BaseColor.BLACK);
canvas.setColorFill(BaseColor.WHITE);
canvas.setLineWidth(0f);
llx = 210;
lly = 100;
wid = 100;
hei = 100;
canvas.roundRectangle(llx,lly, wid, hei, 10);
canvas.fillStroke();
llx = 210;
lly = 210;
wid = 100;
hei = 100;
canvas.rectangle(llx,lly, wid, hei );
canvas.fillStroke();
当您在 PDF 中绘制线条和形状时,您会使用 路径构造运算符。下面的方法引入了一个re
(矩形)运算符来构造一个矩形。
canvas.rectangle(0,0,600,750);
iText 也提供了方便的方法。例如:下面的方法引入了一系列m
(移动到),l
(线到),c
(曲线到),...运算符:
canvas.roundRectangle(llx,lly, wid, hei, 10);
构建路径后,您可以使用 路径绘制运算符 实际绘制一些东西。 iText 有不同的 fill()
、stroke()
和 fillStroke()
变体。
您正在使用此方法:
canvas.fillStroke();
这意味着您使用填充颜色填充路径并使用描边颜色描边路径。在您的问题中,您表示只想填充路径(您想为圆角矩形内的内容着色);你不想抚摸它(你不想画圆角矩形的边框)。
这很容易实现。只需将 fillStroke()
替换为 fill()
:
canvas.fill();
现在您将只填充圆角矩形而不描边它的边框。
mkl 评论:
A line width of 0 shall denote the thinnest line that can be rendered at device resolution: 1 device pixel wide.
这是正确的。将线宽更改为 0 意味着在调用 stroke()
时不绘制线是一种常见的误解。如果你不想看到一条线,解决办法很简单:不要划它。