Skip to content
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

Bugfix - Type resolve missing for nested pages in structure #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

denikod
Copy link

@denikod denikod commented Dec 19, 2024

I found a bug in the code when working with PDF files that have a complex nested page structure.

Screenshot of an example structure

On the left is a complex structure that causes an error
On the right is a normal one

pdf-complex-nested

Which caused the following error:
Fatal error: Uncaught exception 'setasign\Fpdi\PdfParser\Type\PdfTypeException' with message 'Array value expected.'

The proposed commit fixes this bug.

@JanSlabon
Copy link
Member

Great catch and I really wonder why this issue was not triggered before. Can you share the PDF in question? There's already a test document for a name tree:

$path . '/10000_with-tree.pdf',

...but yours seems to be structured differently.

@denikod
Copy link
Author

denikod commented Dec 25, 2024

Can you share the PDF in question?

Hello,
Sorry for delay with response...
I cannot provide the exact document that caused the issue, but after some manipulations, I created an identical document with the same problem.
I have attached the problematic document here:
PDF-complex-structure.pdf

Example of PHP code causing an error
<?php

use setasign\Fpdi\Fpdi;

require_once('fpdf/fpdf.php');
require_once('fpdi/src/autoload.php');

class Pdf {

	function generatePreview($file)
	{
		$pdf = new FPDI();
		
		$pdf_handle = fopen($file, 'rb');
		$pageCount = $pdf->setSourceFile($pdf_handle);

		$max = min(5, $pageCount);

		for ($i=1; $i <= $max; $i++)
		{
			//  Add page to the document
			$templateID = $pdf->importPage($i);

			$pdf->addPage();
			$pdf->useTemplate($templateID);
		}

		$pdf_content = $pdf->Output('S');

		header("Content-type:application/pdf");
		echo $pdf_content;

		fclose($pdf_handle);

		return;
	}
}

$pdf = new Pdf();
$pdf->generatePreview("PDF-complex-structure.pdf");

I hope I've contributed to the growth of this wonderful library! 😊
🎄 Merry Christmas!

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

Successfully merging this pull request may close these issues.

2 participants