xml转换成PDF的一些思路及方法请教
用C#语言开发,希望能提一些原理或思路,以及开发过程中要用到的一些资源,有源码能提供的最好.这关系到小弟我的毕业问题,我将大力散分啊.
[解决办法]
用Ghostscript好像可以,具体没做过,跟你一起问。
[解决办法]
没具体做 不过 思路上
应该是 将xml 导入 为 word
然后 将word转换为 pdf
Word转换PDF格式
http://blog.csdn.net/lybid2002/articles/491441.aspx
[解决办法]
不知道你到底要做什么?打印出来?
我就会activereport
[解决办法]
xml就是数据源了.弄个pdf报表.看你用什么报表了.其他的没用过,只熟悉activereport
[解决办法]
二. 从XML到PDF
对于一个具有一定模板性质的XML文件,我们可以用FOP API来实现其到PDF的转换.
FOP需要fop.jar. 我们可以到http://xml.apache.org/fop/ 上获取和了解其用法.
以一个一般复杂的XML文件为例:
要转换XML文档 test.xml 如下:
<FeatureSRS title= "SRS ">
<introduction>
<objective> objective here </objective>
<scope> scope here </scope>
<responsibilities> responsibilities here </responsibilities>
<references> reference here </references>
<DAA>
<term>
term here
</term>
<definition>
definition here
</definition>
</DAA>
</introduction>
<generalDescription>
<featureName>
<summary> summary here </summary>
<breakdown> breakdown here </breakdown>
</featureName>
<requirement>
<content>
content here.
</content>
</requirement>
<requirement>
<content>
content2 here.
</content>
</requirement>
<featureInteractions> featureInteractions here </featureInteractions>
</generalDescription>
<strResources>
<strResource>
<estring>
estring here
</estring>
<resourceid>
resourceid here
</resourceid>
<rqmt>
rqmt here.
</rqmt>
</strResource>
</strResources>
</FeatureSRS>
对于这样一个XML文档,我们要将其转化成PDF格式必须建立一个XSL-FO文件,来定义对各element和value格
式的转换.
[解决办法]
我们建立XSL-FO文件 test.xsl 如下:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<xsl:stylesheet version= "1.1 " xmlns:xsl= "http://www.w3.org/1999/XSL/Transform " xmlns:fo= "http://www.w3.org/1999/XSL/Format " exclude-result-prefixes= "fo ">
<xsl:output method= "xml " version= "1.0 " omit-xml-declaration= "no " indent= "yes "/>
<!-- ========================= -->
<!-- root element: projectteam -->
<!-- ========================= -->
<xsl:template match= "FeatureSRS ">
<fo:root xmlns:fo= "http://www.w3.org/1999/XSL/Format ">
<fo:layout-master-set>
<fo:simple-page-master master-name= "simpleA4 " page-height= "29.7cm " page-width= "21cm " margin-top= "2cm " margin-bottom= "2cm " margin-left= "2cm " margin-right= "2cm ">
<fo:region-body/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference= "simpleA4 ">
<fo:flow flow-name= "xsl-region-body ">
<fo:block font-size= "20pt " font-weight= "bold " space-after= "5mm " text-align= "center "> Cardiac Feature SRS
</fo:block>
<fo:block font-size= "10pt ">
<xsl:apply-templates/>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<!-- ========================= -->
<!-- child element: member -->
<!-- ========================= -->
<xsl:template name= "introduction " match= "introduction ">
<fo:block font-size= "18pt " font-weight= "bold " space-after= "5mm "> 1. Intruction </fo:block>
<fo:block font-size= "14pt " font-weight= "bold " space-after= "5mm " margin-left= "5mm "> 1.1 Objective </fo:block>
<fo:block font-size= "10pt " font-weight= "normal " space-after= "5mm " margin-left= "7mm ">
<xsl:value-of select= "objective "/>
</fo:block>
<fo:block font-size= "14pt " font-weight= "bold " space-after= "5mm " margin-left= "5mm "> 1.2 Scope </fo:block>
<fo:block font-size= "10pt " font-weight= "normal " space-after= "5mm " margin-left= "7mm ">
<xsl:value-of select= "scope "/>
</fo:block>
<fo:block font-size= "14pt " font-weight= "bold " space-after= "5mm " margin-left= "5mm "> 1.3. Responsibilities </fo:block>
<fo:block font-size= "10pt " font-weight= "normal " space-after= "5mm " margin-left= "7mm ">
<xsl:value-of select= "responsibilities "/>
</fo:block>
<fo:block font-size= "14pt " font-weight= "bold " space-after= "5mm " margin-left= "5mm "> 1.4. References </fo:block>
<fo:block font-size= "10pt " font-weight= "normal " space-after= "5mm " margin-left= "7mm ">
<xsl:value-of select= "references "/>
</fo:block>
<fo:block font-size= "14pt " font-weight= "bold " space-after= "5mm " margin-left= "5mm "> 1.5. Definitions, Acronyms, and Abbreviations </fo:block>
<fo:block font-size= "10pt " font-weight= "bold " space-after= "5mm " margin-left= "5mm ">
<fo:table table-layout= "fixed " border= "2cm " background-color= "#fff2d9 " >
<fo:table-column column-width= "4cm "/>
<fo:table-column column-width= "6cm "/>
<fo:table-body>
<fo:table-row border= "2 ">
<fo:table-cell>
<fo:block>
<xsl:text> Term </xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:text> Definition </xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
<xsl:for-each select= "DAA ">
<fo:table-row border= "2 ">
<fo:table-cell>
<fo:block>
<xsl:value-of select= "term "/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select= "definition "/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block>
</xsl:template>
<xsl:template name= "generalDescription " match= "generalDescription ">
<fo:block font-size= "18pt " font-weight= "bold " space-after= "5mm "> 2. General Description </fo:block>
<fo:block font-size= "14pt " font-weight= "bold " space-after= "5mm " margin-left= "5mm "> 2.1. Feature Name </fo:block>
<fo:block font-size= "14pt " font-weight= "bold " space-after= "5mm " margin-left= "7mm "> 2.1.1. Feature Summary </fo:block>
<fo:block font-size= "10pt " font-weight= "normal " space-after= "5mm " margin-left= "9mm ">
<xsl:value-of select= "featureName/summary "/>
</fo:block>
<fo:block font-size= "14pt " font-weight= "bold " space-after= "5mm " margin-left= "7mm "> 2.1.2. Feature Breakdown </fo:block>
<fo:block font-size= "10pt " font-weight= "normal " space-after= "5mm " margin-left= "9mm ">
<xsl:value-of select= "featureName/breakdown "/>
</fo:block>
<fo:block font-size= "14pt " font-weight= "bold " space-after= "5mm " margin-left= "5mm "> 2.2. Feature Requirements </fo:block>
<fo:block font-size= "10pt " font-weight= "normal " space-after= "5mm " margin-left= "7mm ">
<xsl:for-each select= "requirement ">
<xsl:value-of select= "content "/>
</xsl:for-each>
</fo:block>
<fo:block font-size= "14pt " font-weight= "bold " space-after= "5mm " margin-left= "5mm "> 2.3. Feature Interactions </fo:block>
<fo:block font-size= "10pt " font-weight= "normal " space-after= "5mm " margin-left= "7mm ">
<xsl:value-of select= "featureInteractions "/>
</fo:block>
</xsl:template>
<xsl:template name= "strResources " match= "strResources ">
<fo:block font-size= "18pt " font-weight= "bold " space-after= "5mm "> 3. String Resources </fo:block>
<fo:block font-size= "10pt " font-weight= "bold " space-after= "5mm " margin-left= "5mm ">
<fo:table table-layout= "fixed " border= "2cm " background-color= "#fff2d9 " >
<fo:table-column column-width= "4cm "/>
<fo:table-column column-width= "10cm "/>
<fo:table-column column-width= "4cm "/>
<fo:table-body>
<fo:table-row border= "2 ">
<fo:table-cell>
<fo:block>
<xsl:text> English String </xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:text> Resource ID </xsl:text>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:text> Rqmt </xsl:text>
</fo:block>
</fo:table-cell>
</fo:table-row>
<xsl:for-each select= "strResource ">
<fo:table-row border= "2 ">
<fo:table-cell>
<fo:block>
<xsl:value-of select= "estring "/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select= "resourceid "/>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block>
<xsl:value-of select= "rqmt "/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body>
</fo:table>
</fo:block>
</xsl:template>
</xsl:stylesheet>
[解决办法]
http://www-128.ibm.com/developerworks/tw/views/xml/tutorials.jsp?cv_doc_id=18840
[解决办法]
http://blog.donews.com/limodou/archive/2004/04/01/9917.aspx