67526

Generate a PDF with background image without margin

Question:

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,

Answer1:

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>

Answer2:

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

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

Recommend

  • R web scraper with jsessionid
  • Convert certificate to byte array
  • No suggestions when code snippets are used in sublime
  • Resize Images in Canvas
  • C# mvc3 redirect sitemap.xml to controller action
  • Get Element By Classname Script Not Working
  • ASP.Net MVC entity framework submit model, then open new model in edit page
  • Checking for Windows Server 2003
  • Installing Kohana on OpenShift?
  • API Gateway Encoding multipart/form-data
  • sec:authorize not being evaluated on spring-boot project
  • Dynamically change JavaFX css property
  • Expression.Call GroupBy then Select and Count()?
  • Filtering out choiceless polls in the Django tutorial causes polls in the index to duplicate
  • Querying Elasticsearch Address Based Index
  • Convert current tmux session to configuration file
  • Adding a click event to a dynamically created html element using angular2
  • dmtracedump doesn't work, HELP!
  • Query regarding com.jcraft.jsch.JSchException: UnknownHostKey: x.y.com. DSA key fingerprint is “ac:e
  • Modifying native query cannot have named parameter bindings?
  • Update all WooCommerce product prices to 2 decimals in database
  • cSPADE data mining in R using arulesSequences - Error while converting to “transactions” format
  • Fortran function variable length string return
  • separate tokens in batch file
  • How to define a custom accuracy in Keras to ignore samples with a particular gold label?
  • LINQ to populate treeview based upon grouping
  • Compiling multiple source files in Rcpp
  • How to write seo friendly url's using htaccess?
  • Django, uWSGI & nginx: Process dies for “no reason”
  • using maven pom while creating jar:test-jar some times it says JAR will be empty - no content was ma
  • Can a PHP script be scheduled to run at a specific time or after a specific amount of time has expir
  • reshape/remould data frame to create normalized bar chart and pie chart
  • Comma decimal separator is ignored by ASP.NET MVC model binder
  • calling IO Operations from thread in ruby c extension will cause ruby to hang
  • Using Service Component Runtime