wkhtmltopdf, 0.12.6, Warning: Blocked access to file

前端 未结 5 811
耶瑟儿~
耶瑟儿~ 2020-12-20 11:02

When upgrade wkhtmltopdf to 0.12.6, it came to such messages and the image did not show in the target pdf:

    Warning: Blocked acc         


        
相关标签:
5条回答
  • 2020-12-20 11:32

    This is caused by the change of default behavior in version 0.12.6 of wkhtmltopdf. wkhtmltopdf disables local file access by default now. It could be solved by adding the command line parameter

    --enable-local-file-access
    

    or the combination

    --disable-local-file-access --allow <path>
    
    0 讨论(0)
  • 2020-12-20 11:33

    For those that are using laravel-snappy, add the 'enable-local-file-access' option in the config\snappy.php:

    'pdf' => [
            'enabled' => true,
            'binary'  => env('WKHTML_PDF_BINARY', '/usr/local/bin/wkhtmltopdf'),
            'timeout' => false,
            'options' => [
                'enable-local-file-access' => true,
                'orientation'   => 'landscape',
                'encoding'      => 'UTF-8'
            ],
            'env'     => [],
        ],
    
        'image' => [
            'enabled' => true,
            'binary'  => env('WKHTML_IMG_BINARY', '/usr/local/bin/wkhtmltoimage'),
            'timeout' => false,
            'options' => [
                'enable-local-file-access' => true,
                'orientation'   => 'landscape',
                'encoding'      => 'UTF-8'
            ],
            'env'     => [],
        ],
    

    wkhtmltopdf disables local file access by default in the 0.12.6 version

    0 讨论(0)
  • 2020-12-20 11:48

    in my case, I put "enable-local-file-access": "", in options, it worked.

    0 讨论(0)
  • 2020-12-20 11:54

    Just bumping this thread with a correction in case you're still getting the same error in spite of using:

    --enable-local-file-access
    

    For some reason, this cmd line argument does not work when being specified after input/output files, you have to write this argument right after wkhtmltopdf.exe.

    So

    wkhtmltopdf.exe --enable-local-file-access input.html output.pdf
    

    instead of other variants.

    0 讨论(0)
  • 2020-12-20 11:56

    For the C API, contrary to what the documentation says, it's not load.blockLocalFileAccess but loadPage.blockLocalFileAccess that you must set to "false":

    wkhtmltoimage_set_global_setting(settings, "loadPage.blockLocalFileAccess", "false");
    

    Hopefully, the documentation will be updated soon; see issue #4763.

    0 讨论(0)
提交回复
热议问题