我刚刚下载了xhtmlrenderer和iText jar文件。使用这些jar文件,我可以制作pdf文件。
我的确需要的是: 如果我在"inputFile"处提供一个有效的URL(比如 "
如果是,麻烦指导我如何实现。
此外,当我尝试运行下面的代码时,出现错误: 流已关闭。
我的确需要的是: 如果我在"inputFile"处提供一个有效的URL(比如 "
https://xhtmlrenderer.dev.java.net/news.html
"),我需要创建pdf文件。这是否可能使用飞行器和iText?如果是,麻烦指导我如何实现。
此外,当我尝试运行下面的代码时,出现错误: 流已关闭。
import java.io.*;
import com.lowagie.text.DocumentException;
import org.xhtmlrenderer.pdf.ITextRenderer;
public class FirstDoc {
public static void main(String[] args)
throws IOException, DocumentException {
String inputFile = "samples/sql.html";
String url = new File(inputFile).toURI().toURL().toString();
String outputFile = "firstdoc.pdf";
OutputStream os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
os.close();
}
}
com.lowagie
,那是 iText 的一个古老版本。请使用com.itextpdf
的 iText。 - Amedee Van Gasse