使用 XMLWorkerHelper 解析 html 文本后,Pdf Writer 未打印所有 html 文本

Pdf Writer is not printing all html text after parsing html text with XMLWorkerHelper

我有以下 html 文字。

<p>Use your card when shopping online at Our store and receive 20% off on your very first order.</p> <p>Our store delivers the latest styles at affordable prices for young trendsetters. For those who love putting a sexy spin on their everyday wardrobe, look no further--Our store is the ultimate style destination! Shop the latest pants, dresses and more. Shop now! We've got everything you're looking for.</p> <div> <p>To redeem this offer, click the Redeem button, sign up for our newsletter, and we will email you a discount code, entitling you to 70% off on your first order.</p> </div>

我正在用 XMLWorkerHelper 解析它,如下所示。

StringReader strReader = new StringReader("<html><head><style> body {font-family:ArialUnicodeMS; font-size:9pt;} </style></head><body>" + htmlString+"</body></html>");
            try {
                PdfHtmlElementHandler eh = new PdfHtmlElementHandler();
                p = new Paragraph();
                XMLWorkerHelper.getInstance().parseXHtml(eh, strReader);
                List<Element> htmlList = eh.getHtmlList();
                for(int i=0; i<htmlList.size(); i++) {
                    p.addElement(htmlList.get(i));
                }
            }
           PdfPCell cell_2 = new PdfPCell();
           PdfPTable table = new PdfPTable(2);
           cell_2.addElement(p);
           table.addCell(cell_2);

现在,看到我的 html 文本 carefully.It 在最后有一个 <div> 标签。使用 XMLWorkerHelper 解析后,我在 paragraph 对象中添加元素,如下所示

 p.addElement(htmlList.get(i));

现在生成的 pdf 不会显示完整的 text.Its 打印文本,方法是像下面这样修剪最后的 <div> 标签文本。

在我们的商店在线购物时使用您的卡,并在您的第一笔订单中享受 20% 的折扣。

我们的商店以实惠的价格为年轻的潮流引领者提供最新款式。对于那些喜欢在日常衣橱中加入性感元素的人来说,别无所求——我们的商店是时尚的终极目的地!购买最新的裤子、连衣裙等。现在去购物!我们有您要找的一切。

如何解决这个问题 issue.I 想要全文 printed.Is 这是因为我要添加到段落对象中? 因为当我使用下面的代码时。

StringReader strReader = new StringReader("<html><head><style> body {font-family:ArialUnicodeMS; font-size:9pt;} </style></head><body>" + htmlString+"</body></html>");
            try {
                PdfHtmlElementHandler eh = new PdfHtmlElementHandler();
                pdfDiv = new PdfDiv();
                XMLWorkerHelper.getInstance().parseXHtml(eh, strReader);
                List<Element> htmlList = eh.getHtmlList();
                for(int i=0; i<htmlList.size(); i++) {
                    pdfDiv.addElement(htmlList.get(i));
                }
            }
           PdfPCell cell_2 = new PdfPCell();
           PdfPTable table = new PdfPTable(2);
           cell_2.addElement(pdfDiv);
           table.addCell(cell_2);

正在打印全文。我刚刚用 pdfDiv 替换了 p。但我遇到了另一个问题。

如果文本太长无法打印在一页上,则应打印在其他页面上page.But pdfDiv 不会发生这种情况。

夏天:-

请 help.Its 真的 urgent.I 我正在使用 Itext 库生成 pdf。

问题已通过将 itext 的版本从 5.3.2 更改为 5.5.7.

得到解决