Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mPDF position absolute

I need to generate PDF file from HTML input:

<div style="width: 14cm; height: 21cm; position: relative">
  <img src="bg-image.jpg" style="width: 100%; height: 100%; position: absolute; left: 0; top: 0">
  <img src="image.jpg" style="width: 100px; height: 100px; position: absolute; left: 5cm; top: 5cm">
</div>

where first image is background and second image is user input (smaller photo).

Problem is that when I try to generate in to PDF file with mPDF library, images are not displayed on one page, but one image is on first page, second image is on second page. So I think that absolute positioning does not work and I do not know how to fix it. I can not use first image as background image because its natural dimensions are smaller than background area it have to fill.

Can you give me some advice, please? What is wrong?

like image 897
tomas657 Avatar asked Jun 01 '13 16:06

tomas657


2 Answers

I don't know mPDF but if the problem is absolute positioning you could just use float positioning with negative margins:

<img src="image.jpg" style="float: left; margin: -16cm 0 0 -9cm" />
like image 84
Tobag Avatar answered Oct 06 '22 15:10

Tobag


mPDF only supports position:absolute|fixed partially - as root elements i.e. it will not position blocks absolutely inside another block. This is a known limitation of mPDF.

like image 33
Ruslan Safronov Avatar answered Oct 06 '22 14:10

Ruslan Safronov