0

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 in PDF format.

I am using the PD4ML converter.

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.");
}

Within the statement jt.doConversion("http://pd4ml.com/sample.htm", "D:/pd4ml.pdf");, instead of "http://pd4ml.com/sample.htm" I have to pass a dynamic page URL, and if page is converted into PDF format, so that PDF file should be in the same format.

  • 1
    Well, good for you. Any particular questions, or did you just want to share what you're working on? – Carsten Jul 16 '13 at 08:40

0 Answers0