使用JDOM處理XML資料之PDF篇(二) (轉)

amyz發表於2007-11-26
使用JDOM處理XML資料之PDF篇(二) (轉)[@more@]  使用J處理資料之PDF篇(二)

XML的程式碼和microsoft-com::office" />

/Develop/read_article.?id=20733"> 相同

格式轉換的T-FO檔案的程式碼如下:

watchlist.pdf.xsl

  xmlns:xsl=""

  version="1.0"

  xmlns:fo=""

>

 

  <!-- defines page layout --&gt

   

   

      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 --&gt

   

   

     

      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 on

   

   

   

   

   

     

    line-height="14pt"

    font-family="sans-serif">

     

       

        SYMBOL

       

       

        COMPANY NAME

       

       

        SHARE PRICE

       

       

     

   

    line-height="16pt"

    font-family="sans-serif">

   

     

     

     

     

     

     

     

     

     

     

     

     

     

    $

     

     

     

   

   

     

   

   

 

最後我們在一個檔案中來這個bean:

pdfWriter.jsp

  String aa=getContext().getRealPath("/")+"_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資料的三種方式都介紹過了:

直接讀取:

使用XSLT轉化成HTML:

和這篇裡介紹的使用XSL-FO轉化成二進位制格式。


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752019/viewspace-984953/,如需轉載,請註明出處,否則將追究法律責任。

相關文章