Jump to content
We've recently updated our Privacy Statement, available here ×

alestar

Members
  • Posts

    10
  • Joined

  • Last visited

Community Answers

  1. alestar's post in How to change page sizing/format when load and existing template into JasperDesign and then changed it? was marked as the answer   
    Hello and thanks for the quick answer. I couldn't find how to comment on you answer so I guess I will have to include it in this post.
     
    First, you were right about not guaranteeing the whole page layout resizing, by just changing the de page dimensions. However, the formats that I was changing to, were very similar (A4 and LETTER), so the impact on the components and fields size perse, was not that big. 
    Moreover, what I have to do, to actually change every single individual's page of the book format, was loading every single individual page first into a JasperDesing Object holder and next save it , with the modified size into a jasper field, that will be used in the fillup process. Instead of just doing that for the Report Book page itself.
     
    Here is the code:
    private static JasperDesign getPageTemplateDesign(String templatePath) throws JRException{
     
    logger.info("Setting format page desing for Template: " + templatePath);
     
    JasperDesign design = JRXmlLoader.load(templatePath);
     
    logger.info("Setting Page Dimessions Format to: " + pageFormat);
    if (JRDriver.pageFormat.equals("A4")) {
    JRDriver.pageWidth=595; 
    JRDriver.pageHeight=842;
    JRDriver.columnCount=1;
    JRDriver.columnWidth=555;
    JRDriver.columnSpacing=0;
    JRDriver.leftMargin=20;
    JRDriver.rightMargin=20;
    JRDriver.topMargin=20;
    JRDriver.bottomMargin=20;
    }
    else if (JRDriver.pageFormat.equals("LETTER")) {
    JRDriver.pageWidth=612; 
    JRDriver.pageHeight=792;
    JRDriver.columnCount=1;
    JRDriver.columnWidth=517;
    JRDriver.columnSpacing=0;
    JRDriver.leftMargin=20;
    JRDriver.rightMargin=20;
    JRDriver.topMargin=20;
    JRDriver.bottomMargin=20;
    }
    //Setting twmplate dimesions
    design.setPageWidth(JRDriver.pageWidth);
    design.setPageHeight(JRDriver.pageHeight);
     
    design.setColumnCount(JRDriver.columnCount);
    design.setColumnWidth(JRDriver.columnWidth);
    design.setColumnSpacing(JRDriver.columnSpacing);
     
    design.setLeftMargin(JRDriver.leftMargin);
    design.setRightMargin(JRDriver.rightMargin);
    design.setTopMargin(JRDriver.topMargin);
    design.setBottomMargin(JRDriver.bottomMargin);
     
    return design;
    }
     
    private static void reformattingPageTemplate(String path) throws JRException{
     
    logger.info("Getting Design Template from: " + path);
    JasperDesign design= getPageTemplateDesign(path);
     
    String destFile=path.replaceAll("jrxml", "jasper");
    logger.info("Compiling Re-formated Design Template to: " + destFile);
    JasperCompileManager.compileReportToFile(design, destFile);
    }
     
    private static void formattingALLPage() throws JRException{
     
    reformattingPageTemplate(reportBookPagesDir + "/FrontCover.jrxml");
    reformattingPageTemplate(reportBookPagesDir + "/Copyright.jrxml");
    reformattingPageTemplate(reportBookPagesDir + "/TableOfContent.jrxml");
    reformattingPageTemplate(reportBookPagesDir + "/Summary.jrxml");
    reformattingPageTemplate(reportBookPagesDir + "/Content.jrxml");
    reformattingPageTemplate(reportBookPagesDir + "/AppendixWarnings.jrxml");
    reformattingPageTemplate(reportBookPagesDir + "/Index.jrxml");
    reformattingPageTemplate(reportBookPagesDir + "/BackCover.jrxml");
    //reformattingPageTemplate(reportTemplatePath);
    }
     
     
    Thanks for all the help! ;)
  2. alestar's post in How to pass DataSource from Main Report to sub-report, located on the detail part section, of the main report was marked as the answer   
    Sorry, it took me a long time to post back.

    I find a solution after Theodor (Jasper API main author give me some insights) and here is it! So, for the Jasper Report engine to handle multiple data sources passed to the report, you have to take into account 2 essential things:

    First, for every data source that you want to pass to the Report, you will need to create a new instance. Jasper engine consumes each data source iterating over all the elements in it. When it gets to the next page, there won't be any data, fields or information to read from and fill up the fields on that particular page. Therefore, information won't show up (null) or "blank", depending on the report template configuration.

    Last, make sure you pass a new JREmptyDataSource() when filling the report and pass the data sources instance as parameters, and later as sub-parameters for each individual page. Like this

     

    jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter,new JREmptyDataSource() );
    [/code]
     

    That way main report, or the wrapping report (the book), does not use any data source of the pages instances (if it does not need it, of course) and each page will get a data source, through the parameters.

    Ultimately, on runtime, it the page of the book can consume individually each data source without affecting each other.

    Let me know if this makes any sense? Thanks

     

  3. alestar's post in Would anyone explain me how to add a data source to a "part" of a Report Book? was marked as the answer   
    Sorry, it took me a long time to post back.
    I find a solution after Theodor (Jasper API main author give me some insights) and here is it! So, for the Jasper Report engine to handle multiple data sources passed to the report, you have to take into account 2 essential things:
    First, for every data source that you want to pass to the Report, you will need to create a new instance. Jasper engine consumes each data source iterating over all the elements in it. When it gets to the next page, there won't be any data, fields or information to read from and fill up the fields on that particular page. Therefore, information won't show up (null) or "blank", depending on the report template configuration.
     
    Last, make sure you pass a new JREmptyDataSource() when filling the report and pass the data sources instance as parameters, and later as sub-parameters for each individual page. Like this:
     
    jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter,new JREmptyDataSource() );[/code]That way main report, or the wrapping report (the book), does not use any data source of the pages instances (if it does not need it, of course) and each page will get a data source, through the parameters.
    Ultimately, on runtime, it the page of the book can consume individually each data source without affecting each other. 
    Let me know if this makes any sense? Thanks
×
×
  • Create New...