XSL FO表中的粗边线问题-使用Apache FOP创建PDF [英] Thick border line issue in XSL FO Table - PDF Creation Using Apache FOP
本文介绍了XSL FO表中的粗边线问题-使用Apache FOP创建PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
border-style="none"
设置为fo:table-column
或fo:table-row
,但当我尝试时,
它要么在行中创建黑线(如果我隐藏列线)
或在列的"%s"中创建黑线(如果我隐藏行线)。
如果隐藏列行:
如果行行隐藏:
我的XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="pages">
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="simple"
page-height="8.5in" page-width="11in" margin-top=".5in"
margin-bottom=".5in" margin-left=".5in" margin-right=".5in">
<fo:region-body margin-top="2cm" margin-bottom="2cm" />
<fo:region-before extent="2cm" overflow="hidden" />
<fo:region-after extent="1cm" overflow="hidden" />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="simple"
initial-page-number="1">
<fo:static-content flow-name="xsl-region-before">
<fo:block font-size="13.0pt" font-family="serif"
padding-after="2.0pt" space-before="4.0pt" text-align="center"
border-bottom-style="solid" border-bottom-width="1.0pt">
<fo:block>IF COLUMN LINES HIDED</fo:block>
</fo:block>
</fo:static-content>
<fo:static-content flow-name="xsl-region-after">
<fo:block font-size="12.0pt" font-family="sans-serif"
padding-after="2.0pt" space-before="2.0pt" text-align="center"
border-top-style="solid" border-bottom-width="1.0pt">
<xsl:text>Page</xsl:text>
<fo:page-number />
</fo:block>
</fo:static-content>
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates select="page-body" />
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="page-body">
<fo:block text-align="center" break-before="page">
<fo:table table-layout="fixed" width="100%"
border-style="solid">
<fo:table-column border-style="solid"/>
<fo:table-column border-style="solid"/>
<fo:table-column border-style="solid"/>
<!-- For hiding column lines -->
<!-- <fo:table-column border-style="none"/> -->
<!-- <fo:table-column border-style="none"/> -->
<!-- <fo:table-column border-style="none"/> -->
<fo:table-header>
<xsl:apply-templates select="table-header" />
</fo:table-header>
<fo:table-body>
<xsl:apply-templates select="table-data" />
</fo:table-body>
</fo:table>
</fo:block>
</xsl:template>
<xsl:template match="table-header">
<fo:table-row keep-together.within-page="always"
border-style="solid">
<fo:table-cell>
<fo:block font-size="10pt" font-family="sans-serif"
padding-top="3pt">
<xsl:value-of select="column-one"></xsl:value-of>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-size="10pt" font-family="sans-serif"
padding-top="3pt">
<xsl:value-of select="column-two"></xsl:value-of>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-size="10pt" font-family="sans-serif"
padding-top="3pt">
<xsl:value-of select="column-three"></xsl:value-of>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
<xsl:template match="table-data">
<fo:table-row keep-together.within-page="always"
border-style="none">
<!-- For showing row lines -->
<!-- <fo:table-row keep-together.within-page="always" -->
<!-- border-style="solid"> -->
<fo:table-cell>
<fo:block font-size="10pt" font-family="sans-serif"
padding-top="3pt">
<xsl:value-of select="column-one"></xsl:value-of>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-size="10pt" font-family="sans-serif"
padding-top="3pt">
<xsl:if test="number(column-two) = number(column-two)">
<xsl:value-of select="format-number(translate(column-two, ',','.'), '#,###.##')"></xsl:value-of>
</xsl:if>
</fo:block>
</fo:table-cell>
<fo:table-cell>
<fo:block font-size="10pt" font-family="sans-serif"
padding-top="3pt">
<xsl:value-of select="column-three"></xsl:value-of>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
我的XML:
<?xml version="1.0" encoding="UTF-8"?>
<pages>
<page-body>
<table-header>
<column-one>Column One</column-one>
<column-two>Column Two</column-two>
<column-three>Column Three</column-three>
</table-header>
<table-data>
<column-one>One</column-one>
<column-two>5000</column-two>
<column-three>Three</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>5000</column-two>
<column-three>Three</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>0</column-two>
<column-three>Three</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>0</column-two>
<column-three>Four</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>2000</column-two>
<column-three>Four</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>1234</column-two>
<column-three>Five</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>5666</column-two>
<column-three>Five</column-three>
</table-data>
<table-data>
<column-one>One</column-one>
<column-two>5666</column-two>
<column-three>Five</column-three>
</table-data>
</page-body>
</pages>
我正在使用这些XML和XSL文件通过Apache fop生成PDF,我的代码中有什么问题吗?
推荐答案
不幸的是,在涉及FOP呈现的FO开发中,这种事情时有发生。
有关您的答案,请参阅Section 6.9 of xmlgraphics.apache.org's FAQ re anti-aliasing and Acrobat。
请注意,如果您在Acrobat中使用缩放因子,问题将消失/重新出现,具体取决于设置。
还请注意,如果您使用RenderX(也称为XEP)尝试您的示例,则不会发生这种情况。他们显然已经解决了(或者从来没有)这个问题。试图通过非商业FO产品逍遥法外的危险之一。(当然,并不是说某种东西必须是商业的才是好的,只是商业FO处理器比FOP更好、更强大的事实,尽管FOP正在改进,尽管速度很慢。)
如果您必须继续使用FOP,请确保您使用的是最新版本(请参阅pin)。2.4将带来一些重要好处。附录(SVG的用法):
您可以通过动态内置的SVG标记来避免这种FOP错误。
以下是使用此方法获取PDF表格所需生成的标记类型的示例:
<fo:instream-foreign-object>
<svg:svg width="1000%" height="1000%">
<svg:g id='rowGroup' transform='translate(0, 0)' role="table">
<svg:text x='30' y='30' font-size='18px' font-weight='bold' fill='crimson' text-anchor='middle' role="row">
<svg:tspan role="columnheader" x='100'>Sales</svg:tspan>
<svg:tspan role="columnheader" x='200'>Expenses</svg:tspan>
<svg:tspan role="columnheader" x='300'>Net</svg:tspan>
</svg:text>
<svg:rect x='30' y='40' width='310' height='1' fill='black'/>
<svg:text x='30' y='30' font-size='18px' text-anchor='middle' role="row">
<svg:tspan id="q1" role="rowheader" x='30' dy='1.5em' font-weight='bold' fill='crimson' text-anchor='start'>Q1</svg:tspan>
<svg:tspan role="cell" x='100'>$223</svg:tspan>
<svg:tspan role="cell" x='200'>$195</svg:tspan>
<svg:tspan role="cell" x='300'>$28</svg:tspan>
</svg:text>
<svg:rect x='30' y='60' width='310' height='1' fill='black'/>
<svg:text x='30' y='50' font-size='18px' text-anchor='middle' role="row">
<svg:tspan id="q2" role="rowheader" x='30' dy='1.5em' font-weight='bold' fill='crimson' text-anchor='start'>Q2</svg:tspan>
<svg:tspan role="cell" x='100'>$295</svg:tspan>
<svg:tspan role="cell" x='200'>$263</svg:tspan>
<svg:tspan role="cell" x='300'>$32</svg:tspan>
</svg:text>
<svg:rect x='30' y='80' width='310' height='1' fill='black'/>
<svg:text x='30' y='70' font-size='18px' text-anchor='middle' role="row">
<svg:tspan id="q3" role="rowheader" x='30' dy='1.5em' font-weight='bold' fill='crimson' text-anchor='start'>Q3</svg:tspan>
<svg:tspan role="cell" x='100'>$951</svg:tspan>
<svg:tspan role="cell" x='200'>$232</svg:tspan>
<svg:tspan role="cell" x='300'>$719</svg:tspan>
</svg:text>
<svg:rect x='30' y='100' width='310' height='1' fill='black'/>
<svg:text x='30' y='90' font-size='18px' text-anchor='middle' role="row">
<svg:tspan id="q4" role="rowheader" x='30' dy='1.5em' font-weight='bold' fill='crimson' text-anchor='start'>Q4</svg:tspan>
<svg:tspan role="cell" x='100'>$823</svg:tspan>
<svg:tspan role="cell" x='200'>$175</svg:tspan>
<svg:tspan role="cell" x='300'>$648</svg:tspan>
</svg:text>
<svg:rect x='30' y='120' width='310' height='1' fill='black'/>
</svg:g>
</svg:svg>
</fo:instream-foreign-object>
我将为您的特定案例动态化FO创建,但这应该会教您如何以这种方式生成表。
通过将边框绘制为SVG多边形,您可以轻松地获得所需的效果,这就是Kevin使用本文的目的(尽管我相信他指的是RenderX引擎中的代码)。我的解决方案通过嵌入式SVG创建将其具体化。)当然,<svg:rect>
标记是多边形的一种形式,您可以使用它来呈现边框。
如果要尝试此操作,请记住在<xsl:stylesheet>
标记上指定SVG命名空间。
xmlns:svg="http://www.w3.org/2000/svg"
这篇关于XSL FO表中的粗边线问题-使用Apache FOP创建PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文