开发者

Rounded corners in XSL-FO

开发者 https://www.devze.com 2022-12-08 13:43 出处:网络
Our client\'s request is to have tables in PDF with rounded corner. I only have Apache FOP processor at my disposal and it开发者_开发知识库 doesn\'t support the rounded corner attribute. It also doesn

Our client's request is to have tables in PDF with rounded corner. I only have Apache FOP processor at my disposal and it开发者_开发知识库 doesn't support the rounded corner attribute. It also doesn't support floats, so floating rounded images to left and to right cannot be done.

Do you have any suggestions on how to do this?


You can create the table as a Scalable Vector Graphics(SVG) object, and include that as an external-image in your XSL-FO document. SVG supports rounded corners, and FOP supports SVG.

I believe you can also just create a rounded rectangle SVG and use that as a background to your content, and put the table in front of it. I think I did this once, but I cannot seem to locate the code...


As long as it is fixed width and dont expect things to 'float' dynamically width-wise like css, I have done this (by using a vertical 'Sliding Doors' technique, if you remember old-school css):

Get a rounded corner background image and have it as long as you expect to be on the page (note if you expect things to go onto multiple pages, then this won't work out so well hehe). I use it on headers/footers and things that start a new page (in the body region) that I know won't go more than 1 page.

Then I decide if i need a fixed height ... if so you can just use a background image with no fancyness...

if the height will vary, then I just use the top of the image for one part and the bottom of the image for another part. something like this:

<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 at it i think. like i had content at the bottom so i just use the bottom knowing i am definately going to have at least 70px of content to show the bottom gradient of my rounded corners.... you may just decide on putting all your content in the first block-container and giving the 2nd block-container a fixed height of 70px to only show the bottom background-image (i think this is possible even though if no content is present in that bottom container [forget xsl-fo rules]). Using FOP trunk and works out nicely.

EDIT: i should note i use latest FOP 1.0 (also tried with prev version), and it works well. Also I used a graphic as tall as the content will be since I have borders ... If you just require top and bottom graphics (and background-color to fill the body, then don't need the full 'as-tall-as-possible' image).


Rounded corners are supported in:

  • Apache FOP 2.0+ https://xmlgraphics.apache.org/fop/2.0/extensions.html#rounded-corners
  • AH Formatter 6:0+ https://www.antennahouse.com/product/ahf66/ahf-ext.html#rounding-border
  • RenderX XEP 4.30+ http://www.renderx.com/reference.html#Rounded_Borders.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号