admin管理员组文章数量:1415645
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 01 Answer
Reset to default 1The 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.
版权声明:本文标题:java - iText: Why are my bullet points appearing as dashes instead of the default bullets in pdf? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745194064a2647051.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论