简体   繁体   中英

Missing colored area on pdf using itext pdf

在此处输入图片说明

I am editing an existing pdf using itext 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)

You didn't share your PDF, so I had to try with a PDF I have here. Using an appropriately changed rectangle position and size the code marks this

之前

to look like this:

后

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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