PHPReport icon indicating copy to clipboard operation
PHPReport copied to clipboard

How to set the papersize of PDF output in PHPReport?

Open Amamatthew opened this issue 8 years ago • 3 comments

Sometimes there's a extra width with too many table columns we need to specify the papersize property for the PDF output.

Amamatthew avatar Jul 19 '16 03:07 Amamatthew

Yes, proper way is to add those properties as configurable parameters, becouse currently it's set to A4 source

vernes avatar Jul 19 '16 07:07 vernes

If you want to change it yourself in the code, you can add any value supported by phpexcel found here

vernes avatar Jul 19 '16 07:07 vernes

YES. I pass the arguments to the __construct() later: $R=new PHPReport(array("PaperSize"=>64));

/**
 * Creates new report with some configuration parameters
 * @param array $config 
 */
public function __construct($config=array())
{
    $this->setConfig($config);
    if(!empty($this->_PaperSize)){
        $this->init($this->_PaperSize);
    }else{
        $this->init("default");
    }
}
/**
 * Initializes internal objects 
 */
private function init($_PaperSize)
{
    if($this->_template!='')
    {
        $this->loadTemplate();
    }
    else
    {
        $this->createTemplate($_PaperSize);
    }
}

/**
 * Creates PHPExcel object and template for report
 */
private function createTemplate()
{
    $this->objPHPExcel = new PHPExcel();
    $this->objPHPExcel->setActiveSheetIndex(0);
    $this->objWorksheet = $this->objPHPExcel->getActiveSheet();
    //TODO: other parameters    
    $this->objWorksheet->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);

    if("default"==$this->_PaperSize){
        $this->objWorksheet->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
    }else{
        $this->objWorksheet->getPageSetup()->setPaperSize($this->_PaperSize);
    }
    $this->objWorksheet->getPageSetup()->setHorizontalCentered(true);
    $this->objWorksheet->getPageSetup()->setVerticalCentered(false);
    $this->_usingTemplate=false;
}

Amamatthew avatar Jul 20 '16 01:07 Amamatthew