ITextSharp draws a line under the text (title) in a random place on the page

Does anyone know how I can draw a line under the heading (a short line of bold text) that can be located in a random place on the page.

eg.

My Heading 1 ---------------------------------------------- Some random paragraph My Heading 2 ---------------------------------------------- 

I can do this, as I did above, using the string of the substring _ , but in order to get the string anywhere near the header, I need to set the font size to 2, which leads to a spotty ugly line.

I can also add two pieces on top of each other (one with a title and one with _), similar to the first example in this article http://www.mikesdotnetting.com/Article/82/iTextSharp-Adding-Text-with-Chunks- Phrases-and-Paragraphs , using the same font size, but it only seems to work at the top of the page, as soon as I add other paragraphs and try to do this in the middle of the page, the two pieces are separated with a clear line break at the end of the first fragment.

It seems you can draw lines in iTextSharp, but I don’t know how to calculate the coordinates, since all the examples that I saw use this method to place the line at the top or bottom of the page in a fixed place.

Any help is greatly appreciated.

Cheers Rob

+4
source share
2 answers

The LineSeperator object may be what you are looking for. Wrap it in a piece and place it where you need it.

Here's an example line separator:

 Chunk linebreak = new Chunk(new LineSeparator(4f, 100f, colorGrey, Element.ALIGN_CENTER, -1)); doc.Add(linebreak); 
+8
source

I know this is an older post, but maybe this will help someone.

 //Create Chunk for underline Chunk chkHeader = new Chunk("My Title", fnt13Bold); chkHeader.SetUnderline(1f, -2f); //Add Chunk to paragraph Paragraph pHeader = new Paragraph(chkHeader); 
+6
source

All Articles