I just uploaded the xhtmlrenderer and iText jar files. I can make PDF files using these banks.
I definitely want: I need to create a PDF if I give one valid URL (for example, " https://xhtmlrenderer.dev.java.net/news.html") instead of "inputFile". Is this possible with a flying saucer and iText?
If yes, please help me with this.
Also, when I try to run the code below, I get an error message: stream closed
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();
}
}
source
share