使用xmlworker创建PDF时新页面中的内容

Sat*_*h S 2 java pdf itext xmlworker

我用Itext和创建PDF xmlworker.我的问题是我想在新页面中创建内容.以下是我的代码.

File file = new File("D:/PDFFiles/Sathesh.pdf");
FileOutputStream fos=new FileOutputStream(file);
Document doc=new Document(PageSize.A4, 50, 50, 70, 70);
PdfWriter pdfWriter=PdfWriter.getInstance(doc, fos);
doc.open();
XMLWorkerHelper worker=XMLWorkerHelper.getInstance();
String firstString="<table><tr><td>First Page</td></tr></table>" ;
String secondString="<table><tr><td>Second Page</td></tr></table>" ; 
String final=firstString+secondString;
ByteArrayInputStream is = new ByteArrayInputStream(final.getBytes());
worker.parseXHtml(pdfWriter, doc, is);
doc.close();
fos.close();
Run Code Online (Sandbox Code Playgroud)

我希望firstString在第一页和secondString页面中.等待你的答复.

Mic*_*mey 6

分别解析字符串并在其间添加对newPage()的调用.

像这样的东西:

...
String firstString="<table><tr><td>First Page</td></tr></table>" ;
String secondString="<table><tr><td>Second Page</td></tr></table>" ;
ByteArrayInputStream is = new ByteArrayInputStream(firstString.getBytes());
worker.parseXHtml(pdfWriter, doc, is);
doc.newPage();
is = new ByteArrayInputStream(secondString.getBytes());
worker.parseXHtml(pdfWriter, doc, is);
doc.close();
fos.close();
Run Code Online (Sandbox Code Playgroud)