Reputation: 499
In my code I am trying to add a external border frame to the pdf, but when I do so, the content of my pdf breaks in between and continue in second page. To overcome that Issue I used page-break-inside:avoid; property on parent div. But this resulted in a new strange issue, its keeping the first page blank (without border) and adding the whole content to second page (With border) of pdf.
No way for me to understand what I am doing wrong.
I am detailing dummy code snippet below -
<style type="text/css">
@page { margin: 0px; }
body { margin: 0px; }
html { margin: 0px;}
.back-img
{
background: url('ImageURL');
background-position: top left;
background-repeat: no-repeat;
background-size: 100%;
padding-top: 100px;
padding-left: 100px;
padding-right: 100px;
width:100%;
height:100%;
}
</style>
<div style="page-break-inside:avoid;" class="back-img">
<div style="text-align: center;">
<h1>Heading Text</h1>
<br>
<img src="ImgURL" height="100">
<br><br>
Some Text Here
<br>
Some Text Here.. Some text here..
<br>
Some Text Here
<br><br>
Some Text Here
<br><br>
3-4 lines of paragraph here
<br><br>
<img src="ImgURL" height="50">
<br>
Some text Here
<br>
Some Text Here
<br>
Some Text Here
</div>
</div>
Dompdf version is 0.7.0 PHP version is 7.0.18
Your help is much appreciated.
Upvotes: 2
Views: 6845
Reputation: 533
I've had trouble with this over the years.
A solution that seems to work is make sure the first item is
page-break-inside: auto
on the first element, and then
page-break-inside: avoid
On any elements that follow
Upvotes: 2
Reputation: 13944
This is probably because you set the width and height of the container div to 100%. Dompdf doesn't do the best job flowing elements that are bumping up against the margins of the page. You have a few options to try to address the issuue:
For that latter try something like:
<style type="text/css">
@page { margin: 100px; }
.back-img
{
position: fixed;
background: url('ImageURL');
background-position: top left;
background-repeat: no-repeat;
background-size: 100%;
top: -50px;
right: -50px;
bottom: -50px
left: -50px;
}
</style>
<div class="back-img"></div>
<div style="text-align: center;">...</div>
Upvotes: 1