Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to set the papersize of PDF output in PHPReport? #13

Open
Amamatthew opened this issue Jul 19, 2016 · 3 comments
Open

How to set the papersize of PDF output in PHPReport? #13

Amamatthew opened this issue Jul 19, 2016 · 3 comments

Comments

@Amamatthew
Copy link

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

@vernes
Copy link
Owner

vernes commented Jul 19, 2016

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

@vernes
Copy link
Owner

vernes commented Jul 19, 2016

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

@Amamatthew
Copy link
Author

Amamatthew commented Jul 20, 2016

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;
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants