c# - Cell background color affects the color of other lines -


I am creating a PDF where I add some text to each page as well as 2 lines which use the following method Are:

  private zero-less lines (document pdfDoc, PdfContentByte cb) {cb.MoveTo (0, 562); Cb.LineTo (pdfDoc.PageSize.Width, 562); Cb.MoveTo (0, 561); Cb.LineTo (pdfDoc.PageSize.Width, 561); }  

On a specific page, there is a table where I am using the following code to change the background color for a particular cell:

  Header = new PDFPCL (new phrase (market_data_list [i], grid_data_harding)); Header.Colpan = 2; Header. Herbal alignment = iTextSharp.text.Element.ALIGN_CENTER; Header.BackgroundColor = new baseclosure (238,233,233); Market_table.AddCell (header); // Add cell to table  

Now I am specifying the color in the background which I have specified (gray), but the lines change from black to gray ... I attract those lines

There are two problems with your code:

The problem # 1: Method Draw Line () does not attract any line.

It creates paths for two rows, but the lines are not drawn from that method. You must add the following line:

  cb.Stroke ();  

Without that line, the stroke operator is called as long as the drawing of the lines is postponed. It can never happen, in this case, the lines are never ready. In your case, this happens when by the time other materials are prepared, the color of the stroke could have changed, in that case, to attract the path created in your DrawLines () method The use of color is unpredictable.

Problem # 2: You do not use best practices.

The colors in your code are being used to attract lines and shapes, they are unpredictable because you are not careful with graphics state stack

I have my DrawLines () will change the method like this:

>
  Private Zero Draw (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 (); }  

Now you can save the graphics state ( SaveState () ) before changing the color to black ( SetRGBColorStroke () ) Are there. You create paths for lines (using the LineTo () and MoveTo () method and you attract those lines ( Stroke () < / Code>). To ensure that the color changes you have applied do not affect the other content you are adding, you can use the graphics state stack for your previous state ( RestoreState () ) Restore.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -