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

[Bug]: Getting corrupt PDF document #144

Open
nhet opened this issue Jan 22, 2025 · 10 comments
Open

[Bug]: Getting corrupt PDF document #144

nhet opened this issue Jan 22, 2025 · 10 comments
Labels
bug Something isn't working

Comments

@nhet
Copy link

nhet commented Jan 22, 2025

df5e998c-5889-4c4b-8e50-05df6998856d.pdf

Reproducer

No response

Description

Hi there,
I build up a test env along this guide https://medium.com/the-sensiolabs-tech-blog/how-to-generate-a-pdf-file-in-a-few-lines-of-code-with-symfony-39786a679d29 . I get allways a corrupt PDF. If I use a blank template file the creation works. You find the corrupt file attached.

Gotenberg Version

8.15.3

Gotenberg Bundle Version

0.3.0

@nhet nhet added the bug Something isn't working label Jan 22, 2025
@Jean-Beru
Copy link
Contributor

Hi @nhet !

I opened your file with a text editor and saw some HTML at the end.

<!-- Warning: Undefined array key &quot;192.168.0.152&quot; (500 Internal Server Error) -->

Can you give us the corresponding logs ?

@nhet
Copy link
Author

nhet commented Jan 22, 2025

Ok,
the only log entry I have found inside symfony is:

[Wed Jan 22 13:25:39 2025] [critical] Uncaught PHP Exception ErrorException: "Warning: Undefined array key "192.168.0.152"" at NativeResponse.php line 82
The NativeResponse.php file is located in ./vendor/symfony/http-client/Response/

And the only place in the code where the IP is stored is the GOTENBERG_DSN configuration

###> sensiolabs/gotenberg-bundle ###
GOTENBERG_DSN=http://192.168.0.152:8890
###< sensiolabs/gotenberg-bundle ###

@Jean-Beru
Copy link
Contributor

Can you share us your configuration (config/packages/gotenberg.yaml or config/packages/framework.yaml) to check if the client is correctly configured ? Like in https://github.com/StevenRenaux/GotenbergBundle-Article/blob/main/config/packages/gotenberg.yaml

@nhet
Copy link
Author

nhet commented Jan 22, 2025

config/packages/gotenberg.yaml:

framework:
    http_client:
        scoped_clients:
            gotenberg.client:
                base_uri: '%env(GOTENBERG_DSN)%'

sensiolabs_gotenberg:
    http_client: 'gotenberg.client'
#    default_options:
#        pdf:
#            html:
#                metadata:
#                    Keywords: 'Symfony'

config/packages/framework.yaml

# see https://symfony.com/doc/current/reference/configuration/framework.html
framework:
    secret: '%env(APP_SECRET)%'
    annotations: false
    http_method_override: false
    handle_all_throwables: true
    default_locale: de

    # Enables session support. Note that the session will ONLY be started if you read or write from it.
    # Remove or comment this section to explicitly disable session support.
    session:
        handler_id: null
        cookie_secure: auto
        cookie_samesite: lax

    #esi: true
    #fragments: true
    php_errors:
        log: true

when@test:
    framework:
        test: true
        session:
            storage_factory_id: session.storage.factory.mock_file



@nhet
Copy link
Author

nhet commented Jan 22, 2025

Can you share us your configuration (config/packages/gotenberg.yaml or config/packages/framework.yaml) to check if the client is correctly configured ? Like in https://github.com/StevenRenaux/GotenbergBundle-Article/blob/main/config/packages/gotenberg.yaml

Some problem with the default gotenberg.yaml from your link / repro

@Jean-Beru
Copy link
Contributor

I reproduced this bug by editing Symfony\Component\HttpClient\HttpClient::create to force returning a NativeHttpClient. I need to investigate more to check if this bug is due to the NativeHttpClient.

FYI, the Symfony HttpClient chooses the best client to use depending on your machine. It prefers AmpHttpClient or CurlHttpClient over NativeHttpClient. So, you can install the curl extension to quickly solve your problem.

@nhet
Copy link
Author

nhet commented Jan 22, 2025

Wow, with curl extension the problem seems to be solved. thx @Jean-Beru

@Neirda24
Copy link
Contributor

Great to know it fixed it. @nhet : could you provide us the result of

$ composer show symfony/http-client

please ?

@nhet
Copy link
Author

nhet commented Jan 22, 2025

Find the information attached.

httpClient.Info.txt

@smnandre
Copy link
Contributor

After a quick look, It could be linked to an empty content length header (really not sure)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants