I have a website where I am displaying pdf with itextsharp in telerik radwindow. I am succeeded with displaying pdf on telerik radwindow popup. Now, I have page name and their order and need rearrange to display TOC like below with itextsharp
Asked
Active
Viewed 151 times
-3
-
What you tried so far? Also what exactly is your question? And what do you use to display stuff? Is this on a website, inside a WinForms application, or is it WPF or are you trying to write to a text document... ? – MindSwipe Mar 27 '19 at 10:02
-
Same question as https://stackoverflow.com/questions/55372460/text-alignment-issue-with-string-padding-when-generating-pdf – Amedee Van Gasse Mar 27 '19 at 10:06
-
1This is not a valid question. Showing a picture of something and saying "I want this", is not a question. I recommend reading [ask] and [mcve] in order to get the basic of asking on StackOverflow. – xdtTransform Mar 27 '19 at 10:10
-
I updated my question – Bunty Choudhary Mar 27 '19 at 10:31
-
@AmedeeVanGasse yes it is same question. But here I am asking with itexsharp. and in another question I am trying to do it with padding(padright/padleft) of c#. I am appreciate team if they help me either one way. And if it is not a valid question then don't worry we have lots of resources where anyone can understood this. – Bunty Choudhary Mar 27 '19 at 10:36
1 Answers
0
You can do this by creating a chunk separator (cf. this answer) with a tabPosition
(to make the page numbers left aligned as you show in your image).
using (FileStream output = new FileStream(@"simpleToc.pdf", FileMode.Create, FileAccess.Write))
using (Document document = new Document(PageSize.A4))
{
PdfWriter writer = PdfWriter.GetInstance(document, output);
document.Open();
Chunk leader = new Chunk(new DottedLineSeparator(), 400);
Paragraph p = new Paragraph("Terms and Conditions");
p.Add(leader);
p.Add("4");
document.Add(p);
p = new Paragraph("Dental");
p.Add(leader);
p.Add("6");
document.Add(p);
p = new Paragraph("Vision");
p.Add(leader);
p.Add("7");
document.Add(p);
p = new Paragraph("Neighborhood Pharmacy");
p.Add(leader);
p.Add("8");
document.Add(p);
p = new Paragraph("Teladoc");
p.Add(leader);
p.Add("9");
document.Add(p);
p = new Paragraph("Retail Health Clinics");
p.Add(leader);
p.Add("11");
document.Add(p);
p = new Paragraph("Counseling Services");
p.Add(leader);
p.Add("12");
document.Add(p);
p = new Paragraph("Medical Bill Saver\u2122");
p.Add(leader);
p.Add("13");
document.Add(p);
p = new Paragraph("Vitamins");
p.Add(leader);
p.Add("14");
document.Add(p);
}
The result looks like this
As you called the library "iTextSharp" and only used the [iText] tag, I assume you are using iText 5.x, not 7.x. The code above has been tested using the current 5.5.14-SNAPSHOT development version.
The Chunk
constructor used above is marked Obsolete:
/**
* Creates a tab Chunk.
* Note that separator chunks can't be used in combination with tab chunks!
* @param separator the drawInterface to use to draw the tab.
* @param tabPosition an X coordinate that will be used as start position for the next Chunk.
* @since 2.1.2
*/
[Obsolete]
public Chunk(IDrawInterface separator, float tabPosition) : this(separator, tabPosition, false)
But as the old iText 5.x version as a whole is in maintenance mode, there is no need to fear that it will be dropped from the assembly during further development.

mkl
- 90,588
- 15
- 125
- 265