Q:
The insertion of the new field (checkbox) works, but the checkbox has
no colour. You can load the PDF file into Acrobat and see that the
checkbox is exactly as it should be, in edit mode, but is essentially
transparent.
I have included the code taken from pdftron website below that is
supposed to initialise the checkbox default appearance. Could the
problem be with the way I am using this function?
//My Code
Annot newAnnot = pdftron.PDF.Annot.CreateWidget(doc,annot.GetRect(),
newField);
//Set the border style so we have a colour so we can see it! No!
Annot.BorderStyle bs = new Annot.BorderStyle(1);
newAnnot.SetBorderStyle(bs); //set the colour too..No!
newAnnot.SetColor(new ColorPt(0,0,1));
//try example code from pdftron help?
newAnnot.SetAppearance(CreateCheckmarkAppearance(doc),
Annot.AnnotationState.e_normal)
A:
The problem is that you are setting the background color property, but
are also creating a custom appearance - which takes the priority. You
can draw the annotation background within CreateCheckmarkAppearance().
For example:
Obj CreateCheckmarkAppearance(PDFDoc doc)
{
// Create a checkmark appearance stream
ElementBuilder build = new ElementBuilder();
ElementWriter writer = new ElementWriter();
writer.Begin(doc);
// Draw background
Element e = build.CreateRect(-0.2, -0.2, 1, 1);
e.SetPathFill(true); // this path is should be filled
// Set the path color space and color
Gstate gstate = element.GetGState();
gstate.SetFillColorSpace(ColorSpace.CreateDeviceRGB());
gstate.SetFillColor(new ColorPt(0, 0, 1)); // blue
writer.WritePlacedElement(e);
// Draw checkmark
writer.WriteElement(build.CreateTextBegin());
// other options are circle ("l"), diamond ("H"), cross ("\x35")
// See section D.4 "ZapfDingbats Set and Encoding" in PDF Reference
Manual for
// the complete graphical map for ZapfDingbats font.
e = build.CreateTextRun("4", Font.Create(doc,
Font.StandardType1Font.e_zapf_dingbats), 1);
writer.WriteElement(e);
writer.WriteElement(build.CreateTextEnd());
Obj stm = writer.End();
// Set the bounding box
stm.Put("BBox", Rect.CreateSDFRect(-0.2, -0.2, 1, 1));
stm.Put("Subtype", Obj.CreateName("Form"));
return stm;
}