What functions should I call to set the stroke width and opacity when drawing ink type annotation? I have go through the class API for PdfAnnotation and PDFStamp, but it seems t
What functions should I call to set the stroke width and opacity when drawing ink type annotation?
There are two answers:
The PDF specification mentions
BS dictionary (Optional) A border style dictionary (see Table 166) specifying the line width and dash pattern that shall be used in drawing the paths.
as another entry specific to the Ink annotation dictionary. This at least allows you to set the stroke width but not the opacity. Simply add a line like this
PdfAnnotation an = PdfAnnotation.createInk(stamper.getWriter(), rect, "", inkList);
an.setColor(new BaseColor(30, 89, 255));
an.setFlags(PdfAnnotation.FLAGS_PRINT);
// vvv set line width to 5:
an.setBorderStyle(new PdfBorderDictionary(5, PdfBorderDictionary.STYLE_SOLID));
// ^^^ set line width to 5:
stamper.addAnnotation(an, 1);
to set the stroke width to 5 and get a result like this:
The PDF specification also mentions
The annotation dictionary’s AP entry, if present, shall take precedence over the InkList and BS entries; see Table 168 and 12.5.5, “Appearance Streams.”
Thus, you can create a PdfAppearance
, use its methods to create an appearance exactly as you want it, including transparency, and set it as the normal appearance of the annotation. PDF viewers then shall display the annotation just like you want.