Skip to content

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

New issue

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

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

Already on GitHub? Sign in to your account

Open
GELight opened this issue Oct 27, 2021 · 3 comments
Open

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

GELight opened this issue Oct 27, 2021 · 3 comments

Comments

@GELight
Copy link

GELight commented Oct 27, 2021

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 GELight changed the title Missing pages in generated PDF Missing pages in generated PDF and fitTo... without effect Oct 27, 2021
@dennismuench
Copy link

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
Copy link
Collaborator

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants