简体   繁体   English

使用itext pdf的pdf上缺少彩色区域

[英]Missing colored area on pdf using itext pdf

在此处输入图片说明

I am editing an existing pdf using itext pdf. 我正在使用itext pdf编辑现有的pdf。 While doing this, only a portion of rectangle box is showing as colored and some part is not highlighted. 在执行此操作时,矩形框的仅一部分显示为彩色,而部分未突出显示。 Looks like some overlay issue is happening here. 看起来这里发生了一些叠加问题。

The yellow colour is not showing in complete rectangle. 黄色没有以完整的矩形显示。

    PdfContentByte canvas = stamper.getUnderContent(1);
    canvas.saveState();
    canvas.setColorFill(BaseColor.YELLOW);
    canvas.rectangle(36, 786, 66, 16);
    canvas.fill();
    canvas.restoreState();
    stamper.close();

To make your task work, you should not draw under the existing content (as so that content can simply cover your mark) but instead over it. 为了使您的任务正常工作,您不应在现有内容绘制(这样内容就可以简单地覆盖您的标记),而应其上进行绘制。 And to make the original content shine through, you should use an appropriate blend mode: 为了使原始内容发光,应使用适当的混合模式:

PdfContentByte canvas = stamper.getOverContent(1);
canvas.saveState();
PdfGState state = new PdfGState();
state.setBlendMode(new PdfName("Multiply"));
canvas.setGState(state);
canvas.setColorFill(BaseColor.YELLOW);
canvas.rectangle(36, 786, 66, 16);
canvas.fill();
canvas.restoreState();
stamper.close();

( MarkContent test) MarkContent测试)

You didn't share your PDF, so I had to try with a PDF I have here. 您没有共享您的PDF,所以我不得不尝试这里的PDF。 Using an appropriately changed rectangle position and size the code marks this 使用适当更改的矩形位置和大小,代码将其标记为

之前

to look like this: 看起来像这样:

后

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM