Use JDOM to handle the PDF (2)
XML file code and
http://www.9cbs.net/develop/read_article.asp?id=20733
The code for the XSLT-FO file of the format is as follows:
Watchlist.pdf.xsl
XML Version = "1.0"?>
XMLns: XSL = "http://www.w3.org/1999/xsl/transform" Version = "1.0" XMLns: fo = "http://www.w3.org/1999/xsl/format" > Page-heiGHT = "29.7cm" Page-width = "21cm" Margin-top = "1.5cm" Margin-bottom = "2cm" Margin-left = "2.5cm" Margin-right = "2.5cm"> fo: Simple-Page-Master> fo: layout-master-set> Font-size = "10pt" Font-family = "serif" Line-height = "14pt"> Watch List - Customer # fo: block> fo: static-content> 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 fo: block> Font-family = "sans-serif" Font-weight = "bold" Line-height = "18pt" Space -After.optimumum = "10pt" START-Indent = "10pt"> Hello, fo: block> Font-family = "sans-serif" Font-style = "italic" Line-height = "18pt" Space -After.optimumum = "10pt" START-Indent = "15pt"> Prices were obtained at fo: block> Line-height = "14pt" Font-family = "Sans-Serif"> fo: Table-Cell> fo: Table-Cell> fo: Table-Cell> fo: Table-Row> fo: Table-Header> Line-height = "16pt" Font-family = "sans-serif"> fo: block> fo: Table-Cell> fo: block> fo: Table-Cell> $ fo: block> fo: Table-Cell> fo: Table-Row> xsl: for-energy> fo: Table-Body> fo: Table> fo: flow> fo: Page-Sequence> fo: root> xsl: template> xsl: stylesheet> Finally, we call this Javabean in a JSP file: 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 is the result of formatting. In three ways to use XML data now: Read directly: http://www.9cbs.net/develop/read_article.asp? Id = 20720 Translate into HTML using XSLT: http://www.9cbs.net/develop/read_article.asp? Id = 20733 And the use of XSL-FO is converted into a binary format.