I am using List
class of iText7 to create an ordered list in a PDF. The text in the List
can be made bold easily but not the numbering. If I apply SetBold()
to the List
object every item added to the List
object gets converted to bold as well. I just want to make the numbering of the ordered list in bold. How can I achieve this?
The code that I am using
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(filePath)))
{
using (Document document = new Document(pdfDocument))
{
List header = new List(ListNumberingType.DECIMAL);
for (int i = 0; i < 10; i++)
{
ListItem li = new ListItem();
li.SetKeepTogether(true);
li.Add(new Paragraph("TableName").SetFontSize(13)
.SetBold());
li.Add(new Paragraph("Hello")).SetFontSize(13);
header.Add(li);
}
document.Add(header);
}
}
The output that I am getting
My desired output
In the desired output the numbering of the list is in bold
This is a Java example to achieve the desired result and I hope you can easily adapt it to your programming language
try (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName))) {
try (Document document = new Document(pdfDocument)) {
List header = new List(ListNumberingType.DECIMAL);
for (int i = 0; i < 10; i++) {
ListItem li = new ListItem();
ListItem li2 = new ListItem();
li.add(new Paragraph("TableName").setFontSize(13)
.setFont(PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD)))
.setFont(PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD));
li2.add(new Paragraph("Hello")).setFontSize(13)
.setFont(PdfFontFactory.createFont(StandardFonts.HELVETICA));
li.add(li2);
header.add(li);
}
document.add(header);
}
}
My output result