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

Undefined variable in ->getObjectsByType('EmbeddedFile') but there is an attachment inside given #740

Open
PrimeGhostDE opened this issue Oct 10, 2024 · 3 comments
Labels

Comments

@PrimeGhostDE
Copy link

  • PHP Version: 8.2
  • PDFParser Version: 2.11.0 (newest)

Description:

I have analyzed the bug so far, that there is a problem concerning embeddedFiles.

PDF input

Example pdf invoice.
Rechnung RE-202400282 vom 09.10.2024 zu Ihr Zeichen.pdf

Expected output & actual output

There is only one embedded File in it (please ignore why i use foreach here)

$pdfParser = new PdfParser();
$pdfParsed = $pdfParser->parseContent($pdfContent);
$filespecs = $pdfParsed->getObjectsByType('Filespec');

foreach ($filespecs as $filespec) {
  $filespecDetails = $filespec->getDetails();
  // Output:
  array:7 [
    "AFRelationship" => "Alternative"
    "Desc" => "ZUGFeRD 2.1 Rechnung"
    "EF" => array:1 [
      "F" => array:3 [
        "DL" => "22974"
        "Length" => "1871"
        "Subtype" => "text/xml"
      ]
    ]
    "F" => "factur-x.xml"
    "Subtype" => "text/xml"
    "Type" => "Filespec"
    "UF" => "factur-x.xml"
  ]
}

$pdfParsed->getObjectsByType('EmbeddedFile'); is not empty. so lets get the first embeddedFile
foreach ($embeddedFiles as $embeddedFile) {
  $embeddedFile->getContent(); // returns Undefined variable $embeddedFile
}

expected Output should be that the variable $embeddedFile is not undefined.

Code

see above :)

Kind regards

@PrimeGhostDE PrimeGhostDE changed the title Object Array is empty but there is an attachment inside given Undefined variable in ->getObjectsByType('EmbeddedFile') but there is an attachment inside given Oct 10, 2024
@k00ni k00ni added the bug label Oct 10, 2024
@PrimeGhostDE
Copy link
Author

Hi together,
is there something new to this?

@k00ni
Copy link
Collaborator

k00ni commented Nov 12, 2024

In your code the variable $embeddedFiles is never defined:

$pdfParsed->getObjectsByType('EmbeddedFile');
foreach ($embeddedFiles as $embeddedFile) {
  $embeddedFile->getContent(); // returns Undefined variable $embeddedFile
}

It should complain that $embeddedFiles is not defined. What happens when you do $embeddedFiles = $pdfParsed->getObjectsByType('EmbeddedFile') before the loop?

@k00ni k00ni added needs more info stale needs decision and removed bug labels Nov 12, 2024
@PrimeGhostDE
Copy link
Author

You are right.
I copied it to github without the assignment.
But it stays the same -> it does not work as expected.

$pdfParser = new PdfParser();
$pdfContent = file_get_contents(Storage::path($dokument->path . '/' . $dokument->filename));
$pdfParsed = $pdfParser->parseContent($pdfContent);
$embeddedFiles = $pdfParsed->getObjectsByType('EmbeddedFile');
dd($embeddedFiles); // returns array without any elements.

it does not get into the foreach.

@k00ni k00ni added bug and removed needs more info stale needs decision labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants