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

Mpdf - Getting "CrossReferenceException::OBJECT_NOT_FOUND" while trying to ImportPage from existing PDF file #1964

Open
1 task done
ali-assaabloy opened this issue Dec 1, 2023 · 4 comments

Comments

@ali-assaabloy
Copy link

ali-assaabloy commented Dec 1, 2023

Guidelines

Description of the bug

I'm trying to use the Mpdf to add the bookmarks in the existing PDF file and for that I wrote this code:

$mpdf = new Mpdf(['format' => [215.9, 279.4]]);
$pagecount = $mpdf->SetSourceFile('existingFileName.pdf');
for($i = 1; $i <= $pagecount; $i++){
	$mpdf->AddPage();

	$tplId = $mpdf->ImportPage($i);

	$mpdf->useTemplate($tplId);

	$mpdf->Bookmark("bookmark".$i, 0);
}

$mpdf->Output('newfile.pdf', 'F');

But for some pages I'm getting the "Object (id:38521) not found." on ImportPage() --> getImportedExternalPageLinks() --> PdfType::resolve($annotation, $parser); --> $parser->getIndirectObject($value->value) --> $this->getCrossReference()->getIndirectObject($objectNumber); :

$offset = $this->getOffsetFor($objectNumber);
        if ($offset === false) {
            throw new CrossReferenceException(
                \sprintf('Object (id:%s) not found.', $objectNumber),
                CrossReferenceException::OBJECT_NOT_FOUND
            );
        }

mPDF version

v8.2.2

PHP Version and environment (server type, cli provider etc., enclosing libraries and their respective versions)

8.1.0

Reproducible PHP+CSS+HTML snippet suffering by the error

$mpdf = new Mpdf(['format' => [215.9, 279.4]]);
$pagecount = $mpdf->SetSourceFile('existingFileName.pdf');
for($i = 1; $i <= $pagecount; $i++){
	$mpdf->AddPage();

	$tplId = $mpdf->ImportPage($i);

	$mpdf->useTemplate($tplId);

	$mpdf->Bookmark("bookmark".$i, 0);
}

$mpdf->Output('newfile.pdf', 'F');
@finwe
Copy link
Member

finwe commented Dec 1, 2023

  1. this is general troubleshooting
  2. you did not provide files to reproduce
  3. this looks like an issue of the underlying FPDI library

@finwe finwe closed this as completed Dec 1, 2023
@ali-assaabloy
Copy link
Author

existingFileName.pdf
Please find the file to reproduce it. I attached it while creating the issue, but no idea why it's not attached in the issue

@finwe
Copy link
Member

finwe commented Dec 1, 2023

The other two points still stand.

@ali-assaabloy
Copy link
Author

Hi, I have created the issue at FPDI(Setasign/FPDI#191) and they fixed it. But in Mpdf the code is not using the FPDI importExternalLinks, as it's set to false by default on fpdiImportPage:

public function importPage($pageNumber, $box = PageBoundaries::CROP_BOX, $groupXObject = true)
{
  $pageId = $this->fpdiImportPage($pageNumber, $box, $groupXObject);
  
  $this->importedPages[$pageId]['externalLinks'] = $this->getImportedExternalPageLinks($pageNumber);
  
  return $pageId;
}

and adding the external links through getImportedExternalPageLinks. Please see the fix "Setasign/FPDI@78d0f74#diff-a8561a849cdf24990e0606796ed216d1edd9632c9584cc4b618b69fadd597ad0"

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

No branches or pull requests

2 participants