document has no pages with itext

Other answers are good. This is an alternative.

In general, to prevent this error which often occurs when the document contains no meaningful data for content, even despite document.open() and document.newPage() having been called, and even after stamping other pages into that document, you can add an empty chunk when the document is opened to ensure the library never considers it empty. e.g.

document.open(); 
document.add(new Chunk("")); // << this will do the trick. 

XMLWorkerHelper.parseXHtml() expects (X)HTML or (X)HTML snippets. Try this:

worker.parseXHtml(writer, document, new StringReader("<p>helloworld</p>"));

Try to new a page just like document.newPage() before you write something to document, hope that helps.

Tags:

Java

Itext