Skip to main content

Colors and Styling

PDFixa uses an RGB color model. Set colors on a page before calling draw methods; the color stays active until you change it.

Set a color

// setColor(red, green, blue) — each value 0–255
page.setColor(0, 0, 0); // black (default)
page.setColor(255, 0, 0); // red
page.setColor(0, 102, 204); // blue
page.setColor(255, 255, 255); // white

Text color

Set the color, then draw. All subsequent drawTextBox calls use that color. These examples assume fonts are already registered (see Fonts):

PdfFont boldFont    = doc.registerFont(/* bold .ttf bytes */);
PdfFont regularFont = doc.registerFont(/* regular .ttf bytes */);

page.setColor(30, 30, 30); // near-black body text
page.drawTextBox(72, 750, 450, 20, "Section title", boldFont, 14);

page.setColor(100, 100, 100); // grey secondary text
page.drawTextBox(72, 725, 450, 16, "Subtitle or caption", regularFont, 10);

page.setColor(0, 0, 0); // reset to black

Line color

page.setColor(180, 180, 180);  // light grey rule
page.drawLine(72, 700, 523, 700);

page.setColor(0, 102, 204); // accent color
page.drawLine(72, 698, 200, 698); // short underline accent

Fill color (background rectangles)

fillRect paints a solid rectangle. Draw it before any text that should appear on top.

// Header bar
page.setColor(0, 51, 102); // dark navy
page.fillRect(0, 800, 595, 42); // full-width bar at top of A4

page.setColor(255, 255, 255); // white text on dark background
page.drawTextBox(72, 810, 300, 20, "Monthly Report", boldFont, 14);
// Highlighted row in a table
page.setColor(240, 246, 255); // light blue tint
page.fillRect(72, 460, 451, 18);

page.setColor(0, 0, 0); // black text on top
page.drawTextBox(76, 462, 447, 14, "Grand total", boldFont, 10);

Rectangle outline

drawRect draws only the border, using the current color.

page.setColor(200, 200, 200);         // grey border
page.drawRect(72, 200, 451, 120); // box outline

Color reset pattern

Always reset to black after a colored section so later draw calls aren't accidentally tinted:

page.setColor(220, 53, 69);           // red alert text
page.drawTextBox(72, 680, 300, 16, "Overdue", boldFont, 10);
page.setColor(0, 0, 0); // back to black

Common palette

PurposeRGBHex
Body text000#000000
Secondary text100100100#646464
Rule / divider200200200#c8c8c8
Header background051102#003366
Row highlight240246255#f0f6ff
Accent / link0102204#0066cc
Warning2205369#dc3545
Success4016769#28a745