lolski
lolski

Reputation: 17501

XSL + Apache FOP: Adding content on the remainder of empty space on a paragraph

I'm making a PDF generator with Apache FOP and one of the main requirement is to fill the remaining empty space of a paragraph with a series of dashes like this:

This is a paragraph on a page that will be converted to PDF
but the remaining  space must be filled.-------------------

This is another paragraph on the same page and again the re
maining space must be filled.------------------------------

The tricky part is that I will be using a non monospace (variable width) font. Furthermore, the paragraph alignment will be set to justify. These two requirements are set from the government and can not be changed (which actually make sense since the generated PDF are meant primarily for printing purposes).

Based on my findings, it seems calculating text width precisely (taking in to account variable width, kerning, etc) is impossible in FOP.

My current solution is to hack into the xsl:

<fo:block background-image=dash.jpg>
    <fo:inline background-color=white>This is a paragraph on a page that will be converted to PDF but the remaining  space must be filled.</fo:inline>
</fo:block>

dash.jpg is an image of a dash character where its dimension are carefully calculated so that it sits right when it is tiled across the paragraph, taking into account factors such as font height and spacing. the <fo:inline> tag will cover those dash using a white background so that it only appears on the empty remaining space of the paragraph.

However, the problem with this hack is it is a hack: the calculation of image height can not be very precise since font size, spacing and margin are calculated using point instead of pixel, a decision I made since the generated PDF is meant primarily for printing.

I couldn't think of other solutions since FOP itself doesn't support some properties such as float and display, which honestly could have helped me get much further. I wonder if you have a better solution than what I have right now.

ANSWER as proposed by @NavinRawat:

 <fo:block text-align-last="justify">... a long paragraph ...<fo:leader leader-pattern="dots" /></fo:block>

Upvotes: 0

Views: 748

Answers (1)

Navin Rawat
Navin Rawat

Reputation: 3138

Have you tried <fo:leader leader-pattern="dots"/> after your para content to manipulate if it works.

Upvotes: 0

Related Questions