Introduction
During work I faced one requirement where I had to bind multiple chunks into a single phrase and show these chunks at both the ends; i.e., left and right end, of the same line. So here I will explain how I completed that point.
Here I take one Phrase, ph1, and I have two strings, Project name, which contain the name of the Project and Date. I want to display the Project name at the left side and Date at the right side in a single line.
- Document doc = new document()
- Paragraph para = new Paragraph();
- doc.open()
- Chunk glue = new Chunk(new VerticalPositionMark());
- Phrase ph1 = new Phrase();
- ph1.Add(new Chunk(Environment.NewLine));
- string projectname = "Project Name: " + dr["ProjectName"].ToString();
- string date = dr["StartDate"].ToString() + "-" + dr["EndDate"].ToString();
- Paragraph main = new Paragraph();
- ph1.Add(new Chunk(projectname));
- ph1.Add(glue);
- ph1.Add(new Chunk('('+date +')'));
- main.Add(ph1);
- para.Add(main);
- doc.Add(para);
- doc.close();
Output
Summary
In this blog we saw how we can add multiple chunks into a single phrase, and how we can add two chunks at different locations using a single phrase.