The background color of the cell affects the color of other lines

I create a PDF where I add text to each page, as well as 2 lines that are drawn using the following method:

private void DrawLines(Document pdfDoc, PdfContentByte cb) {
    cb.MoveTo(0, 562);
    cb.LineTo(pdfDoc.PageSize.Width, 562);
    cb.MoveTo(0, 561);
    cb.LineTo(pdfDoc.PageSize.Width, 561);
}

One specific page has a table in which I use the following code to change the background color for one specific cell:

header = new PdfPCell(new Phrase(market_data_list[i], grid_data_heading));
header.Colspan = 2;
header.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
header.BackgroundColor =new BaseColor(238,233,233);
market_table.AddCell(header); //adds cell to the table

Now I get a cell with the specified background color (gray), but the lines change from black to gray ... I want to draw these black lines in black!

+4
source share
1 answer

There are two problems in the code:

Problem number 1: the method DrawLines()does not draw any lines.

, . :

cb.Stroke();

, . , . . , , , DrawLines(), .

№ 2: .

, , , . , ..

DrawLines() :

private void DrawLines(Document pdfDoc, PdfContentByte cb) {
    cb.SaveState();
    cb.SetColorStroke(GrayColor.GRAYBLACK);
    cb.MoveTo(0, 562);
    cb.LineTo(pdfDoc.PageSize.Width, 562);
    cb.MoveTo(0, 561);
    cb.LineTo(pdfDoc.PageSize.Width, 561);
    cb.Stroke();
    cb.RestoreState();
}

(SaveState()) (SetRGBColorStroke()). ( LineTo() MoveTo()), (Stroke()). , , , (RestoreState()).

+2

All Articles