Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt XSL FO表格中的粗边框问题-使用ApacheFop创建PDF_Xslt_Pdf Generation_Xslt 1.0_Xsl Fo_Apache Fop - Fatal编程技术网

Xslt XSL FO表格中的粗边框问题-使用ApacheFop创建PDF

Xslt XSL FO表格中的粗边框问题-使用ApacheFop创建PDF,xslt,pdf-generation,xslt-1.0,xsl-fo,apache-fop,Xslt,Pdf Generation,Xslt 1.0,Xsl Fo,Apache Fop,我正试图根据web应用程序的要求隐藏fo:table行或列行,因此我曾根据需要将border style=“none”设置为fo:table column或fo:table row,但当我尝试时, 或者在行中创建暗线(如果我隐藏列线) 或者在列中创建暗线(如果我隐藏行线) 如果柱线被隐藏: 如果行线被隐藏: 我的XSL: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0"

我正试图根据web应用程序的要求隐藏fo:table行或列行,因此我曾根据需要将
border style=“none”
设置为
fo:table column
fo:table row
,但当我尝试时, 或者在行中创建暗线(如果我隐藏列线) 或者在列中创建暗线(如果我隐藏行线)

如果柱线被隐藏:

如果行线被隐藏:

我的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 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:

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

第一栏
第二栏
第三栏
一个
5000
三
一个
5000
三
一个
0
三
一个
0
四
一个
2000
四
一个
1234
五
一个
5666
五
一个
5666
五

我正在使用这些xml和xsl文件使用ApacheFop生成PDF,我的代码中有问题吗?

不幸的是,在涉及fop渲染的FO开发中,这种事情时有发生

有关您的答案,请参阅

请注意,如果在Acrobat中使用缩放因子,问题将根据设置消失/重新出现

另外请注意,如果您使用RenderX(又称XEP)尝试您的示例,则不会发生这种情况。他们显然已经解决了(或者从来没有)这个问题

试图从非商业性FO产品中脱身的风险之一。(当然,并不是说某些东西必须商业化才能好,但事实上,商业化的FO处理器比FOP更好、更强大,尽管FOP正在改善,尽管进展缓慢。)

如果您必须继续使用FOP,请确保您使用的是最新版本(参见此)。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>

查看这个最近合并的补丁(合并的2020-12-29),它似乎为我解决了这个问题:

(PDF输出中不同的表格边框厚度)


修订版1884907:FOP-2536:允许对PDF边框进行过度绘制

技巧隐藏在XSL FO引擎中。为了解决这个问题,你使用多边形而不是线来绘制边界。嗨,凯文。我不熟悉多边形。关于这个的任何链接???@punithanantony,请参阅我上面的附录。如果你觉得有用,请接受我的回答。谢谢。如果这对您有帮助,请您将其标记为已接受的答案好吗?非常感谢。