PhpSpreadsheet icon indicating copy to clipboard operation
PhpSpreadsheet copied to clipboard

Missing pages in generated PDF and fitTo... without effect

Open GELight opened this issue 4 years ago • 3 comments

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

The hole tables of all sheets will rendered in a PDF.

What is the current behavior?

Example 1: If I have the cells A1 until Z1 with a value, in my generated PDF only the cells A1 until S1 (S1 is cutted off) will rendered. No more pages are generated. Example 2: Regardless of the settings in the page setup (setPrintArea, setFitToWidth, setFitToHeight) in the PDF there will not render all cells of my row again. Example 3: For testing I generate also an excel file. In the page break preview of Excel there I can see multiple print areas like below. If I open it and look into the print preview, the following pages will rendered as seperate pages. If I generate my PDF with PhpSpreadsheet then only the pages 1, 4 and 7 are rendered iside the PDF. (S1 is cutted off on each page)

#-------#-----#-----#
|   1   |  2  |  3  |
#-------#-----#-----#
|   4   |  5  |  6  |
#-------#-----#-----#
|   7   |  8  |  9  |
#-------#-----#-----#

What are the steps to reproduce?

This is my minimal example script where I tested all possible configurations etc ...

<?php

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Tcpdf;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;

include_once "vendor/autoload.php";

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
foreach (["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"] as $cell)
{
    $sheet->setCellValue($cell."1", $cell."1");
}
$sheet->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
$sheet->getPageSetup()->setPaperSize(PageSetup::PAPERSIZE_A4);
$sheet->getPageSetup()->setPrintArea('A1:Z1');
$sheet->getPageSetup()->setFitToWidth(1);
$sheet->getPageSetup()->setFitToHeight(0);

$id = uniqid();
$writerXlsx = new Xlsx($spreadsheet);
$writerXlsx->save(getcwd().DIRECTORY_SEPARATOR."temp/test-".$id.".xlsx");

$writerPdf = new Tcpdf($spreadsheet);
$writerPdf->save(getcwd().DIRECTORY_SEPARATOR."temp/test-".$id.".pdf");

Which versions of PhpSpreadsheet and PHP are affected?

Environment PHP 7.4

composer.json

"require": {
    "phpoffice/phpspreadsheet": "^1.18",
    "tecnickcom/tcpdf": "^6.4"
}

Output of my PDF (screenshot): image

Only in PDF "NO MORE" pages available. Page setup for fit To... or using printArea has no effect

I cannot find any help in documentation.

Best regards, Mario

GELight avatar Oct 27 '21 10:10 GELight

Seems like 3 years later the only option for a Pdf export still is "random cutout". Any page setting other than orientation and paperSize is ignored. Is there a way to work around this? Is there a trick to specify what to print?

dennismuench avatar Oct 21 '24 11:10 dennismuench

I believe you will get the desired result with Mpdf, but not, as reported, with Tcpdf, nor with Dompdf. Mpdf recognizes and acts on the CSS tags which we use to achieve this; the other two do not. If you can think of a different way to accomplish this for the others, let us know.

We have not yet figured out how to implement PrintArea for Html/Pdf. See issue #3941. It's on my to-do list, but I haven't made much progress.

oleibman avatar Oct 21 '24 22:10 oleibman

@oleibman Thank you for the hint. I should have tried Mpdf. That works so much better. I tested every other converter and the outputs all looked very similar, so I thought it was a config/general problem.

dennismuench avatar Oct 22 '24 02:10 dennismuench

Issue mostly resolved; remainder is a duplicate of #3941. Closing.

oleibman avatar Aug 12 '25 23:08 oleibman