XSL-FO to generate a PDF document

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

XSL-FO to generate a PDF document

by ubi_nunes :: Rate this Message:

| View Threaded | Show Only this Message

Hi,

I have to draw cross-line box that will start from the last row of a table and will cover all the white space until the end of the page.

I'm using fo:instream-foreign-object and svg to create the cross-line box.

My problem is that I don't know the size to the box till the xml elements populates the table and it will be different from xml to xml file that I process.

Can anyone help with a code sample?

Many thanks

Ubi

Re: XSL-FO to generate a PDF document

by Tony Graham-3 :: Rate this Message:

| View Threaded | Show Only this Message

On Mon, Jul 13 2009 05:01:27 +0100, ubi.nunes@... wrote:

> I have to draw cross-line box that will start from the last row of a table
> and will cover all the white space until the end of the page.
>
> I'm using fo:instream-foreign-object and svg to create the cross-line box.
>
> My problem is that I don't know the size to the box till the xml elements
> populates the table and it will be different from xml to xml file that I
> process.
>
> Can anyone help with a code sample?

You would want to:

 - Keep the table and the following fo:block together within the page

 - Allow non-uniform scaling on the fo:instream-foreign-object

 - Set the content-height to 'scale-to-fit' (probably also for
   content-width).

Regards,


Tony Graham                         Tony.Graham@...
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd                               XML Guild member
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2


Re: XSL-FO to generate a PDF document

by ubi_nunes :: Rate this Message:

| View Threaded | Show Only this Message

Tony Graham-3 wrote:
On Mon, Jul 13 2009 05:01:27 +0100, ubi.nunes@topazsolutions.co.nz wrote:
> I have to draw cross-line box that will start from the last row of a table
> and will cover all the white space until the end of the page.
>
> I'm using fo:instream-foreign-object and svg to create the cross-line box.
>
> My problem is that I don't know the size to the box till the xml elements
> populates the table and it will be different from xml to xml file that I
> process.
>
> Can anyone help with a code sample?

You would want to:

 - Keep the table and the following fo:block together within the page

 - Allow non-uniform scaling on the fo:instream-foreign-object

 - Set the content-height to 'scale-to-fit' (probably also for
   content-width).

Regards,


Tony Graham                         Tony.Graham@MenteithConsulting.com
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd                               XML Guild member
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2
Hi Tony,

Thanks for the suggestion, but unfortunately it didn't work. I have paste the code I'm trying to get to work. If you can review it and maybe give another suggestion would be great.

                <fo:flow flow-name="xsl-region-body" font-family="Times" font-size="12pt">
                        <fo:block keep-together="always" wrap-option="no-wrap" keep-together.within-page="always">
                                <fo:table table-layout="fixed" width="100%" height="10%" border-collapse="collapse">
                                        <fo:table-column column-width="100.000%" column-number="1"/>
                                        <fo:table-column column-width="100.000%" column-number="2"/>
                                        <fo:table-column column-width="100.000%" column-number="3"/>
                                        <fo:table-column column-width="100.000%" column-number="4"/>
                                        <fo:table-body>
                                                <xfd:table-row-repeat xpath="/certificates/certificate/product/processing">
                                                        <fo:table-cell border="1pt solid black" padding="2pt">
                                                                <fo:block> <xfd:field xpath="processing_type/@code"/>
                                                                 </fo:block>
                                                        </fo:table-cell><fo:table-cell  border="1pt solid black" padding="2pt">
                                                                <fo:block><xfd:field xpath="processing_type"/> </fo:block>
                                                        </fo:table-cell><fo:table-cell border="1pt solid black" padding="2pt">
                                                                <fo:block><xfd:field xpath="premises/@id"/> </fo:block>
                                                        </fo:table-cell><fo:table-cell border="1pt solid black" padding="2pt">
                                                                <fo:block>
                                                                <fo:inline wrap-option="wrap">
                                                                        <xfd:field xpath="premises/name"/>
                                                                </fo:inline> 
                                                                </fo:block>
                                                        </fo:table-cell>
                                                </xfd:table-row-repeat>
                                        </fo:table-body>
                                </fo:table>
                                <fo:block>
                                        <fo:instream-foreign-object content-width="scale-to-fit" content-height="scale-to-fit" scaling="non-uniform">
                                                <svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="6.8in" height="10.1in">
                                                <svg:g transform="scale(1, 1)">
                                                <svg:line x1="0" y1="0" x2="6.8in" y2="10.1in" style="stroke:blue;"/>
                                                <svg:line x1="0" y1="10.1in" x2="6.8in" y2="0" style="stroke:blue;"/>
                                                </svg:g>
                                                </svg:svg>
                                        </fo:instream-foreign-object>
                                </fo:block>
                        </fo:block>
                </fo:flow>

Thanks

Ubi

Re: XSL-FO to generate a PDF document

by Luis Fernando Heckler :: Rate this Message:

| View Threaded | Show Only this Message

-------- Mensagem original --------
Assunto: Re: XSL-FO to generate a PDF document
De: ubi_nunes <ubi.nunes@...>
Para: www-xsl-fo@...
Data: Qua 15 Jul 2009 22:59:13 BRT

> Hi Tony,
>
> Thanks for the suggestion, but unfortunately it didn't work. I have paste
> the code I'm trying to get to work. If you can review it and maybe give
> another suggestion would be great.
>

I think that its a problem when scaling a embeded svg if you doesn't
know the exactly available size, at least using apache fop as xsl-fo
processor:

http://xml.apache.org/fop/graphics.html#svg-scaling

Perhaps an alternative approach its use (and scale non uniform) a png
image instead of a svg.

Regards,
Luis




Re: XSL-FO to generate a PDF document

by Tony Graham-3 :: Rate this Message:

| View Threaded | Show Only this Message

On Thu, Jul 16 2009 02:59:13 +0100, ubi.nunes@... wrote:
...
> Thanks for the suggestion, but unfortunately it didn't work. I have paste
> the code I'm trying to get to work. If you can review it and maybe give
> another suggestion would be great.

I tweaked your SVG a bit, but I had to put the SVG in an external
'cross.svg' file before I could get the cross to resize properly.

Also, it would have helped if you'd posted FO markup starting at
fo:root.  You also had xfd:* elements in your FO that had to be removed,
and setting every column's width to 100% isn't really very effective.

This FO markup (with the SVG copied to 'cross.svg') works okay in Antenna
House Formatter V5:

------------------------------------------------------------
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xlink="http://www.w3.org/1999/xlink">
  <fo:layout-master-set>
    <fo:simple-page-master page-width="297mm" page-height="210mm" margin-right="0.75in" margin-left="0.2in" margin-bottom="0.0in" margin-top="0.375in" master-name="coverPage">
      <fo:region-body margin-bottom="0.9in" margin-top="0.6in" region-name="xsl-region-body_coverpage"/>
      <fo:region-before extent="0.5in" region-name="xsl-region-before_coverpage"/>
      <fo:region-after extent="0.9in" region-name="xsl-region-after_allpages"/>
    </fo:simple-page-master>
    <fo:simple-page-master page-width="297mm" page-height="210mm" margin-right="0.75in" margin-left="0.2in" margin-bottom="0.0in" margin-top="0.375in" master-name="Page2">
      <fo:region-body margin-bottom="0.9in" margin-top="0.6in" region-name="xsl-region-body"/>
      <fo:region-before extent="0.5in" region-name="xsl-region-before_page2"/>
      <fo:region-after extent="0.9in" region-name="xsl-region-after_allpages"/>
    </fo:simple-page-master>
    <fo:page-sequence-master master-name="master2">
      <fo:repeatable-page-master-reference  master-reference="Page2"/>
    </fo:page-sequence-master>
  </fo:layout-master-set>
  <fo:page-sequence master-reference="master2">
    <fo:flow flow-name="xsl-region-body" font-family="Times" font-size="12pt">
  <fo:block keep-together="always" wrap-option="no-wrap"
    keep-together.within-page="always">
    <fo:table table-layout="fixed" width="100%" height="10%"
      border-collapse="collapse">
      <fo:table-column column-width="proportional-column-width(1)" column-number="1"/>
      <fo:table-column column-width="proportional-column-width(1)" column-number="2"/>
      <fo:table-column column-width="proportional-column-width(1)" column-number="3"/>
      <fo:table-column column-width="proportional-column-width(1)" column-number="4"/>
      <fo:table-body>
          <fo:table-cell border="1pt solid black" padding="2pt">
            <fo:block>e
            </fo:block>
          </fo:table-cell><fo:table-cell  border="1pt solid black"
            padding="2pt">
            <fo:block>a </fo:block>
          </fo:table-cell><fo:table-cell border="1pt solid black"
            padding="2pt">
            <fo:block>b </fo:block>
          </fo:table-cell><fo:table-cell border="1pt solid black"
            padding="2pt">
            <fo:block>
              <fo:inline wrap-option="wrap">
                c
              </fo:inline>
            </fo:block>
          </fo:table-cell>
      </fo:table-body>
    </fo:table>
    <fo:block>
      <!--
      <fo:instream-foreign-object content-width="scale-up-to-fit"
        content-height="scale-up-to-fit" scaling="non-uniform" height="100%" width="100%">
        <svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="1600px" height="1600px" viewbox="0 0 1600 1600" preserveAspectRatio="none">
          <svg:g>
            <svg:line x1="0" y1="0" x2="1600" y2="1600" style="stroke:blue;"/>
            <svg:line x1="0" y1="1600" x2="1600" y2="0" style="stroke:blue;"/>
          </svg:g>
        </svg:svg>
      </fo:instream-foreign-object>
      <fo:external-graphic content-width="scale-to-fit"
        content-height="scale-to-fit" scaling="non-uniform" width="100%" height="100%" src="xmlroff.svg"/>
      -->
      <fo:external-graphic content-width="scale-to-fit"
        content-height="scale-to-fit" scaling="non-uniform" width="100%" height="100%" src="cross.svg"/>
    </fo:block>
  </fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
------------------------------------------------------------

Regards,


Tony Graham                         Tony.Graham@...
Director                                  W3C XSL FO SG Invited Expert
Menteith Consulting Ltd                               XML Guild member
XML, XSL and XSLT consulting, programming and training
Registered Office: 13 Kelly's Bay Beach, Skerries, Co. Dublin, Ireland
Registered in Ireland - No. 428599   http://www.menteithconsulting.com
  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --
xmlroff XSL Formatter                               http://xmlroff.org
xslide Emacs mode                  http://www.menteith.com/wiki/xslide
Unicode: A Primer                               urn:isbn:0-7645-4625-2