0

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?

4
  • XML Worker is an add-on for iText. You have the XML Worker library, but not the iText library. And while we are at it: why are you using the old iText 5 + the old XML Worker, when it has been replaced with iText 7 and pdfHTML? See developers.itextpdf.com/content/… Commented Sep 6, 2017 at 16:45
  • I have included iText 7.0 to my app but HtmlConverter can't be imported, although I have added all sub-libraries to the project !! Commented Sep 6, 2017 at 17:08
  • I'm pretty sure some sublibraries are missing. Show us your POM. Commented Sep 6, 2017 at 18:35
  • @BrunoLowagie OP does not use Maven (or Gradle, because Android), because if they were, then adding a dependency on XMLWorker would automatically pull in the required dependency. Therefore I conclude that they can not and will not show you their POM. Commented Sep 6, 2017 at 19:27

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.