Generate a PDF with background image without margin

泄露秘密 提交于 2019-12-11 03:05:19

问题


I want to generate a PDF with DOMPDF tool in CodeIgniter.

I have an image and I want to display it in a background full DIN A4 PDF page, when I try to do this:

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;
}

I have a PDF but it appear a margin (or padding). I want without margin or padding, just a full 100% image background.

Thank you,


回答1:


dompdf does not yet support the background-size declaration. The easiest work-around is to absolutely position an image and set the dimensions to those of the page (percent calculations still appear to be a bit off). You have to take into account the page margins, so you should set those as well.

<!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:


I also stumbled upon your problem long time ago. This what i did to make the page no margins.

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


来源:https://stackoverflow.com/questions/32792412/generate-a-pdf-with-background-image-without-margin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!