Rounded corners in XSL-FO

Our customer request must have tables in PDF format with a rounded corner. I only have an Apache FOP processor and it does not support the rounded corner attribute. It also does not support floats, so floating rounded images left and right cannot be performed.

Do you have any suggestions on how to do this?

+6
xsl-fo
source share
3 answers

You can create the table as a scalable vector graphics (SVG) object and include this as an external image in your XSL-FO document. SVG supports rounded corners, while FOP supports SVG.

I believe that you can just create an SVG rectangle with a rounded rectangle and use it as a background for your content and put a table in front of it. I think I did it once, but I can not find the code ...

+5
source share

As long as they have a fixed width and they don’t expect things to “float” dynamically in width, for example, css, I did this (using the vertical “Sliding doors” technique, if you remember the old css school):

Get an image with a rounded corner of the background and get it as long as you expect to be on the page (note that if you expect events to appear on several pages, then this will not develop so well). I use it in headers and footers and things that start a new page (in the body area), which I know will not be more than 1 page.

Then I decide if I need a fixed height ... if you can just use the background image without fantasy ...

if the height changes then I just use the top of the image for one part and the bottom of the image for the other. something like that:

<fo:block-container> <fo:block-container background-image="url(images/rounded_corner_image.png)" background-repeat="no-repeat" background-position-horizontal="15px" background-position-vertical="top" background-color="white" > <!-- So it used the top of the image for as long as the block-container exists heightwise. I may have had some whitespace in my image and need to move image into place so think I used background-position-horizontal since i had 15px of whitespace i wanted to cut off Also you may set a height above if definatley know you don't need it to 'auto-expand', just make sure you have content that can't overflow if setting height (like a table with Name: Address: fields) --> <fo:block margin="70px 70px 0px 70px"> Need to add some margins before starting content since dont want to text to touch the top and sides of of the rounded corner/borders plus add whitespace for content. </fo:block> </fo:block-container> <fo:block-container background-image="url(images/rounded_corner_image.png)" background-repeat="no-repeat" background-position-horizontal="15px" background-position-vertical="bottom" padding="0px 0px 20px 0px" background-color="white" > <fo:block margin="0px 70px 70px 70px"> Need to add some margins before starting content since dont want to text to touch bottom and sides of of the rounded corner/borders. </fo:block> </fo:block-container> </fo:block-container> 

Theres various ways to go for it I think. for example, I had content at the bottom, so I just use the bottom, knowing that I will have at least 70 pixels of content to show the bottom gradient of my rounded corners .... you can just decide to put all my content in the first block-container and gives the 2nd block container a fixed height of 70 pixels to display only the lower background image (I think this is possible even if there is no content in this lower container [forget xsl-fo rules]). Using the FOP trunk and works great.

EDIT: I have to note that I use the latest FOP 1.0 (also tried with the previous version) and it works well. In addition, I used the graphics as high as the content will be, since I have borders ... If you just need the upper and lower graphics (and background color to fill the body, then you don't need the full as-tall-as "-possible image).

0
source share
0
source share

All Articles