Skip to content

On Windows $pdf->getDataFields() fails because the command adds double-quotes around "A" handle when php runs in PowerShell #336

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

Closed
olignyf opened this issue May 11, 2025 · 4 comments

Comments

@olignyf
Copy link

olignyf commented May 11, 2025

Reproduces only running in PowerShell or Visual Studio Code (which uses PowerShell for its Terminal). Under cmd it is fine.

When it executes

$pdf->getDataFields();

Underneath the command ran is

pdftk "A"="C:/Users/Domino/AppData/Local/Temp/t21F908.tmp.pdf" dump_data_utf8 

Which fails with

Error: Unable to find file.
Error: Failed to open PDF file:
   A
Error: Unable to find file.
Error: Failed to open PDF file:
   =C:/Users/Domino/AppData/Local/Temp/t21F908.tmp.pdf
Done.  Input errors, so no output created.

But if I manually remove the double quotes around the "A" like this it would works:

pdftk A="C:/Users/Domino/AppData/Local/Temp/t21F908.tmp.pdf" dump_data_utf8   
InfoBegin
InfoKey: Creator
InfoValue: Designer 6.3
InfoBegin
(...)

Note that I'm running php inside Visual Studio Code which uses PowerShell. If I would use cmd it would work.

@olignyf olignyf changed the title On Windows $pdf->getDataFields() fails because the command adds double-quotes around "A" handle On Windows $pdf->getDataFields() fails because the command adds double-quotes around "A" handle when php runs in PowerShell May 11, 2025
@mikehaertl
Copy link
Owner

This was probably caused by this fix in the underlying php-shellcommand:
mikehaertl/php-shellcommand#44

TBH I'm not sure how to fix it and I'm also not using windows. Suggestions?

@jjdunn
Copy link

jjdunn commented May 12, 2025

I'm using cmd and have never encountered this problem. Is it required to use PowerShell ?

alternately, there's an option in Command escapeArgs which defaults to true. if this value is set to false then the "A" is not double-quoted. This would seem to solve the problem.

edit: I just stepped through the code on my system. the double-quotes around the "A" are added in Command::addArg() line 309 : $argKey = $doEscape ? escapeshellarg($argKey) : $argKey;

@mikehaertl
Copy link
Owner

mikehaertl commented May 12, 2025

alternately, there's an option in Command escapeArgs which defaults to true. if this value is set to false then the "A" is not double-quoted. This would seem to solve the problem.

Yeah, that's an option. But you may run into problems if your filenames contain spaces (or other potentially critical chars). If you can ensure that this is not the case it should be safe to use 'escapeArgs' => false.

@olignyf
Copy link
Author

olignyf commented May 14, 2025

Thanks for the quick replies. After retrying to reproduce the issue to try a fix I cannot reproduce the issue anymore. It was another error in my application and when I inspected the command line generated internally to see what was wrong and tried it manually I had the error in PowerShell but not in cmd, and assumed the same was occurring in the php runtime. But my error was reusing twice the same Pdf object (can only be used once).

Sorry for the trouble!

@olignyf olignyf closed this as completed May 14, 2025
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

No branches or pull requests

3 participants