Q: I am using following code to add some text in red color to an
existing PDF page:
pdftron.PDF.Page page1 = doc1.GetPage(1);
writer1.Begin(page1);
System.Drawing.Font sys_font = new
System.Drawing.Font("Arial", 10);
Font my_font = Font.CreateTrueTypeFont(doc1,
sys_font, true, true);
//Element element = bld.CreateTextBegin(Font.Create
(doc1, Font.StandardType1Font.e_courier), 10);
Element element = bld.CreateTextBegin(my_font,
10);
writer1.WriteElement(element);
element = bld.CreateTextRun(Session
["ControlNumber"].ToString());
element.SetTextMatrix(1, 0, 0, 1, 290, 780); //
(125, 0, 0, 10, 0, 0);
GState gstate = element.GetGState();
gstate.SetStrokeColor(new ColorPt(1, 0, 0));
writer1.WriteElement(element);
writer1.WriteElement(bld.CreateTextEnd());
writer1.End();
... but result is in black text.
How to make text red?
----------
A:
1) Set the fill color space:
gstate.SetFillColorSpace(ColorSpace.CreateDeviceRGB());
2) Set the fill color (not stroke) to red:
gstate.SetFillColor(new ColorPt(1, 0, 0));