Use JDOM to handle the PDF (2)

zhaozj2021-02-17  52

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

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">

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.optimumum = "10pt"

START-Indent = "10pt">

Hello,

Font-family = "sans-serif"

Font-style = "italic"

Line-height = "18pt"

Space -After.optimumum = "10pt"

START-Indent = "15pt">

Prices were obtained at on

Line-height = "14pt"

Font-family = "Sans-Serif">

Symbol

Company name

Share Price

Line-height = "16pt"

Font-family = "sans-serif">

$

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.

转载请注明原文地址:https://www.9cbs.com/read-29775.html

New Post(0)