Springmvc-pdf
提供:Dev Guides
Spring MVC-PDFの生成の例
次の例は、Spring Web MVCフレームワークを使用してPDFを生成する方法を示しています。 まず、動作するEclipse IDEを用意し、次の手順に従って、Spring Web Frameworkを使用して動的フォームベースのWebアプリケーションを開発します。
Step | Description |
---|---|
1 | Create a project with a name TestWeb under a package com.finddevguides as explained in the Spring MVC - Hello World chapter. |
2 | Create Java classes UserPDFView and PDFController under the com.finddevguides package. |
3 | Download the iText library − iText from the maven repository page. Put it in your CLASSPATH. |
4 | The final step is to create the content of the source and configuration files and export the application as explained below. |
PDFController.java
UserExcelView.java
TestWeb-servlet.xml
views.xml
ここでは、PDFControllerとUserPDFViewを作成しました。 iTextライブラリはPDFファイル形式を処理し、データをPDFドキュメントに変換します。
ソースファイルと構成ファイルの作成が完了したら、アプリケーションをエクスポートします。 アプリケーションを右クリックし、[エクスポート]→[WARファイル]オプションを使用して、 TestWeb.war ファイルをTomcatのwebappsフォルダーに保存します。
次に、Tomcatサーバーを起動し、標準ブラウザーを使用してwebappsフォルダーから他のWebページにアクセスできることを確認します。 また、次のURLを試すこともできます- http://localhost:8080/TestWeb/pdf 。すべてが計画どおりに進んだ場合、次の画面が表示されます。