How to make a separate substring Bold when printing a string in Pdf using iText in java eclipse?

I am using iText in Java to convert HTML to PDF.

I want some paragraph to have some words in bold, and some as bold + Underline for passing as a string to Java code and for converting to PDF using the iText library.

I can not find a suitable method for this. How should I do it?

+4
source share
1 answer

If you want to convert XHTML to PDF, you need iText + XML Worker.

Here you can find some examples: http://itextpdf.com/sandbox/xmlworker

:

public void createPdf(String file) throws IOException, DocumentException {
    // step 1
    Document document = new Document();
    // step 2
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
    // step 3
    document.open();
    // step 4
    XMLWorkerHelper.getInstance().parseXHtml(writer, document,
            new FileInputStream(HTML));
    // step 5
    document.close();
}

, HTML FileInputStream. String. , - :

XMLWorkerHelper.getInstance().parseXHtml(writer, document,
        new StringReader("<p>The <b>String</b> I want to render to PDF</p>"));

Sandbox , , .. , XHTML iText, .

+2

Source: https://habr.com/ru/post/1543203/


All Articles