Search code examples
pdfclown

Can't change the font color


I discovered the font color doesn't work too well, regardless of whether it is blue, dark blue or light blue. They are still all the same color.

var FontArialRegularFilePath = @"C:\Windows\Fonts\Arial.ttf";
var fontArialRegular = pdfclownFonts::Font.Get(parmDocument, FontArialRegularFilePath);
var file = new File();

var primitiveComposer = new PrimitiveComposer(new Page(file.Document));
{
    var blockComposer = new BlockComposer(primitiveComposer);

    primitiveComposer.SetFont(fontArialRegular, 22 /*[Font-Size]*/);
    primitiveComposer.SetFillColor(new DeviceRGBColor(double.Parse("0"), double.Parse("0"), double.Parse("49")));  //Dark Navy Blue...

    blockComposer.Begin(new RectangleF(0f, 0f, 200f, 50f), XAlignmentEnum.Left, YAlignmentEnum.Top);
    blockComposer.ShowText("Listing Price");
    blockComposer.End();
}

Solution

  • The OP sets the color like this:

    primitiveComposer.SetFillColor(new DeviceRGBColor(double.Parse("0"), double.Parse("0"), double.Parse("49")));  //Dark Navy Blue...
    

    So he seems to assume that the color components are given in the range 0..255. This is not the case, though, the type double is used for a reason: the actual range is 0..1.

    Thus, the OP most likely wanted

    primitiveComposer.SetFillColor(new DeviceRGBColor(0.0, 0.0, 49.0/255.0));  //Dark Navy Blue...
    

    As the OP considered the resulting color to be black, here different shades of pure blue created using new DeviceRGBColor(0.0, 0.0, Blue):

    different shades of blue

    The originally proposed value 49.0/255.0 is nearly 0.2, i.e. a very dark blue.

    I assume the OP knows that for certain blueish colors the red and green values are not 0.