Jump to content
  • Improve JRPrintPage

    Assigned User teodord
    CategoryFeature request

    Original issue moved from:



    Consult the original issue for any attachments.


    [ 1462955 ] improve JRPrintPage


    Submitted By: Code_Slave - code_slaveAccepting Donations

    Date Submitted: 2006-04-02 01:26

    Last Updated By: code_slave - Comment added

    Date Last Updated: 2006-04-04 02:08

    Number of Comments: 1

    Number of Attachments: 0


    Assigned To: Nobody/Anonymous

    Priority: 5



    improve JRPrintPage


    Dear teodord,


    maybe there is an easy solution to sending faxes/ separate pages. if we let jasper report render the pages and produce a JasperPrint list (this gets round having to do multiple report runs) we can use JRPrintPage thepage= jpPrint.removePage(int) ;

    to get a page. that page then contains a list of all the elements. all we would need is a "accessor" to recover the name of the fields so we could use something like




    which could return the variable names and a positon within the Elements of "thepage" ( not the detail band as it is itterated)


    so when filling the report with a parameter calles "$P{FAXNUMBER}" when the report has finished filling we can do this (eg):


    jpPrint = JasperFillManager.fillReport(PreCompiledReport_is, parameterHashmap, ourCustomDataSource);


    JRPrintPage thepage= jpPrint.removePage(0) ; //get a page Map Variablenames=thepage.GetVariableHashmap(); //new function


    int faxpos=Variablenames.GetObject("FAXNUMBER"); //get the index


    list Elements=thepage.getElements(); //recover the elements


    String Faxnumber= Elements(faxpos); //get the faxnumber


    pass "thepage" to the pdf routine & the recoverd fax number.



    this would allow coders to recover the actual position of data on a physical report without knowing the specifics of where it actually is, or how it was rendered. (for the actual detail band it would be different as the data would be nested), but is should be ok for header /footers or other single area bands.





    Date: 2006-04-04 02:08

    Sender: code_slaveAccepting Donations

    Logged In: YES



    O.K i have it cracked , we just need some accessor functions, perhaps 5, to reduce the current code down to a few lines


    we would need:


    getAnchorIndexes(), added to a JRPrintPage, so that we could get the Anchor

    indexes for a page, instead of a full document.


    .size() or lenght() added to JasperPrint, to recover the number

    of pages


    .getAnchorIndexes() , we should be able to get a map or a

    hashmap, to

    prevent the need to generate a separate hashmap, as in:

    Map pageAnchorIndexes = TempSinglePage.getAnchorIndexes();

    // get the

    anchored indexes.

    HashMap PageObjects = new HashMap(pageAnchorIndexes); //

    convert it to

    a hashmap


    also we could do with accessor methods for a JRPrintPage







    currently to recover a report field data item you have to:


    tag the field with an "Anchorindex" to identify the item you need then take the completted JasperPrint document convert to a List (to get the page count) then get a single page JRPrintPage from the List then add the single page back to a new JasperPrint !!, to access a Map .getAnchorIndexes() then convert the Map to a Hashmap, which allows you to search on the "keys"


    Then the following code can get the data from the actual page of the actual

    document (where it has been tagged with an Anchorindex)

    List WorkingCopy = TheReport.getPages(); // make a working

    copy so we

    do not bugger up the orig.


    pagecount = WorkingCopy.size(); // WHY MUST I make a

    copy of a

    document to get the number of pages!!


    if (pagecount != 0) {

    for (int pageloop = 0; pageloop < pagecount;

    pageloop++) {

    JRPrintPage SinglePage =

    (JRPrintPage) WorkingCopy.get(pageloop);

    // get a page (why

    can I not get a page directly!!)


    TempSinglePage = new JasperPrint();


    Map pageAnchorIndexes =


    // get the anchored indexes.

    HashMap PageObjects = new

    HashMap(pageAnchorIndexes); //

    convert it to a hashmap

    if (PageObjects.containsKey("FAXNUMBER")) {

    JRPrintAnchorIndex pp =



    JRPrintElement zz = pp.getElement();


    if (zz instanceof JRTemplatePrintText) {

    Faxno = ((JRTemplatePrintText)


    if (Faxno.equals(PreviousFaxNumber)) {


    // add it to a new


    } else {


    // Do some mickymouse setup stuff ,

    so it does not blow


    // why can we just not pass in the

    page info from


    if (Start == false) {




    PreviousFaxNumber = Faxno; //

    setup our compare



    // add it to a new


    Start = false; // flag to ensure

    first document is complete

    before sending it


    } else {


    // it is not an instance of a textfield





    processit(); // to ensure the last document is

    sent when we exit the


    } else {


    // no pages in the report!!





    it would be nice if we could just get the current page count from a JasperPrint, then recover a page from JasperPrint, then recover a hashmap from the page of the page Anchors.


    however doing this we can now process say 1,000 form letters, & visiting the database & jasperreports once, instead of looping. Then splitting up the resultant document before feeding it to the pdf/ other export routines.


    No Files Currently Attached

    User Feedback

    Recommended Comments



    I think nowadays this is easily achievable with custom element properties or generic element support.


    Closing as fixed.


    Thank you,


    Link to comment
    Share on other sites

  • Create New...