PHPOffice / PhpSpreadsheet

A pure PHP library for reading and writing spreadsheet files
https://phpspreadsheet.readthedocs.io
MIT License
13.34k stars 3.46k forks source link

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

Open GELight opened 3 years ago

GELight commented 3 years ago

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

dennismuench commented 2 weeks ago

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?

oleibman commented 2 weeks ago

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.

dennismuench commented 2 weeks ago

@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.