如何更改圆形注释的颜色?
How to change the color of a circle annotation?
您好,我正在使用 C# 中的 iTextSharp 向现有 PDF 添加 SquareCircle 注释。
现在我想更改填充颜色注释 属性 ... 直到现在还没有结果。
打开 pdf,填充颜色 属性 在注释属性的外观选项卡中。
我使用的是 5.5.5.0 版本的 iTextSharp。
提前致谢。
请查看 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, more specifically the 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)引起的问题,这是查看器问题。
您好,我正在使用 C# 中的 iTextSharp 向现有 PDF 添加 SquareCircle 注释。
现在我想更改填充颜色注释 属性 ... 直到现在还没有结果。 打开 pdf,填充颜色 属性 在注释属性的外观选项卡中。
我使用的是 5.5.5.0 版本的 iTextSharp。
提前致谢。
请查看 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, more specifically the 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)引起的问题,这是查看器问题。