Skip to main content
Skip table of contents

How to change the color of a circle annotation?

I am adding a SquareCircle annotation to an already existing PDF using iTextSharp in C#. Now I want to change the Fill Color annotation property, but I don't know how.

When opening the PDF in Acrobat, the fill color property is in the appearance tab of the annotation properties.

Appearance tab

Posted on StackOverflow on Mar 26, 2015 by Lupetto Burlone

Please take a look at the CircleAnnotation example. It creates a circle annotation with a blue border and red as the interior color:

Colored circle annotation

Colored circle annotation

The code to add this annotation in iText 7 looks like this:

protected void manipulatePdf(String src, String dest) throws Exception {
    PdfDocument pdfDoc = new PdfDocument(new PdfReader(new FileInputStream(src)),
            new PdfWriter(new FileOutputStream(dest)));
    Rectangle rect = new Rectangle(150, 770, 50, 50);

    PdfAnnotation annotation = new PdfCircleAnnotation(rect)
            .setTitle(new PdfString("Circle"))
            .setDashPattern(new PdfArray(new int[]{3, 2}))
            .setBorder(new PdfArray(new float[]{0, 0, 2}))
            .put(PdfName.IC, new PdfArray(new int[]{1, 0, 0}));

This line sets the interior color:

annotation.put(PdfName.IC, new PdfArray(new int[]{1, 0, 0}));


some PDF viewers (such as Chrome PDF viewer) are not full PDF viewers. They don't support every type of annotation. For instance, if you open hello_circle.pdf in Chrome, you won't see the annotation. That is not a problem caused by the PDF (nor iTextSharp), that is a viewer problem.

Click How to change the color of a circle annotation? if you want to see how to answer this question in iText 5.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.