【问题标题】:wkhtmltopdf how to set caching of html footer and header?wkhtmltopdf 如何设置 html 页脚和页眉的缓存?
【发布时间】:2019-03-20 08:28:44
【问题描述】:

测试 wkhtmltopdf 以生成巨大的 pdf 报告。 最后的pdf大约有600页。大约 500 页后出现相同的错误

Error:failed to load file .......... with network status code 201 and http status code 0 - Error opening kn_footer.html: Too many open files

fs.file-max 的值约为 1.6M。错误后,我将其增加到 2097152,但它没有帮助。

尝试添加文件缓存但不起作用。命令行如下:

wkhtmltopdf --cache-dir /tmp/ --allow /path/to/my/dir/ --margin-top 20 --load-error-handling ignore --orientation landscape --page-size A4 page kn_utf.html --footer-html kn_footer.html --header-html kn_header.html --footer-spacing 1 kn.pdf

有没有办法说 wkhtmltopdf 一次获取页眉和页脚或在每次迭代后关闭该文件?

【问题讨论】:

    标签: limit wkhtmltopdf


    【解决方案1】:

    我也无法获得任何类型的缓存来处理 532 页的文档。通过将我的footer.html 文件转换为wkhtmltopdf 页脚文本,我确实取得了一些成功。您也可以考虑将其拆分为两个文档,运行 wkhtmltodpf 两次,然后使用 pdfunite 将两个临时 PDF 合并到最终文档中。如果您对文本页脚方法感兴趣,这是我使用的一组选项。不要忘记设置下边距(-B 选项),否则文本页脚会从页面上掉下来。

    wkhtmltopdf \
    -O landscape \
    -s letter \
    -L 20 \
    -R 20 \
    -T 20 \
    -B 20 \
    --exclude-from-outline \
    --image-dpi 300 \
    --header-html $BASE_DIR/header.html \
    --footer-line \
    --footer-spacing  10 \
    --footer-left "$FOOTER_LEFT" \
    --footer-center "$FOOTER_CENTER" \
    --footer-right "$FOOTER_RIGHT" \
    --footer-font-size 10 \
    --cache-dir $BASE_DIR/cache \
    --user-style-sheet $BASE_DIR/some.css \
    $TARGET_DIR/[im]*.html \
    $TARGET_DIR/final.pdf
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-11
      • 2017-04-21
      • 2012-10-16
      • 2016-08-09
      • 1970-01-01
      • 2019-08-08
      相关资源
      最近更新 更多