Laravel 视图不适合 dompdf 生成的 pdf

Laravel View not fitting in dompdf generated pdf

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

The pdf

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

看起来您需要更新 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