Modify <Li> tag symbol in PDF generated through iText

Asked

Viewed 64 times

1

Kind of confusing title, but the problem is somewhat simple.

I am generating a PDF through iText and I am using HTML for being simpler.

I am performing the example below the only problem is that I would like to modify the tag symbol <li> for a square as below:

<li type='square'>Teste</li>

My code:

public static final String DEST = "\\pdfteste\\html_2.pdf";

    public static void main(String[] args)  {
        try{
        File file = new File(DEST);
        file.getParentFile().mkdirs();
        new TestiText7().createPdf(DEST);
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }

    public void createPdf(String file) throws IOException, DocumentException {
        // step 1
        Document document = new Document();
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        writer.setInitialLeading(12);
        // step 3
        document.open();

        // step 4
        StringBuilder sb = new StringBuilder();
        sb.append("<html><head></head><body>");
        sb.append("<ol><li>Teste</li>");
        sb.append("<li>Teste</li>");
        sb.append("<ul><li>Teste</li><li>Teste</li></ul>");
        sb.append("<li>Teste</li>");
        sb.append("<ul><li>Teste</li><li>Teste</li><ul><li type=\"square\">Teste</li></ul></ul>");
        sb.append("</ol>");
        sb.append("</body><html>");

        XMLWorkerHelper.getInstance().parseXHtml(writer, document,
                new StringReader(sb.toString()));

        // step 5
        document.close();
    }

}

This is the result in the file. Someone went through something or just can’t do it?

inserir a descrição da imagem aqui

  • Can you do something similar to CSS? I don’t know if it will, but if it does, I think that would be the way.

  • @Victorstafusa I will still check if via CSS right, but I wanted to go the simplest way.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.