如何更改编辑颜色

huangapple go评论84阅读模式
英文:

How to change redact color

问题

我正在使用 itext 7.1.8 版本,我需要修改隐私保护颜色,但是当我尝试这样做时,颜色没有改变。
我的代码如下:

PdfReader reader = new PdfReader(new FileInputStream(pdfDoc));
PdfWriter writer = new PdfWriter(new FileOutputStream("ResultFile.pdf"));
PdfDocument doc = new PdfDocument(reader, writer);
final PdfPage page = doc.getFirstPage();
final float[] borderColorBlack = { 0, 0, 0 };

PdfAnnotation redact = new PdfRedactAnnotation(new Rectangle(1, 1, 37, 20))
    .setTitle(new PdfString(""))
    .setColor(new float[] {0, 0, 0})
    .setFlag(PdfAnnotation.TOGGLE_NO_VIEW)
    .put(PdfName.Subj, PdfName.Redact)
    .put(PdfName.OC, new PdfArray(borderColorBlack));

page.addAnnotation(redact);
PdfCleanUpTool cleaner = new PdfCleanUpTool(doc, true);
cleaner.cleanUp();
doc.close();

我如何修改隐私保护颜色区域?

英文:

I'm using itext 7.1.8 and I need to change the redact color but when I'm trying to do it the color doesn't change.
My code looks like the following:

PdfReader reader = new PdfReader(new FileInputStream(pdfDoc));
PdfWriter writer = new PdfWriter(new FileOutputStream("ResultFile.pdf"));
PdfDocument doc = new PdfDocument(reader, writer);
final PdfPage page = doc.getFirstPage();
final float[] borderColorBlack = { 0, 0, 0 };

PdfAnnotation redact = new PdfRedactAnnotation(new Rectangle(1, 1, 37, 20))
    .setTitle(new PdfString(""))
    .setColor(new float[] {0, 0, 0})
    .setFlag(PdfAnnotation.TOGGLE_NO_VIEW)
    .put(PdfName.Subj, PdfName.Redact)
    .put(PdfName.OC, new PdfArray(borderColorBlack));

page.addAnnotation(redact);
PdfCleanUpTool cleaner = new PdfCleanUpTool(doc, true);
cleaner.cleanUp();
doc.close();

How can I change the redact color area?

答案1

得分: 1

我在这里找到了解决此问题的方法。我只是添加了一个标志:

PdfAnnotation redact = new PdfRedactAnnotation(new Rectangle(1, 1, 37, 20))
    .setTitle(new PdfString(""))
    .setColor(new float[] {0, 0, 0})
    .setFlag(PdfAnnotation.TOGGLE_NO_VIEW)
    .put(PdfName.Subj, PdfName.Redact)
    .put(PdfName.IC, new PdfArray(borderColorBlack))   // 在这里添加了代码
    .put(PdfName.OC, new PdfArray(borderColorBlack));
英文:

I found a solution to this issue here. I just have added flag:

PdfAnnotation redact = new PdfRedactAnnotation(new Rectangle(1, 1, 37, 20))
    .setTitle(new PdfString(""))
    .setColor(new float[] {0, 0, 0})
    .setFlag(PdfAnnotation.TOGGLE_NO_VIEW)
    .put(PdfName.Subj, PdfName.Redact)
    .put(PdfName.IC, new PdfArray(borderColorBlack))   // Added code here
    .put(PdfName.OC, new PdfArray(borderColorBlack));

huangapple
  • 本文由 发表于 2020年9月9日 16:10:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/63807394.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定