i am trying to hide fo:table row or column lines based on the requirement from web application, so i used to set border-style="none"
to fo:table-column
or fo:table-row
based on the need, but when i tried it,
either it creates dark lines in row's (if i hide column lines)
or creates dark lines in column's (if i hide row lines).
If column lines get hidden:
If row lines get hidden:
MY 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>
MY 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>
I am using these xml and xsl files to generate PDF using apache fop, Is there any problem in my code?
Unfortunately, this sort of thing crops up from time to time in FO development involving FOP rendering.
For your answer, please see Section 6.9 of xmlgraphics.apache.org's FAQ re anti-aliasing and Acrobat.
Notice that if you play with the zoom factor in Acrobat, the problem will disappear/reappear depending on the setting.
Also note that if you try your example with RenderX (a.k.a XEP), this won't happen. They've apparently figured out (or never had) the problem.
One of the perils of trying to get away with a non-commercial FO product. (Not that something has to be commercial to be good, of course, but it's just fact that commercial FO processors are better and more powerful than FOP, though FOP is improving, albeit slowly.)
If you have to continue using FOP, make sure you're on the latest version (see this pin). Some important benefit to be had with 2.4.
You can avoid this FOP bugginess by dynamically-built-out SVG markup.
Here's an example of the kind of markup you'd have to generate to get a PDF table by this method:
<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>
I leave it to you to dynamicize the FO creation for your particular case, but this ought to teach you how to build tables this way.
You can easily achieve the effects you desire by drawing the borders as SVG polygons, which is where Kevin was going with this (although I believe he was speaking of the code inside the RenderX engine. My solution externalizes that via embedded SVG creation.) Of course, the <svg:rect>
tag is a form of polygon, and that's what you'd use to render borders.
Remember to specify the SVG namespace on your <xsl:stylesheet>
tag if you're going to attempt this.
xmlns:svg="http://www.w3.org/2000/svg"