Link to home
Create AccountLog in
Avatar of OTSSolutions
OTSSolutionsFlag for India

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(output);  
 
            PD4ML pd4ml = new PD4ML();  
            pd4ml.setHtmlWidth(userSpaceWidth);  
            pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.A4));  
            pd4ml.setPageInsetsMM(new Insets(topValue, leftValue, bottomValue, rightValue));  
            pd4ml.useTTF("c:/windows/fonts", true);  
 
            pd4ml.render(new URL(url), fos);  
            fos.close();  
 
            if (Desktop.isDesktopSupported()) {  
                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
Avatar of mrcoffee365
mrcoffee365
Flag of United States of America image

What is your question?
ASKER CERTIFIED SOLUTION
Avatar of Am P
Am P
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer