如何在Laravel中覆盖DOMPDF配置文件中的默认DPI?

时间:2016-04-10 16:45:13

标签: laravel dompdf

我在DOMPDF周围使用barryvdh / laravel-dompdf laravel包装器。

我生成的字母用不同的信头打印和张贴,我的信头作为背景图片,文字在顶部。

我已经达到了一切运行良好的程度,然而,DOMPDF中的默认DPI是96,因此打印输出时信头的背景图像的分辨率非常低。

我知道供应商目录中的dompdf_config.inc文件中有一个def("DOMPDF_DPI", 96);选项。如何在不编辑包本身内的文件的情况下覆盖此设置?

2 个答案:

答案 0 :(得分:1)

找到解决方案。

运行php artisan vendor:publish在我的目录中给了我一个配置文件,我可以编辑这个选项。

/**
     * 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
     */
    "DOMPDF_DPI" => 192,

答案 1 :(得分:0)

该文件位于您的供应商文件夹中,您永远不应该触摸它,因为/ vendor应该在您的.gitignore文件中。

你应该真正使用原始的Dompdf库https://github.com/dompdf/dompdf 并做一些类似

的事情
$options = (new Options)->setDpi($yourDpi);
$dom = new DompdfWrapper($options);
$dom->loadHtml($htmlString);
$dom->render();