Jump to content
  • Improve JRPrintPage


    tcloonan
    Assigned User teodord
    CategoryFeature request
    PriorityLow
    ReproducibilityAlways
    ResolutionFixed
    SeverityTrivial
    StatusClosed

    Original issue moved from:

    https://sourceforge.net/tracker/index.php?func=detail&aid=1462955&group_id=36382&atid=416706

     

    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

     

    Summary:

    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

     

    thepage.GetVariableHashmap();

     

    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.

     

     

    Comments

     

    Date: 2006-04-04 02:08

    Sender: code_slaveAccepting Donations

    Logged In: YES

    user_id=413743

     

    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

    getPageHeight()

    getPageWidth()

    getOrientation()

    getDefaultStyle()

    getDefaultFont()

     

    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();

    TempSinglePage.addPage(SinglePage);

    Map pageAnchorIndexes =

    TempSinglePage.getAnchorIndexes();

    // get the anchored indexes.

    HashMap PageObjects = new

    HashMap(pageAnchorIndexes); //

    convert it to a hashmap

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

    JRPrintAnchorIndex pp =

    (JRPrintAnchorIndex)

    PageObjects.get("FAXNUMBER");

    JRPrintElement zz = pp.getElement();

     

    if (zz instanceof JRTemplatePrintText) {

    Faxno = ((JRTemplatePrintText)

    zz).getText();

    if (Faxno.equals(PreviousFaxNumber)) {

    newDocument.addPage(SinglePage);

    // add it to a new

    report

    } else {

     

    // Do some mickymouse setup stuff ,

    so it does not blow

    up

    // why can we just not pass in the

    page info from

    JRPrintPage?

    if (Start == false) {

    processit();

    }

    startNewDocument(TheReport);

    PreviousFaxNumber = Faxno; //

    setup our compare

    strings

    newDocument.addPage(SinglePage);

    // add it to a new

    report

    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

    loop

    } 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

    Hi,

     

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

     

    Closing as fixed.

     

    Thank you,

    Teodor

    Link to comment
    Share on other sites


×
×
  • Create New...