抚摸矩形背景
Stroking rect background
我最近将 PDFBox 更新到 2.0.0 版(用于其新的图像方法),但它们改变了您填充矩形的方式。
以前您会添加矩形,设置描边颜色并敲击,设置非描边颜色并填充矩形。
现在 fillRect 已替换为填充,我无法描边和填充。填充后调用 stroking 将不执行任何操作,反之亦然。
现在我不得不第二次调用 addRect 以获得预期的效果。
对更新我的方法有什么帮助吗?
Previously you would addRect, set the stroking color and struck
... 这样做会创建一个无效的 PDF!在路径创建开始(这里:addRect
)和绘制(这里:stroke
)之间,只允许额外的路径创建操作和最终可选的剪切路径操作。您设置的中间描边颜色无效。
大多数 PDF 查看器不会抱怨这种无效语法,但它仍然无效...
Now the fillRect has been replaced with fill and I'm unable to stroke and fill.
fillRect
仍然存在,只是已被弃用。因此,你可以看看它的作用:
public void fillRect(float x, float y, float width, float height) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: fillRect is not allowed within a text block.");
}
addRect(x, y, width, height);
fill();
}
因此,如果您曾经这样做
setStrokingColor(...);
addRect(...);
stroke();
setNonStrokingColor(...);
fillRect(...);
在 PDFBox 1.8.x 中,您可以在 2.0.0 中执行相同的操作或(不使用不推荐使用的方法)将最后一行替换为
addRect(...);
fill();
Now I'm forced to call addRect for a second time to get the desired effect.
但这也是你以前在幕后所做的!
PS最近PDFBox新增了两个操作'PDPageContentStream
class:fillAndStroke
,fillAndStrokeEvenOdd
、closeAndFillAndStroke
和 closeAndFillAndStrokeEvenOdd
。因此,现在您也可以使用
setStrokingColor(...);
setNonStrokingColor(...);
addRect(...);
fillAndStroke();
我最近将 PDFBox 更新到 2.0.0 版(用于其新的图像方法),但它们改变了您填充矩形的方式。
以前您会添加矩形,设置描边颜色并敲击,设置非描边颜色并填充矩形。
现在 fillRect 已替换为填充,我无法描边和填充。填充后调用 stroking 将不执行任何操作,反之亦然。
现在我不得不第二次调用 addRect 以获得预期的效果。
对更新我的方法有什么帮助吗?
Previously you would addRect, set the stroking color and struck
... 这样做会创建一个无效的 PDF!在路径创建开始(这里:addRect
)和绘制(这里:stroke
)之间,只允许额外的路径创建操作和最终可选的剪切路径操作。您设置的中间描边颜色无效。
大多数 PDF 查看器不会抱怨这种无效语法,但它仍然无效...
Now the fillRect has been replaced with fill and I'm unable to stroke and fill.
fillRect
仍然存在,只是已被弃用。因此,你可以看看它的作用:
public void fillRect(float x, float y, float width, float height) throws IOException
{
if (inTextMode)
{
throw new IllegalStateException("Error: fillRect is not allowed within a text block.");
}
addRect(x, y, width, height);
fill();
}
因此,如果您曾经这样做
setStrokingColor(...);
addRect(...);
stroke();
setNonStrokingColor(...);
fillRect(...);
在 PDFBox 1.8.x 中,您可以在 2.0.0 中执行相同的操作或(不使用不推荐使用的方法)将最后一行替换为
addRect(...);
fill();
Now I'm forced to call addRect for a second time to get the desired effect.
但这也是你以前在幕后所做的!
PS最近PDFBox新增了两个操作'PDPageContentStream
class:fillAndStroke
,fillAndStrokeEvenOdd
、closeAndFillAndStroke
和 closeAndFillAndStrokeEvenOdd
。因此,现在您也可以使用
setStrokingColor(...);
setNonStrokingColor(...);
addRect(...);
fillAndStroke();