0

Okay.

The Problem is kinda weird.

I'm trying to convert HTML page to PDF file and save it.

I'm using mPDF for this. However, CSS rendering isn't going as expected.

I'm not using CSS3. So, I don't think that this is the problem.

Here's a screen shot of how should it be :

enter image description here

PDF :

Goes really wrong

Thanks in advance.

HTML : https://codepen.io/AKhaled47/pen/omRObM

CSS :

div.calendar{
  margin:2pc auto;
  padding:0px;
  width:602px;
}
div.calendar div.box{
    position:relative;
    top:0px;
    left:0px;
    width:100%;
    height:40px;
    background-color:#890e4f;    
    border-radius: 5px;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;  
}
div.calendar div.header{
    line-height:40px;  
    vertical-align:middle;
    position:absolute;
    left:11px;
    top:0px;
    width:582px;
    height:40px;   
    text-align:center;
}
div.calendar div.header a.prev,div.calendar div.header a.next{ 
    position:absolute;
    top:0px;   
    height: 17px;
    display:block;
    cursor:pointer;
    text-decoration:none;
    color:#FFF;
}
div.calendar div.header span.title{
    color:#FFF;
    font-size:18px;
}
div.calendar div.header a.prev{
    left:0px;
}
div.calendar div.header a.next{
    right:0px;
}
div.calendar div.box-content{
    background: #FFF;
    border:1px solid #890e4f;
    border-top:none;
    border-radius:5px;
    border-top-left-radius:0;
    border-top-right-radius:0;
}
div.calendar ul.label{
    float:left;
    margin: 0px;
    padding: 0px;
    margin-top:5px;
    margin-left: 5px;
}
div.calendar ul.label li{
    margin:0px;
    padding:0px;
    margin-right:5px;  
    float:left;
    list-style-type:none;
    width:80px;
    height:40px;
    line-height:40px;
    vertical-align:middle;
    text-align:center;
    color:#000;
    font-size: 15px;
    background-color: transparent;
}
div.calendar ul.dates{
    float:left;
    margin: 0px;
    padding: 0px;
    margin-left: 5px;
    margin-bottom: 5px;
}
div.calendar ul.dates li{
    margin:0px;
    padding:0px;
    margin-right:5px;
    margin-top: 5px;
    line-height:80px;
    vertical-align:middle;
    float:left;
    list-style-type:none;
    width:80px;
    height:80px;
    font-size:25px;
    background-color: #DDD;
    color:#000;
    text-align:center; 
}
:focus{
    outline:none;
}
div.clear{
    clear:both;
}
2
  • 1
    I'm not very familiar with CSS. But one thing I recognized in your code: are you using deliberately the unit 'pc' (Pica) instead of 'px'(magic css unit) in your first css element? If it is deliberateness, let's have a look at your html code... Are you using any kind of loop to generate your html? Commented Feb 20, 2019 at 8:55
  • 1- Changing pc to px doesn't make any difference. 2- No, I don't. I just used for loops and foreach in calendar class. that's it. Commented Feb 20, 2019 at 18:40

1 Answer 1

2

Float elements are only partially supported in mPDF. For best results, use a HTML table (which is perfectly suitable for a calendar).

See documentation on floats: https://mpdf.github.io/what-else-can-i-do/floating-blocks.html

Sign up to request clarification or add additional context in comments.

8 Comments

Okay, let me try. Although changing the HTML would be a big deal for this. But some efforts would be better
Unfortunately, Goes worse.
Checked my HTML 4 times for any non closed tags, etc. It's displaying normal on my web page. But not in the pdf.
Not helpful. Update your question with actual HTML code. Just append it, do not rewrite it for the sake of history.
idownvotedbecau.se/imageofcode - No one will ever reproduce your problem from an image of PHP code. Also see MCVE.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.