1
我尝试了一切,但无法找到任何解决方案。我使用iText,飞碟将HTML转换为PDF,但无法做到这一点。运行这段代码同时有什么办法将HTML转换为PDF?
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.xhtmlrenderer.pdf.ITextRenderer;
import com.lowagie.text.DocumentException;
public class Pdf {
public static void main(String[] args) throws DocumentException, IOException {
String File_To_Convert = "WebContent/index.html";
String url = new File(File_To_Convert).toURI().toURL().toString();
System.out.println(""+url);
String HTML_TO_PDF = "ConvertedFile.pdf";
OutputStream os = new FileOutputStream(HTML_TO_PDF);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
os.close();
}
}
错误:
Flying Saucer: No configuration files found in classpath using URL: resources/conf/xhtmlrenderer.conf, resorting to hard-coded fallback properties.
PLZ表明你尝试过什么.. –
公共类PDF { 公共静态无效的主要(字串[] args)抛出DocumentException,IOException异常{ \t字符串File_To_Convert = “的WebContent/index.html的”; String url = new File(File_To_Convert).toURI()。toURL()。toString(); System.out.println(“”+ url); String HTML_TO_PDF =“ConvertedFile.pdf”; OutputStream os = new FileOutputStream(HTML_TO_PDF); ITextRenderer renderer = new ITextRenderer(); renderer.setDocument(url); renderer.layout(); renderer.createPDF(os); os.close(); } } – user2681809
警告:Flying Saucer:在类路径中找不到使用URL:resources/conf/xhtmlrenderer.conf的配置文件,并使用硬编码的回退属性。 – user2681809