You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Petermair Patrick <Pa...@anecon.com> on 2009/06/22 17:41:10 UTC
text output page header
Hi!
We are using Velocity to create some reports that will be printed out. One
report gets a list of customers and prints some data about them. I¹m now
faced with the problem of writing a page header at the beginning of every
page (that gets printed out). Something like:
³Page 23²
and so on... Is there any support in Velocity to print some kind of header
after a fixed amount of lines? I know how many lines a page can hold. The
data per customer isn¹t static so I don¹t know how many lines each customer
will take. So basically my textfile would look like this:
Page 1
<some data>
<more data>
Page 2
<some more data>
Page 3
<even more data>
<still more data>
<more more data>
Page 4
...
Without the header I would simply output every customer in a ³for each²
loop. But I need to tell Velocity somehow that it needs to print an extra
line with some header data after every 80th line (for example).
I was going through the documentation but I couldn¹t find anything that
would help me do this ... any ideas?
Thanks,
Patrick
Re: text output page header
Posted by ap...@recks.org.
Hi,
to my knowledge, neither the Velocity-engine nor the Template currently have capabilities to count lines and do something ever x-lines. But you could device some workarounds.
a) Pass all lines through a macro that counts the lines and inserts the header information. (untested code)
#set( $pageNr = 1 )
#set( $lineNr = 0 )
#macro( println $text )
#if( $lineNr % 80 )
Page $pageNr
#set( $pageNr= $pageNr+ 1 )
#end
## emit the text
$text
#set( $lineNr = $lineNr + 1 )
## or do something more sophisticated to count the lines...
#end
...
## use the macro
#println("some data")
#println("more data")
...
b) Use a custom Writer class passed to the velocity rendering which does the line handling.
c) Use velocity to generate FOP content post-rendered to pages
I would do b) or c).
Just 2cents of ideas...
Christoph
Petermair Patrick wrote:
> Hi!
>
> We are using Velocity to create some reports that will be printed out. One
> report gets a list of customers and prints some data about them. I¹m now
> faced with the problem of writing a page header at the beginning of every
> page (that gets printed out). Something like:
>
> ³Page 23²
>
> and so on... Is there any support in Velocity to print some kind of header
> after a fixed amount of lines? I know how many lines a page can hold. The
> data per customer isn¹t static so I don¹t know how many lines each customer
> will take. So basically my textfile would look like this:
>
> Page 1
> <some data>
> <more data>
> Page 2
> <some more data>
> Page 3
> <even more data>
> <still more data>
> <more more data>
> Page 4
> ...
>
> Without the header I would simply output every customer in a ³for each²
> loop. But I need to tell Velocity somehow that it needs to print an extra
> line with some header data after every 80th line (for example).
>
> I was going through the documentation but I couldn¹t find anything that
> would help me do this ... any ideas?
>
> Thanks,
> Patrick
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: text output page header
Posted by Claude Brisson <cl...@renegat.net>.
You can use a custom buffered writer that would count output lines and
insert the appropriate headers.
Claude
On lun., 2009-06-22 at 17:41 +0200, Petermair Patrick wrote:
> Hi!
>
> We are using Velocity to create some reports that will be printed out. One
> report gets a list of customers and prints some data about them. I¹m now
> faced with the problem of writing a page header at the beginning of every
> page (that gets printed out). Something like:
>
> ³Page 23²
>
> and so on... Is there any support in Velocity to print some kind of header
> after a fixed amount of lines? I know how many lines a page can hold. The
> data per customer isn¹t static so I don¹t know how many lines each customer
> will take. So basically my textfile would look like this:
>
> Page 1
> <some data>
> <more data>
> Page 2
> <some more data>
> Page 3
> <even more data>
> <still more data>
> <more more data>
> Page 4
> ...
>
> Without the header I would simply output every customer in a ³for each²
> loop. But I need to tell Velocity somehow that it needs to print an extra
> line with some header data after every 80th line (for example).
>
> I was going through the documentation but I couldn¹t find anything that
> would help me do this ... any ideas?
>
> Thanks,
> Patrick
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org