OTSSolutions
asked on
Converting JSP page to PDF format
Hi guys,
I have a jsp page containing a dynamic report with images. Which is producing the data from the database. I want an option in jsp page "Save as pdf" so that entire page should be saved as pdf format.
I am using http://www.pd4ml.com/examples.htm
The code where i need to pass the dynamic page name or url mapping is......
public static void main(String[] args) {
try {
PdfViewerStarter jt = new PdfViewerStarter();
jt.doConversion("http://pd4ml.com/sample.htm", "D:/pd4ml.pdf");
} catch (Exception e) {
e.printStackTrace();
}
}
public void doConversion( String url, String outputPath )
throws InvalidParameterException, MalformedURLException, IOException {
File output = new File(outputPath);
java.io.FileOutputStream fos = new java.io.FileOutputStream(o utput);
PD4ML pd4ml = new PD4ML();
pd4ml.setHtmlWidth(userSpa ceWidth);
pd4ml.setPageSize(pd4ml.ch angePageOr ientation( PD4Constan ts.A4));
pd4ml.setPageInsetsMM(new Insets(topValue, leftValue, bottomValue, rightValue));
pd4ml.useTTF("c:/windows/f onts", true);
pd4ml.render(new URL(url), fos);
fos.close();
if (Desktop.isDesktopSupporte d()) {
Desktop.getDesktop().open( output);
} else {
System.out.println("Awt Desktop is not supported!");
}
System.out.println( outputPath + "\ndone." );
}
The statement jt.doConversion("http://pd4ml.com/sample.htm", "D:/pd4ml.pdf");
instead of "http://pd4ml.com/sample.htm" i have to pass dynamic page url and if page is converted into pdf format so that pdf file should be in same format.
Thanks
I have a jsp page containing a dynamic report with images. Which is producing the data from the database. I want an option in jsp page "Save as pdf" so that entire page should be saved as pdf format.
I am using http://www.pd4ml.com/examples.htm
The code where i need to pass the dynamic page name or url mapping is......
public static void main(String[] args) {
try {
PdfViewerStarter jt = new PdfViewerStarter();
jt.doConversion("http://pd4ml.com/sample.htm", "D:/pd4ml.pdf");
} catch (Exception e) {
e.printStackTrace();
}
}
public void doConversion( String url, String outputPath )
throws InvalidParameterException,
File output = new File(outputPath);
java.io.FileOutputStream fos = new java.io.FileOutputStream(o
PD4ML pd4ml = new PD4ML();
pd4ml.setHtmlWidth(userSpa
pd4ml.setPageSize(pd4ml.ch
pd4ml.setPageInsetsMM(new Insets(topValue, leftValue, bottomValue, rightValue));
pd4ml.useTTF("c:/windows/f
pd4ml.render(new URL(url), fos);
fos.close();
if (Desktop.isDesktopSupporte
Desktop.getDesktop().open(
} else {
System.out.println("Awt Desktop is not supported!");
}
System.out.println( outputPath + "\ndone." );
}
The statement jt.doConversion("http://pd4ml.com/sample.htm", "D:/pd4ml.pdf");
instead of "http://pd4ml.com/sample.htm" i have to pass dynamic page url and if page is converted into pdf format so that pdf file should be in same format.
Thanks
What is your question?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.