【问题标题】:Laravel View not fitting in dompdf generated pdfLaravel View 不适合 dompdf 生成的 pdf
【发布时间】:2021-08-26 16:13:27
【问题描述】:

我在 laravel 8+ 版本中使用 dompdf,我通过首先加载视图然后提取其内容并将其保存为 pdf 文件成功生成了 pdf。我的视图中只有 1 个由 dompdf 加载的表,它不适合页面。

The pdf

有人知道如何解决这个问题吗?

【问题讨论】:

  • 尝试在 dompdf 配置中更改 "dpi" => 196,
  • 非常感谢它的工作!

标签: php laravel pdf dompdf


【解决方案1】:

看起来你需要更新dompdf config文件中的dpi

默认dpi96。最好改成"dpi" => 196

来自 dom pdf 配置文件

 /**
         * Image DPI setting
         *
         * This setting determines the default DPI setting for images and fonts.  The
         * DPI may be overridden for inline images by explictly setting the
         * image's width & height style attributes (i.e. if the image's native
         * width is 600 pixels and you specify the image's width as 72 points,
         * the image will have a DPI of 600 in the rendered PDF.  The DPI of
         * background images can not be overridden and is controlled entirely
         * via this parameter.
         *
         * For the purposes of DOMPDF, pixels per inch (PPI) = dots per inch (DPI).
         * If a size in html is given as px (or without unit as image size),
         * this tells the corresponding size in pt.
         * This adjusts the relative sizes to be similar to the rendering of the
         * html page in a reference browser.
         *
         * In pdf, always 1 pt = 1/72 inch
         *
         * Rendering resolution of various browsers in px per inch:
         * Windows Firefox and Internet Explorer:
         *   SystemControl->Display properties->FontResolution: Default:96, largefonts:120, custom:?
         * Linux Firefox:
         *   about:config *resolution: Default:96
         *   (xorg screen dimension in mm and Desktop font dpi settings are ignored)
         *
         * Take care about extra font/image zoom factor of browser.
         *
         * In images, <img> size in pixel attribute, img css style, are overriding
         * the real image dimension in px for rendering.
         *
         * @var int
         */
        "dpi" => 96,

参考:https://github.com/barryvdh/laravel-dompdf/blob/master/config/dompdf.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-20
    • 1970-01-01
    • 2017-08-14
    • 2012-06-06
    • 2012-09-13
    • 2013-05-07
    • 2015-11-07
    相关资源
    最近更新 更多