简体   繁体   English

Java无法删除图像文件,写入PDF后将itext7 html转换为Pdf转换图像文件

[英]Java Can't delete image file, itext7 html To Pdf conversion image file lock after writing to PDF

I am creating a multi page PDF file from HTML templates. 我正在根据HTML模板创建多页PDF文件。 There are some images as well that I'm showing in PDF. 还有一些我正在用PDF显示的图像。 PDF generate successfully and images are added in PDF file. PDF生成成功,并且图像已添加到PDF文件中。 But After this when I want to delete images they are not deleting, Popup appears that files are locked. 但是在此之后,当我要删除不删除的图像时,弹出窗口显示文件已锁定。 When I kill the program that writes PDF file, then you can delete images. 当我杀死编写PDF文件的程序时,可以删除图像。

public void createPdf(String htmlString) throws IOException {
     PdfWriter writer = new PdfWriter("C:\\Users\\DELL\\Desktop\\filename.pdf");
     PdfDocument pdf = new PdfDocument(writer);

     ConverterProperties properties = new ConverterProperties();
     HtmlConverter.convertToPdf(htmlString, pdf, properties);

     pdf.close();
     writer.close();
}

Note 注意

  1. I am converting HTML text to pdf. 我正在将HTML 文本转换为pdf。
  2. In html text img tag is used to insert external images from local file system. 在html文本中, img标签用于从本地文件系统插入外部图像。

This indeed is a bug in iText7. 这确实是iText7中的错误。 It has been fixed already and the fix will be available in 7.1.2 release (and correspondingly pdfHTML 2.0.2). 它已经得到修复,并且该修复程序将在7.1.2版本(以及相应的pdfHTML 2.0.2)中提供。

If you want to use the fixed version already, you can build iText Core from sources yourself. 如果要使用固定版本,则可以自己从源代码构建iText Core。 The commit fixing the issue is 4565db5de87666dc60d65befb463a0519fb8334d . 解决该问题的提交为4565db5de87666dc60d65befb463a0519fb8334d You don't have to build custom pdfHTML version because fix was only in iText7 Core. 您不必构建自定义pdfHTML版本,因为修复仅在iText7 Core中进行。

Build instructions are available here . 此处提供构建说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM