How can I center image in mpdf? - php

I would like to centre image in mpdf (version 6>).
This is my (shortened) html output that I send to mpdf. The displayed class does not help.
<style>
IMG.displayed {
display: block;
margin-left: auto;
margin-right: auto }
</style>
<img style="max-height:600px" class="displayed" src="/images/size_original/m_princezna_1.jpg"/>

Add a text-align: center property on a parent HTML element of the image, eg.:
body { text-align: center }

I tried the solution of Finwe but that moved the image to next page. So did a workaround with a combination of solutions here of Ram Guru99 and there :
<table style="width:100%;">
<tr>
<td align="center">
<img src="<?php echo $imagepath ;?>"/>
</td>
</tr>
</table>

You can use below code to center image in the page.
<p style="text-align:center;">
<img src="imageurl.png"/>
</p>

Related

How to make a barlike chart but only with html and css [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I have a database with lots of records and I have to make a foreach loop in order to get all that data. The problem is that a chart for every data would overload the page. So I need to make a barlike chart using two divs and one div(the blue one) to take percentage of the main one (the grey div) accourding to the value from that data. I did all of that but I don't know how to make the inner div build change it's percentage width according to how close it is from the highest value in my database. This is how I fetch the numbers shown in the right.
<?php echo #$item->{"media_count"}; ?>
I will attach an image so you can see how I need to make it look like.
barlike chart
<table class="table table-bordered">
<tbody style="width: 401px; border: 0;">
<?php foreach ($data->data->data as $key => $item):
if (#$item->{"name"}) {
?>
<tr>
<td>
<?php echo #$item->{"name"}; ?>
</td>
<td>
<div class="outer">
<div class="inner" style="width: 20%;"></div>
</div>
</td>
<td>
<?php echo #$item->{"media_count"}; ?>
</td>
</tr>
<?php }
endforeach ?>
</tbody>
</table>
Is this the sort of layout you are looking for?
.outer, .inner {
height: 20px;
margin-bottom: 5px;
}
.outer {
background-color: gray;
width: 200px;
}
.inner {
background-color: blue;
}
<div class="outer">
<div class="inner" style="width: 20%;"></div>
</div>
<div class="outer">
<div class="inner" style="width: 40%;"></div>
</div>
<div class="outer">
<div class="inner" style="width: 60%;"></div>
</div>
Create a full width div, set the height and width and color it gray. Then, inside that div, create another div with no margin, set the height and color it blue. Set the width of the blue div to the width that you want it.
You could use absolute positioning for the bars inside a relatively positioned div to make the bars follow the outer div.
.outerGraph {
position: relative;
width: 400px;
height: 200px;
background-color: #fff;
}
.value {
position: absolute;
height: 20px;
right: 10px;
}
.bar {
position: absolute;
background-color: blue;
height: 20px;
left: 10px;
}
.bar1 {
top: 10px;
}
.bar2 {
top: 40px;
}
.bar3 {
top: 70px;
}
<div class="outerGraph">
<div class="bar bar1" style="width: 75px;" title="88204"></div>
<div class="value bar1">88204</div>
<div class="bar bar2" style="width: 100px;" title="92784"></div>
<div class="value bar2">92784</div>
<div class="bar bar3" style="width: 200px;" title="100000"></div>
<div class="value bar3">100000</div>
</div>
Use the title attribute on the bars for the hover effect and apply the bar[] class for both bars and their numbers.
Honestly, I cannot think of a reason you shouldnt just use javascript; you should tell us why you want this and post some code of your own

How to make pictures next each other in the center in side html tag

I have this code
<?php
echo '<p style="text-align: center;"><img src="tran.png"/></p>';
echo '<p style="text-align: center;"><img src="courselist.png"/></p>';
?>
but when I run it show me this icons(pictures) under each other
like this
ICON1
ICON2
How I can make it next each other like this and I want the icons still in the middle of the page.
ICON1 ICON2
You can easily do that by using by using display inline and margin auto atribbutes!
CSS:
.imgcenter {
display: inline-block;
margin-left: auto;
margin-right: auto;
height: 30px;
}
#images{
text-align:center;
}
HTML
<div id="images">
<a href="tran.php?page=A">
<img class="imgcenter" border="0" alt="Mail" src="http://megaicons.net/static/img/icons_sizes/8/178/512/social-networks-instagram-icon.png"/>
</a>
<a href="course_list.php?page=A">
<img class="imgcenter" border="0" alt="Facebook" src="http://megaicons.net/static/img/icons_sizes/8/178/512/social-networks-instagram-icon.png"/>
</a>
</div>
Running example:
http://jsfiddle.net/X3b5g/389/
Use one p tag.
<?php
echo '<p style="text-align: center;"><img src="tran.png"/> ';
echo '<img src="courselist.png"/></p>';
?>
Remove the p tag. Or css them style="display: inline"
Meaning:
<p style="display:inline">.... rest of code
But unless the p tag is needed you can remove it and just use the center tag instead

DOMPDF is not generating dynamic image using PHP

I am generating a pdf using DOMPDF but in that the image is not displaying instead it is throwing an error "Image not found".
Here is my code :
require_once "dompdf_config.inc.php";
require_once('html2_pdf_lib/html2pdf.class.php');
include_once('../config.php');
$file = "www/test/mytest.php";
$html=file_get_contents($file);
$dompdf = new DOMPDF();
//$dompdf->load_html($my_html);
$dompdf->load_html_file('https://www.lettertowomen.com/admin/dompdf/www/test/mytest.php?id=111');
$dompdf->render();
$dompdf->stream("sample.pdf");
mytest.php
<body>
<form action="" method="POST">
<table width="1000" height="1000" style="background-color: #b91781;font-family: 'DejaVuSerif'; color: #ffffff;font-size: 20px;">
<tbody><tr>
<td width="249" valign="middle" align="center">
<div style="height: 595; width: 249; text-align: left;padding-top:140px;">
<img src="<?php echo base_url;?>uploads/<?php echo $result['image'];?>" style="border-radius: 159px;
width: 159px; height:225px;margin:70px auto 0;">
</div>
</td>
<td width="583" valign="middle" align="center">
<div style="height: 188px; width: 448px; text-align: left;">
<span style="display: block;
float: left;">To <span style="font-size: 22px; font-weight: 700; line-height: 34px; position: relative; top: 17px;"><?php echo $result['recipient_name'];?></span>
</span><br><br>
<div style="clear: both; display: inline-block; min-height: 160px; padding: 0px 18px; margin: 28px auto 0px;color: #ffffff">From the day you were born,<br>
I fell in love with you my girl.<br>
And when you bloomed like a rose without a single thorn,<br>
You turned my entire life into a most precious pearl.<br>
Your love and care for me is a beautiful dawn,<br>
That marks the end of darkness left to unfurl.<br><br>
Feeling blessed to have you as my daughter. </div>
<br><br>
<span style="display: block;
float: right;">From<span style="font-size: 22px; font-weight: 700; line-height: 34px; position: relative; top: 18px;"><?php echo $result['sender_name'];?></span>
</span></div>
</td>
</tr>
</tbody></table>
</form>
</body>
</html>
everything is displaying but image is not displayed. I have check already asked question in stackoverflow : dompdf not displaying image generated by PHP file but it is not working in my case
Also I have set DOMPDF_ENABLE_REMOTE = true
Thanks in advance
You can use Base64 image data
$html = '<div>
<p>IMAGE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gLW00Va/vcb/z3nRu81AevpKr5tYPi9EhOwprK7ZQLWVCZgTeX8lP8CuDenorrKqfIAAAAASUVORK5CYII%3D">
</div>':
require_once('dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF ();
$dompdf->load_html ($html);
$dompdf->render ();
$dompdf->stream ("Test.pdf", array ("Attachment" => false));
Get the image from php in base64:
//getIMG.php?data=1&id=123
if ($data == 1) {
echo "data:image/".$adj->type.";base64,"
.str_replace ("\n", "", base64_encode ($adj->imageBinary));
}
For showing the image, you have to go to your dompdf source file like
..dompdf\src\Image\Cache.php
In the Cache.php file, you will search .... and make chrootValid true.. by default it will be false.
$chrootValid = true;
save it and try now...
Hope it will work

CSS Break Long Text with "..."

Am trying to use text-overflow:ellipsis inside the <td> tag but it supports only to <div> tag.
Any idea to support for <td> tag?
check what am trying to do
http://phpresult.com/source/share/L9F71379328772
I have Found the Solution by using max-width
<style>
.test
{
white-space:nowrap;
text-overflow:ellipsis;
max-width: 100px;
overflow:hidden;
border:1px solid #000000;
}
</style>
</head>
<body>
<table border="1">
<tr>
<td class="test">
This is the Long text only applied to div tag
</td>
</tr>
</table>
</body>
Add below code...
td {
display: block; /* or inline-block */
}
or
Use
table-layout: fixed;
or give fixed width to your table

How to center absolutely positioned elements in css for a pdf

I'm trying to center the names(#box2) and the topic(#box1) on top of an image.
<?php require_once('seminar_config.php'); ?>
Print
<body>
<?php
$participants = $db->get_results("SELECT participant FROM tbl_participants WHERE state=1");
$topics = $db->get_results("SELECT topic FROM tbl_topics");
if(!empty($participants)){
?>
<?php ob_start(); ?>
<div id="container">
<img src="certificate.jpg"/>
<?php foreach($topics as $a=>$b){ ?>
<?php foreach($participants as $k=>$v){ ?>
<img src="certificate.jpg"/>
<div id="box1" class="common"><?php echo $b->topic; ?></div>
<div id="box2" class="common"><?php echo $v->participant; ?></div>
<?php } ?>
<?php } ?>
</div>
<?php $_SESSION['certificates'] = ob_get_contents(); ?>
<?php ob_flush(); ?>
<?php } ?>
</body>
And here's the script that creates the pdf:
<?php require_once('html2pdf/html2pdf.class.php'); ?>
<?php
$html2pdf = new HTML2PDF('L', 'A4', 'en');
$html2pdf->writeHTML('<style>
#box1{
margin-top: 350px;
}
#box2{
margin-top: 200px;
}
.common{
height: 20px;
left: 630px;
right: 630px;
text-align: center;
position: absolute;
left: 0;
top: 0;
font-size:20px;
}
</style>'.
$_SESSION['certificates']);
$html2pdf->Output('random.pdf');
?>
I have no problem with the center positioning of the names and topic if I'm not using html2pdf to generate pdf files.
But if I use html2pdf everything is ruined. Please help me center things in css when using html2pdf.
Most common HTML-to-PDF programs either don't understand CSS, or understand CSS poorly. If your HTML is working, but doesn't translate well to PDF using html2pdf, you might give wkhtmltopdf a shot https://github.com/antialize/wkhtmltopdf
If you want to center .common try following:
.common{
position: absolute;
left: 50%;
top: 0;
font-size:20px;
width:600px;
margin-left:-300px;
}
Old question, but I had similar problem today. Here is how I was able to solve it after trying every method in the history of html and css to center something. I used a table like JorisW:
<table style='width:100%' align='center'>
<tr>
<td>
<img src="image.gif">
</td>
</tr>
</table>
Here is what I use to position divs in center.
Say you want to position div with id=test
CSS
#test {
width: 500px;
margin: 0 auto; //auto margin to left and right
}
Try using tables and inline css styles
<table align="left" width="100%" style="page-break-after:always; margin-top:25px; margin-left:25px; font-family:tahoma; font-size:20px; ">
<tr><td>Your info</td></tr>
</table>

Categories