velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: text output page header
Date Mon, 22 Jun 2009 16:03:41 GMT

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 )
     ## emit the text
     #set( $lineNr = $lineNr + 1 )
     ## or do something more sophisticated to count the lines...
   ## 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...

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:
For additional commands, e-mail:

View raw message