Stefan,

what you're trying to do is not trivial. You can theoretically get the
number of pages in the XMLHandler code like this:

PageViewport page = (PageViewport) context.getProperty(PAGE_VIEWPORT);
int pageCount = page.getPageSequence().getPageCount();

....BUT there is absolutely no guarantee that the number of pages is
correct. Actually, I think it will be wrong in many cases since pages
can still be added to the PageSequence area tree object at the point the
XMLHandler is thrown into action.

The PageNumberCitationLayoutManager can insert an UnresolvedPageNumber
area tree object into the area tree. UnresolvedPageNumber implements
Resolvable. Maybe something could be done with this interface but I'm
not sure without going deeper.

Let me just say that I'm usually post-processing the print files if I
have to add packaging marks (like OMR etc.). That would certainly be
easier to implement and provides options for parallelizing document
production as FOP is usually the most CPU-eating part of the chain.

BTW, what's that barcode you're implementing?

On 25.05.2007 11:36:08 Stefan.Haberl wrote:
> Hi,
> 
> I have to generate a special barcode on every rendered page for a mass 
> printing facility, essentially so that the printed pages end up in the 
> correct envelope for postage. 
> 
> To this end I've written a custom BarcodeObj class (subclass of 
> org.apache.fop.fo.XMLObj) to represent the barcode in the area trea and a 
> BarcodeElementMapping to register a new barcode tag, which I can use 
> within my fo files. A BarcodeXmlHandler class which implements the 
> org.apache.fop.render.XMLHandler interface is responsible for rendering 
> the barcode itself.
> 
> So far everything works nicely, however I've the problem, that I have to 
> know at the rendering stage, whether a page is the last within a 
> PageSequence so that I can render a dedicated "end bit" in the barcode. 
> How do I know, that a page is the last one within a sequence? I tried the 
> ref-id approach as described in the doc for my fo file, but how do I read 
> the value of the ref-id in my XMLHandler class?
> 
> 
> The relevant fo part:
> ...
> <fo:instream-foreign-object>
>   <boewe:barcode fo:ref-id="last-page"/>
> </fo:instream-foreign-object>
> 
> ... (at the end of the flow)
> <fo:block id="last-page"/>
> 
> 
> 
> The relevant code in BarcodeXmlHandler:
> 
> public class BarcodeXMLHandler implements XMLHandler, 
> RendererContextConstants {
> 
>   public void handleXML(RendererContext context, Document doc, String ns) 
> throws Exception {
> 
>     PageViewport page = (PageViewport) context.getProperty(PAGE_VIEWPORT);
>     int pageNumber = page.getPageNumber();
>  
>     /* TODO: How to get total number of pages within the page sequence? */
> 
>     ...
>   }
> }
> 
> 
> Thanks for any help,
> Stefan


Jeremias Maerki


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to