Question

I am trying to add a line after text using the following:

bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb = writer.DirectContent;
template = cb.CreateTemplate(50, 50);
String text = "Name: " + MySession.Current._name;
float len = bf.GetWidthPoint(text, 8);
cb.SetRGBColorFill(0, 0, 0);
cb.BeginText();
cb.SetFontAndSize(bf, 8);
cb.SetTextMatrix(pageSize.GetLeft(330), pageSize.GetTop(30));
cb.ShowText(text);
cb.EndText();
cb.LineTo(pageSize.GetLeft(40), pageSize.GetTop(32));
cb.Stroke();
cb.SetColorStroke(new BaseColor(0, 0, 0));
cb.AddTemplate(template, pageSize.GetLeft(330), pageSize.GetTop(30));

The text works well but no line, any suggestions.

Was it helpful?

Solution 2

I figured out the solution:

                cb.AddTemplate(template1, pageSize.GetLeft(330), pageSize.GetTop(30));
                cb.SetLineWidth(2);
                cb.MoveTo(0, pageSize.Top - 34 );
                cb.LineTo(pageSize.Width, pageSize.Top - 34);
                cb.Stroke();

I should have had the stroke after Add.Template.

Hope this helps someone having the same issue.

OTHER TIPS

Use:

doc.Add(new Paragraph(" "));

In every where You can add this for moving to new Line

Environment.NewLine

use like this

string str = "MyText"+Environment.NewLine+strMyVariable+Environment.NewLine+"The Ending Text";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top