Note that there are some explanatory texts on larger screens.

plurals
  1. POXSL + Apache FOP: Adding content on the remainder of empty space on a paragraph
    text
    copied!<p>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:</p> <pre><code>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.------------------------------ </code></pre> <p>The tricky part is that I will be using a non monospace (variable width) font. Furthermore, the paragraph alignment will be set to <code>justify</code>. 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).</p> <p>Based on my <a href="http://apache-fop.1065347.n5.nabble.com/Extract-font-width-using-FOP-td37360.html" rel="nofollow">findings</a>, it seems calculating text width precisely (taking in to account variable width, kerning, etc) is impossible in FOP.</p> <p>My current solution is to hack into the xsl:</p> <pre><code>&lt;fo:block background-image=dash.jpg&gt; &lt;fo:inline background-color=white&gt;This is a paragraph on a page that will be converted to PDF but the remaining space must be filled.&lt;/fo:inline&gt; &lt;/fo:block&gt; </code></pre> <p><code>dash.jpg</code> 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 <code>&lt;fo:inline&gt;</code> tag will cover those dash using a white background so that it only appears on the empty remaining space of the paragraph.</p> <p>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.</p> <p>I couldn't think of other solutions since FOP itself doesn't support some properties such as <code>float</code> and <code>display</code>, which honestly could have helped me get much further. I wonder if you have a better solution than what I have right now.</p> <p>ANSWER as proposed by @NavinRawat:</p> <pre><code> &lt;fo:block text-align-last="justify"&gt;... a long paragraph ...&lt;fo:leader leader-pattern="dots" /&gt;&lt;/fo:block&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload