当前位置: 首页 > 面试题库 >

具有base64图像的HTML到PDF引发FileNotFoundException

司空俊雄
2023-03-14
问题内容

我正在使用itextpdf-5.0.6.jar(Java 8),当我尝试导出具有base64图像标签的html代码时,出现文件未找到异常的情况。

如果我移除图片标签,一切都会很好!

我发现很少有关于覆盖图像标签处理器的解决方案,但是大多数解决方案都是旧的并且与5.0.6版本不兼容。

这是我发送的HTML:

    "<!doctype html>\n<html lang=\"en\">\n<head>\n    
<meta charset=\"UTF-8\">\n    
<title>Test PDF</title>\n</head>\n<body>\n\n
<div class=\"pdf-header\">\n\n 
  <img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAc4AAABQCAYAAACQ/ZU3AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoV2luZ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0bRaZ70zToSZnBxyFgnT/pYZaJsFwAFphaIdyl2enzfGCfs0gsiftP3I4BHzhPVjkU1FKGASQ2iBiycqcuF29uy+NAwQcYBP1+k6+IBpADPMMaVMU7xVRyv7fZj7i52Ni9ugqs/VymsO5TF/VRGrZQ4mHokH4JSxxPYig2d4iIJMWJeIhtRgU/INvC6apzaXKVILIoxgoEfaPTTOuN7V74SEXtQ6UFEG5vqrih2BSoAUptqkIKMdxob39ecU/xwd2Yfg9X2Yz4wT+S+R6PcZ238MHgMltuAMA8cDZL85ioKMW4YA2DyRalJbPWM/EZyv8eFmmAmAIRxsjzUUOE57gII0qA+FZdwp0jY3EcapwT1S/UT7DBfz9ZHURlPa8VBuu4tvjBMH7/dRkD93hq1DQ46A1I8nURDzBUaB2rJIQQfTjsuRCEydyG+8pIQK3y0uojc9nJcmESxw3rmBsg/E/D1BQa5fQ/UB7flDodmyVyP9KTyHo8ZKjlYKmFhPSRQyAOM8jXTe2xc3NDU1Iei4g3SApNPtSgg3h6TTyOyBJNSFhNSwT7eU32BjaCV/rwSk5yoki/9QXgZsOo0UmHaSMMlgXF0U7WD/Lq3Mvh7lK8foYpH8ioEg3nVi9lPYoF2gmTukzXKtlNGF4h9DhD37JIB3pQcF1VXayXsGwgazQt4HpKr7Qj6Xybwvl38nVelGswY+k/WUBDZ21MQjr0c5O9soZv9f8KZfVW995bi/5HHPDelL8w6UQ6GAx9IIyQai3Kt2fKH3qxxDx4g861v4PwEGAPxb/SZEmJVjAAAAAElFTkSuQmCC\">     \n\n\n</div>\n\n<div class=\"main\">\n<div class=\"canvas\">\nHellow world</div></div></body>\n</html>"

我的代码的一部分:

fileOutputStream = new FileOutputStream(file);
Document document = new Document();
PdfWriter.getInstance(document, fileOutputStream);
document.open();
HTMLWorker htmlWorker = new HTMLWorker(document);
StringReader stringReader = new StringReader(htmlCode);
htmlWorker.parse(stringReader);
document.close();
fileOutputStream.close();

任何帮助将不胜感激


问题答案:

请停止使用HTMLWorker,因为在StackOverflow HTMLWorker上已多次重复使用,但很早以前该类已被XML
Worker放弃了。我们不会投资进一步开发HTMLWorker它,因此使用它是一个非常糟糕的选择。请切换到XML Worker。

还要升级到最新的iText版本,即您使用的版本从2011年2月4日开始,在过去的4年中已修复了许多错误。确保同时拥有相同版本号的iText
jar和XML Worker jar。

目前尚不支持Base64图像,但是我为您提供了一个非常简单的概念证明,它显示了添加对此类图像的支持是多么容易。看一下ParseHtml4示例和生成的PDF:html_4.pdf。

为此,您需要编写ImageProvider接口的实现。我通过扩展AbstractImageProvider类来做到这一点:

class Base64ImageProvider extends AbstractImageProvider {

    @Override
    public Image retrieve(String src) {
        int pos = src.indexOf("base64,");
        try {
            if (src.startsWith("data") && pos > 0) {
                byte[] img = Base64.decode(src.substring(pos + 7));
                return Image.getInstance(img);
            }
            else {
                return Image.getInstance(src);
            }
        } catch (BadElementException ex) {
            return null;
        } catch (IOException ex) {
            return null;
        }
    }

    @Override
    public String getImageRootPath() {
        return null;
    }
}

如您所见,我"base64,"通过标记的src属性检查传递给XML Worker
的内容是否存在img。如果String存在,我将解码其后的内容,"base64,"并返回一个Image使用结果字节创建的对象。

一旦ImageProvider实现了此实现,只需将其传递给XML Worker。



 类似资料:
  • 我有申请发邮件。图书馆使用了斯威夫特·梅勒。我已经生成了用于发送电子邮件html字符串,其中包含各种标记,包括标记我可以将img src标记转换为bas64图像吗 至

  • 我试图生成一个. docx从超文本标记语言字符串与docx4j在Java,其中包含Base64图像里面。目前,我能够生成Word并下载它(在一个Vaadin项目内),但图像没有正确插入。但是,如果我把超文本标记语言代码放入index.html页面,它们确实显示正确! 我使用的代码是这样的: 有没有什么特别的工作应该做,而我没有做? 编辑: 我现在可以插入图片了!用以下代码替换行下方和行上方的代码:

  • 问题内容: 我在内联显示Base64图像时遇到问题。 有人可以指出我正确的方向吗? 问题答案: 我怀疑当然是实际的base64数据,否则对我来说看起来不错。在类似方案起作用的地方查看此小提琴。您可以尝试指定字符集。 您可以尝试使用base64解码器查看base64数据是否正确。

  • 我已经搜索了这些问题,但没有找到解决我的具体问题的方法。我需要做的是将包含图像和CSS样式的HTML文件转换为PDF。我正在使用iText5,并且已经能够将样式包含到生成的PDF中。但是,包括图像在内,我还在挣扎。我在下面包含了我的代码。具有绝对路径的图像包含在生成的PDF中,具有相对路径的图像不包含在生成的PDF中。我知道我需要实现AbstractImageProvider,但我不知道如何实现。

  • 在Android中,有没有办法在中显示带有文本的图像?我正在从

  • 我写了一些使用javascript/jQuery捕获图像的代码下面是代码: 项目_图像打印base64格式,如何将base64转换为图像,以及如何在javascript客户端中使用该路径。 我在谷歌搜索了这么多网站,但它不工作,而且代码不适合我的要求。