您好我正在使用C#中的iTextSharp为已存在的PDF添加SquareCircle注释。
现在我想更改Fill Color注释属性......直到现在都没有结果。 打开pdf,“填充颜色”属性位于注释属性的“外观”选项卡中。
我正在使用5.5.5.0版本的iTextSharp。
提前感谢。
答案 0 :(得分:0)
请查看CircleAnnotation示例。它创建一个圆形注释,蓝色边框,红色作为内部颜色:
添加此注释的代码如下所示:
public void manipulatePdf(String src, String dest) throws IOException, DocumentException {
PdfReader reader = new PdfReader(src);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
Rectangle rect = new Rectangle(150, 770, 200, 820);
PdfAnnotation annotation = PdfAnnotation.createSquareCircle(
stamper.getWriter(), rect, "Circle", false);
annotation.setTitle("Circle");
annotation.setColor(BaseColor.BLUE);
annotation.setFlags(PdfAnnotation.FLAGS_PRINT);
annotation.setBorder(new PdfBorderArray(0, 0, 2, new PdfDashPattern()));
annotation.put(PdfName.IC, new PdfArray(new int[]{1, 0, 0}));
stamper.addAnnotation(annotation, 1);
stamper.close();
}
我将此示例基于official documentation的示例,更具体地说是MovieTemplates示例。
我添加的唯一内容是设置内部颜色的线:
annotation.put(PdfName.IC, new PdfArray(new int[]{1, 0, 0}));
如果您需要一个C#示例:我为本书编写的示例已移植到C#,您可以在此处找到它们:chapter 7: C# examples
将put()
更改为Put()
以使其适合您应该不会有问题。
警告:某些PDF查看器(例如Chrome PDF查看器)不是完整的PDF查看器。它们不支持所有类型的注释。例如,如果您在Chrome中打开hello_circle.pdf,则无法看到注释。这不是由PDF(也不是iTextSharp)引起的问题,这是一个观众问题。