データベースからデータを生成する、画像付きの動的レポートを含む jsp ページがあります。Save as PDFページ全体を PDF 形式で保存するように、jsp ページにオプションが必要です。
PD4ML コンバーターを使用しています。
動的なページ名または URL マッピングを渡す必要があるコードは次のとおりです。
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.");
}
ステートメント内ではjt.doConversion("http://pd4ml.com/sample.htm", "D:/pd4ml.pdf");
、代わりに"http://pd4ml.com/sample.htm"
動的ページ URL を渡す必要があり、ページが PDF 形式に変換される場合は、PDF ファイルが同じ形式である必要があります。