java - iText: Why are my bullet points appearing as dashes instead of the default bullets in pdf? - Stack Overflow

I’m facing a problem where, whenever there is an unordered list in the HTML content that I’m parsing as

I’m facing a problem where, whenever there is an unordered list in the HTML content that I’m parsing as elements and filling into the PDF cell, everything else displays fine except the bullet points, which appear as dashes (-). What could cause this?

 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 Document document = new Document(PageSize.A4, 40, 40, 40, 40);
 PdfWriter writer = PdfWriter.getInstance(document, baos);
 document.open();
 document.add(buildContent());
 document.close();

 // method that should provide content to the document.

 public PdfPTable buildContent() throws IOException {
   InfoList infoList = infoListInstance.get();
   PdfPTable table = new PdfPTable(2);
   for (InfoListMessage message : infolistList.getMessages()) {
     renderMessageMetadata(message, table);
     renderMessageContent(message, table);
   }
   return table;
 }

 public void renderMessageContent(InfoListMessage message,
     PdfPTable table) throws IOException {

   PdfPCell cell = new PdfPCell();

   for (Element e :
       XMLWorkerHelper.parseToElementList(message.getContent(), null)) {
     cell.addElement(e);
   }
   table.addCell(cell);
}

HTML input:

<ul> 
  <li>document2.txt.txt (23 B)</li> 
  <li>document1.txt.txt (12 B)</li>  
</ul>

The method where the problem occurs and exception is thrown in the for-loop line.

How to get bullet points instead of dashes for an unordered list?

I’m facing a problem where, whenever there is an unordered list in the HTML content that I’m parsing as elements and filling into the PDF cell, everything else displays fine except the bullet points, which appear as dashes (-). What could cause this?

 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 Document document = new Document(PageSize.A4, 40, 40, 40, 40);
 PdfWriter writer = PdfWriter.getInstance(document, baos);
 document.open();
 document.add(buildContent());
 document.close();

 // method that should provide content to the document.

 public PdfPTable buildContent() throws IOException {
   InfoList infoList = infoListInstance.get();
   PdfPTable table = new PdfPTable(2);
   for (InfoListMessage message : infolistList.getMessages()) {
     renderMessageMetadata(message, table);
     renderMessageContent(message, table);
   }
   return table;
 }

 public void renderMessageContent(InfoListMessage message,
     PdfPTable table) throws IOException {

   PdfPCell cell = new PdfPCell();

   for (Element e :
       XMLWorkerHelper.parseToElementList(message.getContent(), null)) {
     cell.addElement(e);
   }
   table.addCell(cell);
}

HTML input:

<ul> 
  <li>document2.txt.txt (23 B)</li> 
  <li>document1.txt.txt (12 B)</li>  
</ul>

The method where the problem occurs and exception is thrown in the for-loop line.

How to get bullet points instead of dashes for an unordered list?

Share Improve this question edited yesterday rhens 4,8783 gold badges23 silver badges38 bronze badges asked Feb 14 at 12:23 Manish KumarManish Kumar 212 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

The default list item marker in iText v5 or earlier is a dash. XML Worker, which converts HTML/CSS to PDF or iText layout elements does not override this to the default HTML/CSS list marker.

You can define this explictly:

<ul style="list-style-type: disc">
    <li>document2.txt.txt (23 B)</li>
    <li>document1.txt.txt (12 B)</li> 
</ul>

Resulting in the expected output:

Newer versions of iText's HTML/CSS to PDF conversion respect the default marker.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745194065a4616004.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信