// 下階層用テンプレート #topicpath ---- //ここにコンテンツを記述します。 まだ書き途中!! ***OpenOffice.orgサーバを起動 [#vb286280] Windows: > cd [OOo_DIR]/program >soffice -accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager Linux: /opt/openoffice.org2.0/program/soffice -accept="socket,port=8100;urp;StarOffice.ServiceManager" -display :1.0 ***Servletのソースコード [#w5a57884] package nu.mine.kino.servlets; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.joott.uno.DocumentConverter; import net.sf.joott.uno.DocumentConverterFactory; import net.sf.joott.uno.DocumentFormat; /** * Servlet implementation class for Servlet: PDFServlet * * @web.servlet name = "PDFServlet" * @web.servlet-mapping url-pattern = "/PDFServlet" * */ public class PDFServlet extends HttpServlet { /* * (non-Java-doc) * * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, * HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("Servlet.Start."); String fileName = request.getParameter("file"); try { // テンプレートとなるSXWファイルのパスを取得し、ファイルを読み込みます。 String inputPath = this.getServletContext().getRealPath( "/WEB-INF/" + fileName); System.out.println(inputPath); File inputFile = new File(inputPath); // 出力ファイルを作成します。 String outputPath0 = "/WEB-INF/output.pdf" + Thread.currentThread().getId(); String outputPath = getServletContext().getRealPath(outputPath0); File outputFile = new File(outputPath); System.out.println(outputPath); DocumentConverter converter = DocumentConverterFactory .getConverter(); try { // 変換を実行します。 converter.convert(inputFile, outputFile, DocumentFormat.PDF_WRITER); } catch (IOException e) { e.printStackTrace(); } response.setHeader("Cache-Control", ""); response.setHeader("Pragma", ""); response.setContentType(DocumentFormat.PDF_WRITER.getMimeType()); FileInputStream in = new FileInputStream(outputFile); OutputStream os = response.getOutputStream(); byte[] buffer = new byte[2048]; int bytes; while ((bytes = in.read(buffer, 0, 2048)) != -1) { os.write(buffer, 0, bytes); } in.close(); os.close(); outputFile.delete(); } catch (Exception e) { e.printStackTrace(); } System.out.println("Servlet.End."); } } また、必要なlibは以下の感じ。 dom4j-1.4.jar jooconverter.jar jootemplates.jar juh.jar jurt.jar ognl-2.6.5.jar ridl.jar sandbox.jar unoil.jar xerces-2.6.2.jar xstream-1.0.1.jar 参考~ -[[Javaを利用してドキュメントをプログラムから操作する:http://oooug.jp/mirror/documents/tips/java_sample.html]] ---- この記事は #vote(おもしろかった,そうでもない) -フォントについて。フォントは基本的に、埋め込みになってしまうみたい。 -- [[きの]] &new{2006-08-20 23:36:45 (日)}; -なのでMS*のフォントはLinuxにないから、他のフォントに置き換えられてPDFにうめこまれてしまう。キレイに出すにはIPAフォントをインストールしておくことだなあ。 -- [[きの]] &new{2006-08-20 23:37:37 (日)}; -置き換えられるフォントは設定可能。場所はウィンドウ>>オプションの、OpenOffice.org>>フォントで、設定できる。これがPDF出力時にも参照されるようだ。 -- [[きの]] &new{2006-08-20 23:39:42 (日)}; -さらに、デフォルトのフォントについては、オプションの、OpenOffice.org Writer>>既定のフォント(アジア諸国語)で変更可能。。これでOKか。。 -- [[きの]] &new{2006-08-21 18:58:11 (月)}; #comment #topicpath SIZE(10){現在のアクセス:&counter;}