Convert HTML to PDF using XMLWorker library doesn't work

1.5k views Asked by At

I have an HTML document which I need to convert to PDF format. I have added iText XMLWorker library to my project and wrote this snippet:

OutputStream file = new FileOutputStream(new File("testing.pdf"));
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, file);
document.open();
InputStream is = new ByteArrayInputStream(docString.getBytes());
XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
document.close();
file.close();

But the problem is that I can't include neither Document nor PdfWriter. They are not included in the library and when I tried to add

import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfWriter;

no .text is found in the library added.

What is the problem? Is there any thing missing? Should I include something else?

1

There are 1 answers

0
Patrick Ferro Ribeiro On

In 2019 to use in android iText7 and pdfHtml works fine using this in your build.gradle

implementation 'com.itextpdf:itext7-core:7.1.5' implementation 'com.itextpdf:html2pdf:2.1.2'

This the latest release.