PDF Header alignment

View: New views
5 Messages — Rating Filter:   Alert me  

PDF Header alignment

by Samuel Remacle :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello
 
I'm generating a PDF file with a header, I'd like to put an image at the left of the header and some text at the right of it.
 
I guess I have to use a table to do that, but I can't understand how to align my text in a table cell, because I need to put the image of the first cell on the left and the text of the second cell on the right, but XSL fo seems to have no property to aligne the content of a table cell. Anyway, I tried to put just a table with two cells (not taking care of the alignment) in the header and it doesnt work.
 
My code to put just the image in the header is the following:
 
<?xml version='1.0' encoding='windows-1252'?>
<xsl:stylesheet version="1.0" 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"/>
  <xsl:template match="/">
    <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-left="1cm"
                               margin-right="1cm" margin-top="0.5cm">
          <fo:region-body margin-left="1cm" margin-right="1cm"
                          margin-bottom="1cm" margin-top="2.5cm"/>
          <fo:region-before extent="2cm" display-align="after"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="simpleA4">
        <fo:static-content flow-name="xsl-region-before">
          <fo:block margin-left="1cm" margin-right="1cm"
                    border-bottom-color="silver" border-bottom-style="solid"
                    border-bottom-width="0.5pt">
            <fo:external-graphic src="url('...')"
                                 height="1.8cm" width="3.6cm"/>
          </fo:block>
        </fo:static-content>
        <fo:flow flow-name="xsl-region-body">
          <xsl:call-template name="subElementTemplate"/>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>
  <xsl:template name="subElementTemplate">
    <xsl:param name="fontSize" select="16"/>
    <xsl:param name="textIndent" select="0"/>
    <xsl:for-each select="child::node()">
      <xsl:choose>
        <xsl:when test="child::*/child::node()">
          <xsl:value-of select="'&#x2028;'"/>
          <fo:leader/>
          <fo:block font-size="{concat(string($fontSize), 'pt')}"
                    text-indent="{concat(string($textIndent), 'in')}"
                    font-weight="bold">
            <xsl:value-of select="local-name()"/>
            <xsl:call-template name="subElementTemplate">
              <xsl:with-param name="fontSize" select="$fontSize - 1"/>
              <xsl:with-param name="textIndent" select="$textIndent + 0.1"/>
            </xsl:call-template>
          </fo:block>
        </xsl:when>
        <xsl:otherwise>
          <xsl:if test="position() = 1">
            <xsl:value-of select="'&#x2028;'"/>
            <fo:leader/>
          </xsl:if>
          <fo:block font-size="{concat(string($fontSize), 'pt')}"
                    text-indent="{concat(string($textIndent), 'in')}"
                    font-weight="bold">
            <xsl:value-of select="concat(local-name(), ': ', current()/text())"/>
          </fo:block>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
 
Now here's the code I'm using to put the image and the text (without taking care of the alignment):
 
<?xml version='1.0' encoding='windows-1252'?>
<xsl:stylesheet version="1.0" 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"/>
  <xsl:template match="/">
    <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-left="1cm"
                               margin-right="1cm" margin-top="0.5cm">
          <fo:region-body margin-left="1cm" margin-right="1cm"
                          margin-bottom="1cm" margin-top="2.5cm"/>
          <fo:region-before extent="2cm" display-align="after"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <fo:page-sequence master-reference="simpleA4">
        <fo:static-content flow-name="xsl-region-before">
          <fo:block margin-left="1cm" margin-right="1cm"
                    border-bottom-color="silver" border-bottom-style="solid"
                    border-bottom-width="0.5pt">
            <fo:table table-layout="fixed">
              <fo:table-column column-width="9.5cm"/>
              <fo:table-column column-width="9.5cm"/>
              <fo:table-body>
                <fo:table-row>
                  <fo:table-cell>
                    <fo:external-graphic src="url('...')"
                                         height="1.8cm" width="3.6cm"/>
                  </fo:table-cell>
                  <fo:table-cell>
                    <fo:block>
                      <xsl:value-of select="'Test'"/>
                    </fo:block>
                  </fo:table-cell>
                </fo:table-row>
              </fo:table-body>
            </fo:table>
          </fo:block>
        </fo:static-content>
        <fo:flow flow-name="xsl-region-body">
          <xsl:call-template name="subElementTemplate"/>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
  </xsl:template>
  <xsl:template name="subElementTemplate">
    <xsl:param name="fontSize" select="16"/>
    <xsl:param name="textIndent" select="0"/>
    <xsl:for-each select="child::node()">
      <xsl:choose>
        <xsl:when test="child::*/child::node()">
          <xsl:value-of select="'&#x2028;'"/>
          <fo:leader/>
          <fo:block font-size="{concat(string($fontSize), 'pt')}"
                    text-indent="{concat(string($textIndent), 'in')}"
                    font-weight="bold">
            <xsl:value-of select="local-name()"/>
            <xsl:call-template name="subElementTemplate">
              <xsl:with-param name="fontSize" select="$fontSize - 1"/>
              <xsl:with-param name="textIndent" select="$textIndent + 0.1"/>
            </xsl:call-template>
          </fo:block>
        </xsl:when>
        <xsl:otherwise>
          <xsl:if test="position() = 1">
            <xsl:value-of select="'&#x2028;'"/>
            <fo:leader/>
          </xsl:if>
          <fo:block font-size="{concat(string($fontSize), 'pt')}"
                    text-indent="{concat(string($textIndent), 'in')}"
                    font-weight="bold">
            <xsl:value-of select="concat(local-name(), ': ', current()/text())"/>
          </fo:block>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
 
As you will see in the attached PDF fil the image is no more at the right place, and I get the following message on my console:
 
[WARNING] Some static content could not fit in the area.
 
So, my questions:
 
How can I get the image at the right place?
 
How can I align the text at the right of the document?
 
testPDF.pdf --> only the image
 
test2PDF.pdf --> the image and the text
 
Thanks,
 
Samuel



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@...
For additional commands, e-mail: fop-users-help@...

testPDF.pdf (12K) Download Attachment
test2PDF.pdf (12K) Download Attachment

Re: PDF Header alignment

by JBryant :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

You can set the alignment properties on the blocks within the table cells,
thus:

<fo:table table-layout="fixed">
  <fo:table-column column-width="2in"/>
  <fo:table-column column-width="2.5in"/>
  <fo:table-column column-width="2in"/>
  <fo:table-body>
    <fo:table-row>
      <fo:table-cell>
         <fo:block text-align="left">Left footer stuff here</fo:block>
      </fo:table-cell>
      <fo:table-cell>
         <fo:block text-align="center">Center footer stuff here</fo:block>
      </fo:table-cell>
      <fo:table-cell>
         <fo:block text-align="right">Right footer stuff here</fo:block>
      </fo:table-cell>
    </fo:table-row>
  </fo:table-body>
</fo:table>


The footer definition I actually use for most of the documents for this
client is:

          <fo:table table-layout="fixed">
            <fo:table-column column-width="2in"/>
            <fo:table-column column-width="2.5in"/>
            <fo:table-column column-width="2in"/>
            <fo:table-body>
              <fo:table-row>
                <fo:table-cell>
                  <fo:block xsl:use-attribute-sets="footerleft">
                    Date prepared: <xsl:value-of
select="format-date(current-date(),'[D1] [MNn] [Y0001]')"/>
                  </fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block xsl:use-attribute-sets="footercenter">
                    Confidential and Proprietary
                  </fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block xsl:use-attribute-sets="footerright">
                    <fo:page-number />
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
              <fo:table-row>
                <fo:table-cell number-columns-spanned="3">
                  <fo:block xsl:use-attribute-sets="footercenter">
                    Copyright <xsl:value-of select="$copyrightYears"/>,
<xsl:value-of select="$copyrightOwner"/>. All Rights Reserved
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
            </fo:table-body>
          </fo:table>

Then I define the alignment in the named attribute set (which I keep in a
separate XSL file and import into several kinds of documents).

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@...
For additional commands, e-mail: fop-users-help@...


Re: PDF Header alignment

by sivag_123 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I tried your solution. When we insert the text and image in 2 different blocks, then the image comes to the left and text comes to the center. But they are not inline. I want the image in the left and text in the right in the same line. If you can share some ideas, it would be great.

Thanks and regards,
Sivashankar



JBryant wrote:
You can set the alignment properties on the blocks within the table cells,
thus:

<fo:table table-layout="fixed">
  <fo:table-column column-width="2in"/>
  <fo:table-column column-width="2.5in"/>
  <fo:table-column column-width="2in"/>
  <fo:table-body>
    <fo:table-row>
      <fo:table-cell>
         <fo:block text-align="left">Left footer stuff here</fo:block>
      </fo:table-cell>
      <fo:table-cell>
         <fo:block text-align="center">Center footer stuff here</fo:block>
      </fo:table-cell>
      <fo:table-cell>
         <fo:block text-align="right">Right footer stuff here</fo:block>
      </fo:table-cell>
    </fo:table-row>
  </fo:table-body>
</fo:table>


The footer definition I actually use for most of the documents for this
client is:

          <fo:table table-layout="fixed">
            <fo:table-column column-width="2in"/>
            <fo:table-column column-width="2.5in"/>
            <fo:table-column column-width="2in"/>
            <fo:table-body>
              <fo:table-row>
                <fo:table-cell>
                  <fo:block xsl:use-attribute-sets="footerleft">
                    Date prepared: <xsl:value-of
select="format-date(current-date(),'[D1] [MNn] [Y0001]')"/>
                  </fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block xsl:use-attribute-sets="footercenter">
                    Confidential and Proprietary
                  </fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block xsl:use-attribute-sets="footerright">
                    <fo:page-number />
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
              <fo:table-row>
                <fo:table-cell number-columns-spanned="3">
                  <fo:block xsl:use-attribute-sets="footercenter">
                    Copyright <xsl:value-of select="$copyrightYears"/>,
<xsl:value-of select="$copyrightOwner"/>. All Rights Reserved
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
            </fo:table-body>
          </fo:table>

Then I define the alignment in the named attribute set (which I keep in a
separate XSL file and import into several kinds of documents).

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org

Re: PDF Header alignment

by Jeremias Maerki-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Either use a table with two columns, one left-aligned for the image and
one right aligned for the text.

Or you can do that in one fo:block and set that to
text-align-last="justify" and use an fo:leader for elastic spacing.

On 22.10.2009 09:17:12 sivag_123 wrote:

>
> Hi,
>
> I tried your solution. When we insert the text and image in 2 different
> blocks, then the image comes to the left and text comes to the center. But
> they are not inline. I want the image in the left and text in the right in
> the same line. If you can share some ideas, it would be great.
>
> Thanks and regards,
> Sivashankar
>
>
>
>
> JBryant wrote:
> >
> > You can set the alignment properties on the blocks within the table cells,
> > thus:
> >
> > <fo:table table-layout="fixed">
> >   <fo:table-column column-width="2in"/>
> >   <fo:table-column column-width="2.5in"/>
> >   <fo:table-column column-width="2in"/>
> >   <fo:table-body>
> >     <fo:table-row>
> >       <fo:table-cell>
> >          <fo:block text-align="left">Left footer stuff here</fo:block>
> >       </fo:table-cell>
> >       <fo:table-cell>
> >          <fo:block text-align="center">Center footer stuff here</fo:block>
> >       </fo:table-cell>
> >       <fo:table-cell>
> >          <fo:block text-align="right">Right footer stuff here</fo:block>
> >       </fo:table-cell>
> >     </fo:table-row>
> >   </fo:table-body>
> > </fo:table>
> >
> >
> > The footer definition I actually use for most of the documents for this
> > client is:
> >
> >           <fo:table table-layout="fixed">
> >             <fo:table-column column-width="2in"/>
> >             <fo:table-column column-width="2.5in"/>
> >             <fo:table-column column-width="2in"/>
> >             <fo:table-body>
> >               <fo:table-row>
> >                 <fo:table-cell>
> >                   <fo:block xsl:use-attribute-sets="footerleft">
> >                     Date prepared: <xsl:value-of
> > select="format-date(current-date(),'[D1] [MNn] [Y0001]')"/>
> >                   </fo:block>
> >                 </fo:table-cell>
> >                 <fo:table-cell>
> >                   <fo:block xsl:use-attribute-sets="footercenter">
> >                     Confidential and Proprietary
> >                   </fo:block>
> >                 </fo:table-cell>
> >                 <fo:table-cell>
> >                   <fo:block xsl:use-attribute-sets="footerright">
> >                     <fo:page-number />
> >                   </fo:block>
> >                 </fo:table-cell>
> >               </fo:table-row>
> >               <fo:table-row>
> >                 <fo:table-cell number-columns-spanned="3">
> >                   <fo:block xsl:use-attribute-sets="footercenter">
> >                     Copyright <xsl:value-of select="$copyrightYears"/>,
> > <xsl:value-of select="$copyrightOwner"/>. All Rights Reserved
> >                   </fo:block>
> >                 </fo:table-cell>
> >               </fo:table-row>
> >             </fo:table-body>
> >           </fo:table>
> >
> > Then I define the alignment in the named attribute set (which I keep in a
> > separate XSL file and import into several kinds of documents).
> >
> > Jay Bryant
> > Bryant Communication Services
> > (presently consulting at Synergistic Solution Technologies)
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-users-unsubscribe@...
> > For additional commands, e-mail: fop-users-help@...
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/PDF-Header-alignment-tp445298p26005134.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
>
>



Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@...
For additional commands, e-mail: fop-users-help@...


Re: PDF Header alignment

by sivag_123 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Jeremias,

I used the fo:leader tag and it works. Thanks a lot for ur suggestion.

Thanks and regards,
Sivashankar

Jeremias Maerki-2 wrote:
Either use a table with two columns, one left-aligned for the image and
one right aligned for the text.

Or you can do that in one fo:block and set that to
text-align-last="justify" and use an fo:leader for elastic spacing.

On 22.10.2009 09:17:12 sivag_123 wrote:
>
> Hi,
>
> I tried your solution. When we insert the text and image in 2 different
> blocks, then the image comes to the left and text comes to the center. But
> they are not inline. I want the image in the left and text in the right in
> the same line. If you can share some ideas, it would be great.
>
> Thanks and regards,
> Sivashankar
>
>
>
>
> JBryant wrote:
> >
> > You can set the alignment properties on the blocks within the table cells,
> > thus:
> >
> > <fo:table table-layout="fixed">
> >   <fo:table-column column-width="2in"/>
> >   <fo:table-column column-width="2.5in"/>
> >   <fo:table-column column-width="2in"/>
> >   <fo:table-body>
> >     <fo:table-row>
> >       <fo:table-cell>
> >          <fo:block text-align="left">Left footer stuff here</fo:block>
> >       </fo:table-cell>
> >       <fo:table-cell>
> >          <fo:block text-align="center">Center footer stuff here</fo:block>
> >       </fo:table-cell>
> >       <fo:table-cell>
> >          <fo:block text-align="right">Right footer stuff here</fo:block>
> >       </fo:table-cell>
> >     </fo:table-row>
> >   </fo:table-body>
> > </fo:table>
> >
> >
> > The footer definition I actually use for most of the documents for this
> > client is:
> >
> >           <fo:table table-layout="fixed">
> >             <fo:table-column column-width="2in"/>
> >             <fo:table-column column-width="2.5in"/>
> >             <fo:table-column column-width="2in"/>
> >             <fo:table-body>
> >               <fo:table-row>
> >                 <fo:table-cell>
> >                   <fo:block xsl:use-attribute-sets="footerleft">
> >                     Date prepared: <xsl:value-of
> > select="format-date(current-date(),'[D1] [MNn] [Y0001]')"/>
> >                   </fo:block>
> >                 </fo:table-cell>
> >                 <fo:table-cell>
> >                   <fo:block xsl:use-attribute-sets="footercenter">
> >                     Confidential and Proprietary
> >                   </fo:block>
> >                 </fo:table-cell>
> >                 <fo:table-cell>
> >                   <fo:block xsl:use-attribute-sets="footerright">
> >                     <fo:page-number />
> >                   </fo:block>
> >                 </fo:table-cell>
> >               </fo:table-row>
> >               <fo:table-row>
> >                 <fo:table-cell number-columns-spanned="3">
> >                   <fo:block xsl:use-attribute-sets="footercenter">
> >                     Copyright <xsl:value-of select="$copyrightYears"/>,
> > <xsl:value-of select="$copyrightOwner"/>. All Rights Reserved
> >                   </fo:block>
> >                 </fo:table-cell>
> >               </fo:table-row>
> >             </fo:table-body>
> >           </fo:table>
> >
> > Then I define the alignment in the named attribute set (which I keep in a
> > separate XSL file and import into several kinds of documents).
> >
> > Jay Bryant
> > Bryant Communication Services
> > (presently consulting at Synergistic Solution Technologies)
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/PDF-Header-alignment-tp445298p26005134.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
>
>



Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org