0

I have the following code:

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
$sheet->getPageMargins()
    ->setLeft(0.1)
    ->setRight(0.1)
    ->setTop(0.1)
    ->setBottom(0.1)
    ->setHeader(0);
$sheet->setCellValue('A1', 'Test input');

$writer = new Mpdf($spreadsheet);
$dateStamp = Carbon::now()->format('YmdHis');
$saveDirectory = REPORTS_DIR . Auth::user()->getAuthIdentifier() . '/';
if (is_dir($saveDirectory) === false) {
    mkdir($saveDirectory, 755, true);
}
$writer->save($saveDirectory . $dateStamp . '-global.pdf');

The margines aren't being set correctly. I have set it to huge number and tiny numbers (as above) and none of them update the printed pdf document. When I swop out the Mpdf writer for an Xlsx writer, the margins work and when I change it, it updates the spreadsheet accordingly.

Is there some other way that I need to set the margins for it to update on the pdf size?

Bird87 ZA
  • 2,313
  • 8
  • 36
  • 69

2 Answers2

0

I see this is not supported currently in the library. I've created a pull request with the code to get this to work (tested by myself, there's no tests for this class).

Once this is merged, you will be able to use the code above to achieve this.

Bird87 ZA
  • 2,313
  • 8
  • 36
  • 69
0

2022, this is the way to archive the margin, thanks to pull request of @Bird87-za

$spreadsheet->getActiveSheet()->getPageMargins()->setTop(0.748);
$spreadsheet->getActiveSheet()->getPageMargins()->setRight(0.7);
$spreadsheet->getActiveSheet()->getPageMargins()->setLeft(0.7);
$spreadsheet->getActiveSheet()->getPageMargins()->setBottom(0.7);

// HEADER Y FOOTER
$spreadsheet->getActiveSheet()->getPageMargins()->setHeader(0.3);
$spreadsheet->getActiveSheet()->getPageMargins()->setFooter(0.3);

Ale DC
  • 1,646
  • 13
  • 20