Added by flor on September-7-2007, 11:44 am
public class HtmlDoc {
/** Creates a new instance of HtmlDoc */
public HtmlDoc() {
}
public static int topdf(String filename) { // I - Name of file to convert
String command; // Command string
Process process; // Process for HTMLDOC
Runtime runtime; // Local runtime object
java.io.InputStream input; // Output from HTMLDOC
byte buffer []; // Buffer for output data
int bytes; // Number of bytes
// Construct the command string
command = "htmldoc --quiet --jpeg --webpage -t pdf --left 36 " +
"--header .t. --footer .1. " + filename
// Run the process and wait for it to complete...
runtime = Runtime.getRuntime();
try {
// Create a new HTMLDOC process...
process = runtime.exec(command);
// Get stdout from the process and a buffer for the data...
input = process.getInputStream();
buffer = new byte[8192];
ExternalContext econtext = FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse response = (HttpServletResponse)econtext.getResponse();
response.setContentType("application/pdf");
response.setHeader("Content-Disposition", "attachment; filename=\""+filename+".pdf\"");
// Read output from HTMLDOC until we have it all...
while ((bytes = input.read(buffer)) > 0)
response.getOutputStream().write(buffer, 0, bytes);
response.getOutputStream().flush();
// Return the exit status from HTMLDOC...
return (process.waitFor());
}
catch (Exception e) {
// An error occurred - send it to stderr for the web server...
System.err.print(e.toString() + " caught while running:\n\n");
System.err.print(" " + command + "\n");
return (1);
}
}
Added by flor on December-25-2007, 4:27 pm
Added by flor on November-7-2007, 9:10 am
Added by flor on October-29-2007, 10:24 pm
Added by flor on September-5-2007, 10:42 pm
Added by flor on September-5-2007, 8:04 pm