首页 > 应用开发 > IT综合 > 使用JDOM处理XML数据之PDF篇(二) (转)
XML文件的代码和microsoft-com:Office:office" />
.NET/Develop/read_article.ASP?id=20733">http://www.csdn.net/Develop/read_article.asp?id=20733 相同
格式转换的xslT-FO文件的代码如下:
watchlist.pdf.xsl
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format" > <!-- defines page layout --> page-height="29.7cm" page-width="21cm" margin-top="1.5cm" margin-bottom="2cm" margin-left="2.5cm" margin-right="2.5cm"> <!-- defines the content --> font-size="10pt" font-family="serif" line-height="14pt" > Watch List - Customer # font-family="sans-serif" font-weight="bold" line-height="26pt" space-after.optimum="12pt" background-color="blue" color="white" text-align="center"> Your Stock Watch List font-family="sans-serif" font-weight="bold" line-height="18pt" space-after.optimum="10pt" start-indent="10pt"> Hello, font-family="sans-serif" font-style="italic" line-height="18pt" space-after.optimum="10pt" start-indent="15pt"> Prices were obtained at line-height="14pt" font-family="sans-serif"> line-height="16pt" font-family="sans-serif"> $
pdfWriter.jsp
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="org.jdom.*" %>
<%@ page import="org.jdom.output.*" %>
<%@ page import="org.jdom.input.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="XML.*" %>
<%
String aa=getservletContext().getRealPath("/")+"J2EE_xml";
String fileName="watchlist.xml";
String trace=aa+fileName;
String styleName="watchlist.pdf.xsl";
String styleTrace=aa+styleName;
String resultName="aa.pdf";
String resultTrace=aa+resultName;
XML.PDFWriter PDFWriter = new XML.PDFWriter();
try {
PDFWriter.createPDFFromXML(styleTrace,trace, resultTrace);
} catch (Exception e) {
System.out.println(e.getMessage());
}
%>
aa.pdf就是格式化后的结果。
到现在使用XML数据的三种方式都介绍过了:
直接读取:http://www.csdn.net/Develop/read_article.asp?id=20720
使用XSLT转化成HTML:http://www.csdn.net/Develop/read_article.asp?id=20733
和这篇里介绍的使用XSL-FO转化成二进制格式。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10752019/viewspace-984953/ ,如需转载,请注明出处,否则将追究法律责任。