wkhtmltopdf ContentNotFoundError, code 1
Asked Answered
W

2

8

I am trying to generate a basic pdf with the wkhtmltopdf phpwrapper. I am also using the yii framework.

This is my HTML:

<!doctype html>
<html>
    <head>
    </head>

    <body> 
            <p>test</p>
    </body>
</html>

My Settings in wktmltopdf:

$pdfParams = array(

            'header-html' => $this->tmpHeaderFile->getFileName(),
            'footer-html' => $this->tmpFooterFile->getFileName(),

            'username' => 'myUser',
            'password' => 'myPass',
        );
 $this->pdf = new Pdf($pdfParams);

The error im getting:

Exception 'Exception' with message 'Could not create PDF: Loading pages (1/6)
[>                                                           ] 0%
[======>                                                     ] 10%
[==============================>                             ] 50%
[============================================================] 100%
Counting pages (2/6)                                               
[============================================================] Object 1 of 1
Resolving links (4/6)                                                       
[============================================================] Object 1 of 1
Loading headers and footers (5/6)                                           
[===>                                                        ] 5%
[======>                                                     ] 10%
[======>                                                     ] 10%
[=======>                                                    ] 13%
[==========>                                                 ] 17%
[==================================>                         ] 57%
[====================================>                       ] 61%
Warning: Failed to load https://work.mydomain.com/devs/florian/web//devs/florian/web/themes/css/report-footer.css (ignore)
[============================================================] 100%
Printing pages (6/6)                                               
[>                                                           ] Preparing
[============================================================] Page 1 of 1
Done                                                                      
Exit with code 1 due to network error: ContentNotFoundError'

Any idea what the problem is?

Wainscot answered 24/8, 2017 at 15:7 Comment(0)
D
2

I have faced similar issues before. When working with wkhtmltopdf, you need to ensure all your static assets are added to the HTML file.

For example: CSS files, use internal style sheets:

<!doctype html>
<html>
    <head>
       <style>
           html {
               margin: 0;
           }
       </style>
    </head>

    <body> 
            <p>test</p>
    </body>
</html>

For javascript files, add script directly into HTML file as well.

<!doctype html>
<html>
    <head>
       <script type="text/javascript">
          var body = document.querySelector('body');
       </script>
    </head>

    <body> 
            <p>test</p>
    </body>
</html>

I hope this helps

Dobsonfly answered 19/12, 2017 at 5:11 Comment(0)
T
0

I know I'm late here, but for future readers: in my case there was a broken link in a header template. Then when wkhtmltopdf tries to load that, it breaks...

So, I would check for broken links in:

'header-html' => $this->tmpHeaderFile->getFileName(),
'footer-html' => $this->tmpFooterFile->getFileName(),
Trotskyism answered 27/11, 2020 at 17:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.