【问题标题】:Generate a PDF with background image without margin生成带有背景图像的 PDF,没有边距
【发布时间】:2015-09-26 00:32:16
【问题描述】:

我想用 CodeIgniter 中的 DOMPDF 工具生成 PDF。

我有一张图片,我想在背景完整的 DIN A4 PDF 页面中显示它,当我尝试这样做时:

body{
  background-image: url('http://blogs.ucl.ac.uk/quantum/files/2013/12/artwork-fullsize.jpg'); background-position: bottom right; background-repeat: no-repeat; 
  background-size: 100%;
  width:100%;
  height:100%;
  padding: 0px;
  margin: 0px;
}

我有一个 PDF,但它显示为边距(或填充)。我想要没有边距或填充,只是一个完整的 100% 图像背景。

谢谢,

【问题讨论】:

    标签: php codeigniter dompdf


    【解决方案1】:

    dompdf 还不支持background-size 声明。最简单的解决方法是绝对定位图像并将尺寸设置为页面的尺寸(百分比计算似乎仍然有点偏离)。您必须考虑页边距,因此您也应该设置它们。

    <!DOCTYPE html>
    <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
      <style>
         @page { margin: .5in; }
         .bg { top: -.5in; right: -.5in; bottom: -.5in; left: -.5in; position: absolute; z-index: -1000; min-width: 8.5in; min-height: 11in; }
      </style>
    </head>
    <body>
      <img class="bg" src="http://eclecticgeek.com/images/macro/ants.jpg">
    </body>
    </html>
    

    【讨论】:

      【解决方案2】:

      很久以前我也偶然发现了您的问题。这是我为使页面没有边距所做的。

      <style>@page{margin:0}</style>
      

      【讨论】:

        猜你喜欢
        • 2013-11-30
        • 1970-01-01
        • 2011-11-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多