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