Reputation: 11
I am generating PDFs from XSL-FO with Apache FOP. I would like to be able to format images such that they take up the rest of the space on the page. I would also like to have either the top/bottom or left/right of the image cropped depending on whether the image aspect ratio is too wide or too tall to fit the space in the rest of the page.
Here is a small test I'm working on:
<?xml version="1.0" encoding="iso-8859-1"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="test-page">
<fo:region-body margin="1in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="test-page">
<fo:flow flow-name="xsl-region-body">
<fo:block>Some content.</fo:block>
<fo:block-container display-align="center" height="100%" overflow="hidden" break-after="page">
<fo:block>
<fo:external-graphic width="100%" content-width="scale-to-fit" src="bgtall.png"/>
</fo:block>
</fo:block-container>
</fo:flow>
</fo:page-sequence>
</fo:root>
Two problems:
height="100%"
is just a filler. I want the height of the block-container to be from the current end of content to the end of page. Is there any way to do this?display-align="center"
only seems to work when the content is smaller than the block. So my too-tall image only has the bottom cut off.Currently we're solving this problem by generating the PDF twice and cropping the images to fit perfectly. I don't like this solution and I would love to find a better way.
Upvotes: 1
Views: 916
Reputation: 8068
You could use the XSLTExtensions (https://github.com/pplcg/XSLTExtensions, https://www.w3.org/community/ppl/wiki/XSLTExtensions) from the Print and Page Layout Community Group (http://www.w3.org/community/ppl/) to:
If XSLTExtensions doesn't work for you:
Upvotes: 0
Reputation: 8877
While it should be simple, apparently it does not work in FOP. I will show you results from RenderX and FOP:
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master margin-top="1in" margin-left="1in"
margin-bottom="18pt" margin-right="18pt"
page-width="700pt" page-height="780pt" master-name="first">
<fo:region-body margin-top="0pt"/>
<fo:region-before extent="0pt"/>
<fo:region-after extent="0pt"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="first">
<fo:flow flow-name="xsl-region-body">
<fo:block space-before="18pt">Bingo</fo:block>
<fo:block space-before="18pt">Bango</fo:block>
<fo:block space-before="18pt">Bongo</fo:block>
<fo:block>
<fo:block-container reference-orientation="90" background-color="yellow">
<fo:block><fo:leader/></fo:block>
</fo:block-container>
</fo:block>
<fo:block>I should be on the next page</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
Which gives you the following in RenderX --- the yellow area takes the full remaining area on the page and content after is on the next page. It does not matter how much content is before, it would "expand" to take the fill progression dimension and since it is rotated, this is the space from the start to the top of the footer area. The second part of your question would just involve inserting and scaling an image in the yellow area.
What you will get from FOP is completely wrong. It puts the yellow block on the second page the content following on the third page and the yellow block is drawn completely wrong. This is from FOP for the exact same file:
If you are going to use FOP, you should submit a bug as their formatting is wrong. There is no reason to go onto part two of your question (to insert and scale an image) because you cannot achieve part one.
Upvotes: 0