Crystal Reports for Eclipse Developer Guide

To set a page margin condition formula in the report's print options

  1. Use the PrintOutputController to retrieve and instance of the PrintOptions object saved with the report.
      PrintOutputController printOutputController = clientDoc.getPrintOutputController();
      IPrintOptions printOptions = printOutputController.getPrintOptions();
    
  2. Clone the PrintOptions object.
       IPrintOptions newPrintOptions = (PrintOptions)((PrintOptions)printOptions).clone(true);
    
  3. Retrieve the PageMargins object.
       IPageMargins newMargins = newPrintOptions.getPageMargins();
    
  4. Create a new PageMarginConditionFormulas and IConditionFormula object.
      PageMarginConditionFormulas formulas = new PageMarginConditionFormulas();
      IConditionFormula condFormula = new ConditionFormula();
    
  5. Set the formula syntax and text.
      String formulaText = "If Remainder(pagenumber,2) = 0 then 1440 else 2880";
      condFormula.setSyntax(FormulaSyntax.crystal);
      condFormula.setText(formulaText);
      formulas.setFormula(PageMarginConditionFormulaType.left, condFormula);
    
  6. Set the formulas in the PageMargins object and set the new margins in thePrintOptions object.
      newMargins.setPageMarginConditionFormulas(formulas);
      newPrintOptions.setPageMargins(newMargins);
    
  7. Use the PrintOutputController to modify the print options of the report.
      printOutputController.modifyPrintOptions(newPrintOptions);
    
Example: 
This sample creates a formula that checks whether a page number is even or odd and sets the margins accordingly: if the page is an even number, the margin is set to one inch; if the page is an odd number, the margin is set to two inches. The formula is applied to the left margin of the report.
void SetPageMarginFormula(ReportClientDocument clientDoc)
{
  PrintOutputController printOutputController = clientDoc.getPrintOutputController();
  IPrintOptions printOptions = printOutputController.getPrintOptions();
  IPrintOptions newPrintOptions = (PrintOptions)((PrintOptions)printOptions).clone(true);
  
  IPageMargins newMargins = newPrintOptions.getPageMargins();
  
  PageMarginConditionFormulas formulas = new PageMarginConditionFormulas();
  IConditionFormula condFormula = new ConditionFormula();

  String formulaText = "If Remainder(pagenumber,2) = 0 then 1440 else 2880";
  condFormula.setSyntax(FormulaSyntax.crystal);
  condFormula.setText(formulaText);
  formulas.setFormula(PageMarginConditionFormulaType.left, condFormula);
 
  newMargins.setPageMarginConditionFormulas(formulas);
  newPrintOptions.setPageMargins(newMargins);
  
  printOutputController.modifyPrintOptions(newPrintOptions);
}



SAP BusinessObjects
http://www.sap.com/sapbusinessobjects/
Support services
http://service.sap.com/bosap-support/
Product Documentation on the Web
http://help.sap.com/