xsl fo pdf fop - Not getting the expected dimensions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

xsl fo pdf fop - Not getting the expected dimensions

Léa Massiot
Hello and thank you for reading my post.

Below are the XSL stylesheet and the XML data files I am using.
Given these two files and using "fop" (1.0) emebeded in a Java application I generate a resulting PDF document which basically consists of a 210mm x 297mm page containing a rectangle with the "Hello World" string inside.
My problem is that, even though I am specifying I would like that rectangle to be 100mm x 200mm in the XML file (see below), I get a 94mm x 189mm area when I print the generated PDF document and measure it with a ruler.

Can you help me understand what's happening?

I was wondering if maybe some kind of "reset" (comparable to a CSS reset like *{padding: 0; margin: 0;}) might have to be done prior to working?

Thank you for helping.
Best regards.




XSL stylesheet
<?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="quotation">
    
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    
      <fo:layout-master-set>
        <fo:simple-page-master master-name = "simple_page_master" 
                               page-height = "{@page_height}"
                               page-width  = "{@page_width}"                                          
                               >
                                       
          <fo:region-body />
          
        </fo:simple-page-master>
      </fo:layout-master-set>

      <fo:page-sequence master-reference="simple_page_master">
        <fo:flow flow-name="xsl-region-body">
          <xsl:apply-templates select="area" />
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
        
  </xsl:template>
  
  <xsl:template match="area">
  
    <xsl:variable name="top">
      <xsl:value-of select="top" />
    </xsl:variable>
        
    <xsl:variable name="left">
      <xsl:value-of select="left" />
    </xsl:variable>
        
    <xsl:variable name="height">
      <xsl:value-of select="height" />
    </xsl:variable>
        
    <xsl:variable name="width">
      <xsl:value-of select="width" />
    </xsl:variable>
    
    <fo:block-container position = "absolute"
              top      = "{$top}"
              left     = "{$left}"
              height   = "{$height}"
              width    = "{$width}"
              background-color = "DarkSlateGray">
      
      <fo:block>
        <xsl:value-of select="content" />
      </fo:block>            

      
    </fo:block-container>
  </xsl:template>
  
</xsl:stylesheet>

XML data
<?xml version="1.0" encoding="UTF-8"?>
<quotation page_height='297mm' 
           page_width='210mm'>
  <area>
      <top>0mm</top>
      <left>0mm</left>
      <height>200mm</height>
      <width>100mm</width>
      <content>Hello World</content>    
  </area>
</quotation>
Reply | Threaded
Open this post in threaded view
|

Re: xsl fo pdf fop - Not getting the expected dimensions

Léa Massiot
And yet another example:

If I add a 2 cm margin to the body region like this:
<fo:region-body margin="2cm" />

Here are the margins I actually get on the printed document:
- margin left: 2.45 cm
- margin right: 2.5 cm
- margin top: 2.65 cm
- margin bottom: 3 cm

Thanks for helping me out.
Reply | Threaded
Open this post in threaded view
|

Re: xsl fo pdf fop - Not getting the expected dimensions

Glenn Adams-2
In reply to this post by Léa Massiot
Léa,

This is not an XSL-FO specification/standards issue. Please move this thread to the <[hidden email]> mail list.

Regards,
Glenn

On Fri, May 25, 2012 at 4:33 AM, Léa Massiot <[hidden email]> wrote:
Hello and thank you for reading my post.

Below are the XSL stylesheet and the XML data files I am using.
Given these two files and using "fop" (1.0) emebeded in a Java application I
generate a resulting PDF document which basically consists of a 210mm x
297mm page containing a rectangle with the "Hello World" string inside.
My problem is that, even though I am specifying I would like that rectangle
to be 100mm x 200mm in the XML file (see below), I get a 94mm x 189mm area
when I print the generated PDF document and measure it with a ruler.

Can you help me understand what's happening?

I was wondering if maybe some kind of "reset" (comparable to a CSS reset
like *{padding: 0; margin: 0;}) might have to be done prior to working?

Thank you for helping.
Best regards.




XSL stylesheet

<?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="quotation">

   <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

     <fo:layout-master-set>
       <fo:simple-page-master master-name = "simple_page_master"
                              page-height = "{@page_height}"
                              page-width  = "{@page_width}"
                              >

         <fo:region-body />

       </fo:simple-page-master>
     </fo:layout-master-set>

     <fo:page-sequence master-reference="simple_page_master">
       <fo:flow flow-name="xsl-region-body">
         <xsl:apply-templates select="area" />
       </fo:flow>
     </fo:page-sequence>
   </fo:root>

 </xsl:template>

 <xsl:template match="area">

   <xsl:variable name="top">
     <xsl:value-of select="top" />
   </xsl:variable>

   <xsl:variable name="left">
     <xsl:value-of select="left" />
   </xsl:variable>

   <xsl:variable name="height">
     <xsl:value-of select="height" />
   </xsl:variable>

   <xsl:variable name="width">
     <xsl:value-of select="width" />
   </xsl:variable>

   <fo:block-container position = "absolute"
             top      = "{$top}"
             left     = "{$left}"
             height   = "{$height}"
             width    = "{$width}"
             background-color = "DarkSlateGray">

     <fo:block>
       <xsl:value-of select="content" />
     </fo:block>


   </fo:block-container>
 </xsl:template>

</xsl:stylesheet>


XML data

<?xml version="1.0" encoding="UTF-8"?>
<quotation page_height='297mm'
          page_width='210mm'>
 <area>
     <top>0mm</top>
     <left>0mm</left>
     <height>200mm</height>
     <width>100mm</width>
     <content>Hello World</content>
 </area>
</quotation>

--
View this message in context: http://old.nabble.com/xsl-fo-pdf-fop---Not-getting-the-expected-dimensions-tp33907126p33907126.html
Sent from the w3.org - www-xsl-fo mailing list archive at Nabble.com.




Reply | Threaded
Open this post in threaded view
|

Re: xsl fo pdf fop - Not getting the expected dimensions

Jeremias Maerki-2
In reply to this post by Léa Massiot
Hi Léa,

take a look at http://xmlgraphics.apache.org/fop/faq.html#pdf-print-contortion

HTH
Jeremias Maerki


On 25.05.2012 12:33:26 Léa Massiot wrote:

> Hello and thank you for reading my post.
>
> Below are the XSL stylesheet and the XML data files I am using.
> Given these two files and using "fop" (1.0) emebeded in a Java application I
> generate a resulting PDF document which basically consists of a 210mm x
> 297mm page containing a rectangle with the "Hello World" string inside.
> My problem is that, even though I am specifying I would like that rectangle
> to be 100mm x 200mm in the XML file (see below), I get a 94mm x 189mm area
> when I print the generated PDF document and measure it with a ruler.
>
> Can you help me understand what's happening?
>
> I was wondering if maybe some kind of "reset" (comparable to a CSS reset
> like *{padding: 0; margin: 0;}) might have to be done prior to working?
>
> Thank you for helping.
> Best regards.
>
>
>
>
> XSL stylesheet
>
> <?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="quotation">
>    
>     <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
>    
>       <fo:layout-master-set>
>         <fo:simple-page-master master-name = "simple_page_master"
>                                page-height = "{@page_height}"
>                                page-width  = "{@page_width}"                                          
>                                >
>                                        
>           <fo:region-body />
>          
>         </fo:simple-page-master>
>       </fo:layout-master-set>
>
>       <fo:page-sequence master-reference="simple_page_master">
>         <fo:flow flow-name="xsl-region-body">
>           <xsl:apply-templates select="area" />
>         </fo:flow>
>       </fo:page-sequence>
>     </fo:root>
>        
>   </xsl:template>
>  
>   <xsl:template match="area">
>  
>     <xsl:variable name="top">
>       <xsl:value-of select="top" />
>     </xsl:variable>
>        
>     <xsl:variable name="left">
>       <xsl:value-of select="left" />
>     </xsl:variable>
>        
>     <xsl:variable name="height">
>       <xsl:value-of select="height" />
>     </xsl:variable>
>        
>     <xsl:variable name="width">
>       <xsl:value-of select="width" />
>     </xsl:variable>
>    
>     <fo:block-container position = "absolute"
>               top      = "{$top}"
>               left     = "{$left}"
>               height   = "{$height}"
>               width    = "{$width}"
>               background-color = "DarkSlateGray">
>      
>       <fo:block>
>         <xsl:value-of select="content" />
>       </fo:block>            
>
>      
>     </fo:block-container>
>   </xsl:template>
>  
> </xsl:stylesheet>
>
>
> XML data
>
> <?xml version="1.0" encoding="UTF-8"?>
> <quotation page_height='297mm'
>            page_width='210mm'>
>   <area>
>       <top>0mm</top>
>       <left>0mm</left>
>       <height>200mm</height>
>       <width>100mm</width>
>       <content>Hello World</content>    
>   </area>
> </quotation>
>
> --
> View this message in context: http://old.nabble.com/xsl-fo-pdf-fop---Not-getting-the-expected-dimensions-tp33907126p33907126.html
> Sent from the w3.org - www-xsl-fo mailing list archive at Nabble.com.
>
>


Reply | Threaded
Open this post in threaded view
|

Re: xsl fo pdf fop - Not getting the expected dimensions

G. Ken Holman
In reply to this post by Léa Massiot
At 2012-05-25 03:33 -0700, Léa Massiot wrote:
>Below are the XSL stylesheet and the XML data files I am using.
>Given these two files and using "fop" (1.0) emebeded in a Java application I
>generate a resulting PDF document which basically consists of a 210mm x
>297mm page containing a rectangle with the "Hello World" string inside.
>My problem is that, even though I am specifying I would like that rectangle
>to be 100mm x 200mm in the XML file (see below), I get a 94mm x 189mm area
>when I print the generated PDF document and measure it with a ruler.
>
>Can you help me understand what's happening?

I do not use FOP so I put your files through
another processor and the box came out precisely at 100mmx200mm.

So it sounds like a FOP bug.

Note in your stylesheet you are following poor
form in the declaration of result tree fragment
variables with text nodes, rather than simply
addressing the values of the elements with
attribute value templates the way you did with your simple page master.

>   <xsl:template match="area">
>
>     <xsl:variable name="top">
>       <xsl:value-of select="top" />
>     </xsl:variable>
>
>     <xsl:variable name="left">
>       <xsl:value-of select="left" />
>     </xsl:variable>
>
>     <xsl:variable name="height">
>       <xsl:value-of select="height" />
>     </xsl:variable>
>
>     <xsl:variable name="width">
>       <xsl:value-of select="width" />
>     </xsl:variable>
>
>     <fo:block-container position = "absolute"
>               top      = "{$top}"
>               left     = "{$left}"
>               height   = "{$height}"
>               width    = "{$width}"
>               background-color = "DarkSlateGray">

The following would produce the same result
without the overhead of creating variables:

   <xsl:template match="area">

     <fo:block-container position = "absolute"
               top      = "{top}"
               left     = "{left}"
               height   = "{height}"
               width    = "{width}"
               background-color = "DarkSlateGray">

       <fo:block>
         <xsl:value-of select="content" />
       </fo:block>

And even if you needed variables later in the
code, the following would be better:

   <xsl:variable name="width" select="width"/>

I hope this helps.

. . . . . . . Ken

--
Public XSLT, XSL-FO, UBL and code list classes in Europe -- Oct 2012
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/f/
G. Ken Holman                   mailto:[hidden email]
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal


Reply | Threaded
Open this post in threaded view
|

Re: xsl fo pdf fop - Not getting the expected dimensions

Léa Massiot
Thank you for your answers.

@Glenn Adams
Ok but it appears that, as I tried to move my thread to http://old.nabble.com/FOP---Users-f353.html, I got the message:
"Can't move out of mailing list archive for www-xsl-fo@w3.org
Please fix the error and try again."

@Jeremias Maerki
Ok. I didn't get better results.
I wanted to use the Adobe Reader measuring tool but it appears it's not available anymore... as far as I'm not mistaken...
Adobe Reader X - version 10.1.3 is the PDF reader installed on my computer.

@Ken Holman
G. Ken Holman wrote
I do not use FOP so I put your files through another processor and the box came out precisely at 100mmx200mm.
What is this other processor you're using?

Even with the simpler code below, I do not get the expected 2cm page margins, the 4cm margin and the 5cm padding...

Thank you for helping me out.
Best regards,
--
Léa

<?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="/">
    
    <fo:root>
    
      <fo:layout-master-set>
        <fo:simple-page-master master-name = "A4-portrait" 
                               page-height="29.7cm" 
                               page-width="21.0cm" 
                               margin="2cm"                                        
                               >
                                       
          <fo:region-body />
          
        </fo:simple-page-master>
      </fo:layout-master-set>

      <fo:page-sequence master-reference="A4-portrait">
        <fo:flow flow-name="xsl-region-body">
          <fo:block background-color="DarkSlateGray"
                          padding-left="5cm"
                          margin-left="4cm">
            Hello
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
        
  </xsl:template>
  
</xsl:stylesheet>
Reply | Threaded
Open this post in threaded view
|

Re: xsl fo pdf fop - Not getting the expected dimensions

G. Ken Holman
At 2012-05-28 02:40 -0700, Léa Massiot wrote:
>@Ken Holman
>
>G. Ken Holman wrote:
> > I do not use FOP so I put your files through another processor and the box
> > came out precisely at 100mmx200mm.
>
>What is this other processor you're using?

Your file works in the three tools I
have:  Antenna House, RenderX and Ibex (though I
had to change the colour name for RenderX to work).

. . . . . . . . . Ken

--
Public XSLT, XSL-FO, UBL and code list classes in Europe -- Oct 2012
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/f/
G. Ken Holman                   mailto:[hidden email]
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal


Reply | Threaded
Open this post in threaded view
|

Re: xsl fo pdf fop - Not getting the expected dimensions

Léa Massiot
This doesn't really help but thank you for testing.
Best regards,
--
Léa


G. Ken Holman wrote
At 2012-05-28 02:40 -0700, Léa Massiot wrote:
>@Ken Holman
>
>G. Ken Holman wrote:
> > I do not use FOP so I put your files through another processor and the box
> > came out precisely at 100mmx200mm.
>
>What is this other processor you're using?

Your file works in the three tools I
have:  Antenna House, RenderX and Ibex (though I
had to change the colour name for RenderX to work).

. . . . . . . . . Ken

--
Public XSLT, XSL-FO, UBL and code list classes in Europe -- Oct 2012
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/f/
G. Ken Holman                   mailto:gkholman@CraneSoftwrights.com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal

Reply | Threaded
Open this post in threaded view
|

Re: xsl fo pdf fop - Not getting the expected dimensions

Jeremias Maerki-2
In reply to this post by Léa Massiot
Léa,
I stand by my comment earlier. It must be the "Size Options" in Acrobat
Reader's print dialog. It must be on "Actual Size". Or a setting in the
printer driver. Have you tried a different printer?

I've had to change the color name, too, and added another background
color for illustration. Here's the FO and PDF generated with Apache FOP
1.0. Printed out, the sizes are withing mechanical tolerance, i.e. shift
of the whole page content < 1mm.

The ten-thousands of users of Apache FOP would cut our collective heads
off, if there was a bug as serious as considerable size deviations.

Jeremias Maerki


On 28.05.2012 11:40:21 Léa Massiot wrote:

> Thank you for your answers.
>
> @Glenn Adams
> Ok but it appears that, as I tried to move my thread to
> http://old.nabble.com/FOP---Users-f353.html, I got the message:
> "Can't move out of mailing list archive for [hidden email]
> Please fix the error and try again."
>
> @Jeremias Maerki
> Ok. I didn't get better results.
> I wanted to use the Adobe Reader measuring tool but it appears it's not
> available anymore... as far as I'm not mistaken...
> Adobe Reader X - version 10.1.3 is the PDF reader installed on my computer.
>
> @Ken Holman
>
> G. Ken Holman wrote:
> > I do not use FOP so I put your files through another processor and the box
> > came out precisely at 100mmx200mm.
>
> What is this other processor you're using?
>
> Even with the simpler code below, I do not get the expected 2cm page
> margins, the 4cm margin and the 5cm padding...
>
> Thank you for helping me out.
> Best regards,
> --
> Léa
>
>
> <?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="/">
>    
>     <fo:root>
>    
>       <fo:layout-master-set>
>         <fo:simple-page-master master-name = "A4-portrait"
>                                page-height="29.7cm"
>                                page-width="21.0cm"
>                                margin="2cm"                                        
>                                >
>                                        
>           <fo:region-body />
>          
>         </fo:simple-page-master>
>       </fo:layout-master-set>
>
>       <fo:page-sequence master-reference="A4-portrait">
>         <fo:flow flow-name="xsl-region-body">
>           <fo:block background-color="DarkSlateGray"
>                           padding-left="5cm"
>                           margin-left="4cm">
>             Hello
>           </fo:block>
>         </fo:flow>
>       </fo:page-sequence>
>     </fo:root>
>        
>   </xsl:template>
>  
> </xsl:stylesheet>
>
> --
> View this message in context: http://old.nabble.com/xsl-fo-pdf-fop---Not-getting-the-expected-dimensions-tp33907126p33918782.html
> Sent from the w3.org - www-xsl-fo mailing list archive at Nabble.com.
>
>
>

test.fo (1K) Download Attachment
out.pdf (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: xsl fo pdf fop - Not getting the expected dimensions

Léa Massiot
Hello Jeremias,

- I printed the PDF document you attached choosing "Actual size" at print time.
=> Yes, the various dimensions are correct (modulo 1mm).

- Imitating the FO document you attached, I tried generating the PDF file using the below XSL-FO stylesheet (n°1).
=> And again the dimensions are correct.
(BTW, it also works with "DarkSlateGray" instead of "orange" as the "fo:region-body" background color.)

- I also tested my original XSL-FO stylesheet (cf. XSL-FO stylesheet n°2 below) which is also properly rendered...

A great thank you for your help and for sending the FO and PDF attachments. It really helped.
Best regards,
--
Léa

**** XSL-FO stylesheet n°1

<?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="/">
    
    <fo:root>
    
      <fo:layout-master-set>
        <fo:simple-page-master master-name = "A4-portrait" 
                               page-height="29.7cm" 
                               page-width="21.0cm" 
                               margin="2cm"                                        
                               >
                                       
          <fo:region-body background-color="DarkSlateGray" />
          
        </fo:simple-page-master>
      </fo:layout-master-set>

      <fo:page-sequence master-reference="A4-portrait">
        <fo:flow flow-name="xsl-region-body">
          <fo:block background-color="gray"
                    padding-left="5cm"
                    margin-left="4cm">
            Hello
          </fo:block>
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
        
  </xsl:template>
  
</xsl:stylesheet>

**** XSL-FO stylesheet n°2

<?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="quotation">
    
    <fo:root>
    
      <fo:layout-master-set>
        <fo:simple-page-master master-name = "A4-portrait" 
                               page-height="{@page_height}" 
                               page-width="{@page_width}" 
                               margin="{@margin}"                                        
                               >
                                       
          <fo:region-body background-color="orange" />
          
        </fo:simple-page-master>
      </fo:layout-master-set>

      <fo:page-sequence master-reference="A4-portrait">
        <fo:flow flow-name="xsl-region-body">
          <xsl:apply-templates select="area" />
        </fo:flow>
      </fo:page-sequence>
    </fo:root>
        
  </xsl:template>
  
  <xsl:template match="area">
    <fo:block-container position = "absolute"
                        top      = "{top}"
                        left     = "{left}" 
                        width    = "{width}">
      <fo:block background-color="gray">
        <xsl:value-of select="content" />
      </fo:block>
    </fo:block-container>
  </xsl:template>
</xsl:stylesheet>

**** XML

<?xml version="1.0" encoding="UTF-8"?>
<quotation page_height="29.7cm" 
           page_width="21.0cm"
           margin="2cm">
  <area>
    <top>1cm</top>
    <left>2cm</left>
    <height>20cm</height>
    <width>10cm</width>
    <content>
      Hello
    </content>    
  </area>
</quotation>

Jeremias Maerki-2 wrote
Léa,
I stand by my comment earlier. It must be the "Size Options" in Acrobat
Reader's print dialog. It must be on "Actual Size". Or a setting in the
printer driver. Have you tried a different printer?

I've had to change the color name, too, and added another background
color for illustration. Here's the FO and PDF generated with Apache FOP
1.0. Printed out, the sizes are withing mechanical tolerance, i.e. shift
of the whole page content < 1mm.

The ten-thousands of users of Apache FOP would cut our collective heads
off, if there was a bug as serious as considerable size deviations.

Jeremias Maerki