PDFBox: Handling white text on color background

此生再无相见时 提交于 2019-12-11 17:24:36

问题


I have some tricky PDF files contains white text. To don't render it in text stripper, I override ProcessTextPosition method:

private static final int COLOR_WHITE = 16777215;    
@Override
protected void processTextPosition(TextPosition text) {
        PDGraphicsState gs = getGraphicsState();    
        PDColor nonStrokingColor = gs.getNonStrokingColor();
        try {
            if (nonStrokingColor.toRGB() != COLOR_WHITE) {
                super.processTextPosition(text);
            }
        } catch (IOException e) {
            logger.error("Could not convert stroking color to RGB", e);
        }
}

However, sometimes I still need to render such white text- when it's placed on color background. As I understand, this is usually some filled rectangle under it, but I don't know how to handle it in ProcessTextPosition. Is there any way to do that? File example: example. Here "INCOME" is white on green rectangle, also "Huron account" is white text on blue rectangle.

来源:https://stackoverflow.com/questions/49383004/pdfbox-handling-white-text-on-color-background

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!