I want to display text in center of the page. But, it's not display proper. I used mpdf and i want to display using mpdf in php.
What I tried :
<?php
require_once __DIR__ . '/../bootstrap.php';
$mpdf = new \Mpdf\Mpdf();
$mpdf->SetDisplayMode('fullwidth');
$stylesheet = '<style>' . file_get_contents('example1.css') . '</style>'; // external css
$mpdf->WriteHTML($stylesheet, 1);
$mpdf->WriteHTML('<div id="center">
Hello World
</div>', 2);
$mpdf->Output('filename.pdf');
CSS :
#centrar{
margin:0;
width: 80%;
background-color: #000;
}
body { text-align: center }
Output :
enter image description here
It's display center in first line. I want to display in full page center part.
How to do that? Please help me. Thanks.
Related
I am using HTML2PDF library of PHP to create PDF from HTML. My page url is as below ::
http://domain.com/admin/invoice/invoicedownload
To create pdf using below code ::
ob_start();
$width_in_mm = 240;
$height_in_mm = 250;
$html2pdf = new HTML2PDF('P', array($width_in_mm,$height_in_mm), en, true, 'UTF-8', array(15, 10, 15, 10));
$html2pdf->setDefaultFont('Arial');
$html2pdf->pdf->SetTitle('Invoice Details');
$html2pdf->writeHTML($pdf_template);
$html2pdf->Output($file_name,'I');
die();
This code open pdf view in browser new tab.
Issue I am facing is that that new tab title is set as "Invoice Details - invoicedownload" but I want it as "Invoice Details". Always url's last part is append in title.
Please help me for this.
Thank you in advance.
In order to define your own tab title, you can use the 'embed' html tag.
File n°1 (main):
html, body, embed
{
width: 100%;
height: 100%;
}
body
{
margin: 0;
padding: 0;
}
<!DOCTYPE html>
<html>
<head>
<title>Your title</title>
</head>
<body>
<embed src=/path-to-your-pdf type='application/pdf'/>
</body>
</html>
File n°2 (/path-to-your-pdf):
<?php
$html2pdf = new Html2Pdf('P, 'A4', 'en');
$html2pdf->writeHTML($pdf_template);
$html2pdf->output();
Hope this helps ;)
Is there a gallery that have three features:
displays pictures in a lightbox
allows to import tens or hundreds of images at once from a folder
takes descriptions from file names
I have to make it on yesterday :)
I've made my own script together with original Lightbox
http://lokeshdhakar.com/projects/lightbox2/
Decided it will be much faster that way:
<?php
echo str_replace(array('<','>'), array('<','>'),'<table id="galx"><tr>');
$source_dir = 'images/taken/from/here';
$mini_dir = 'mini';
$target_dir = 'imagies/copied/to/there';
$i=0;
$images = array_diff(scandir($source_dir), array('..', '.',$mini_dir));
foreach($images as $image)
{
$filename = pathinfo($image, PATHINFO_FILENAME);
$title = mb_strtoupper(trim(str_replace('_',' ',$filename)));
$s = "<td><a href='$target_dir/$image' data-lightbox='galx' data-title='$title' >"
. "<img src='$target_dir/$mini_dir/$filename.jpg' /><br/>"
. "$title<a/></td>"; //gallery with titles
/*$s = "<td><a href='$target_dir/$image' data-lightbox='galx' >"
. "<img src='$target_dir/$mini_dir/$filename.jpg' />"
. "<a/></td>";*/ //gallery without titles
if (++$i % 5 == 0)
$s .= '</tr><tr>';
$s = str_replace(array('<','>'), array('<','>'), $s); //comment this line if want to paste it as php code
echo $s;
}
echo str_replace(array('<','>'), array('<','>'),'</tr></table>');
?>
Some basic css:
#galx {
width: 650px;
}
#galx td {
text-align: center;
}
#galx a {
display: block;
width: 120px;
font-size: 0.8em;
margin:1px auto;
text-decoration: none;
color: black;
text-align: center;
}
I've used FastStone Image Viewer to batch resize images at once and create miniatures. In app just press F3 to open advanced processing tool.
It just won't work with non-english letters on Windows - PHP bug. It still spoils first non-english letter of file name on Linux, so need to prefix '_' in such cases.
Overall good result - i've hided script somewhere on website and in 1,5 hours generated 6 galleries with ~1,5k pictures, and most of the time was consumed by file processing and copying. Not elegant but effective.
I am using a Wordpress theme and want to make it change the background images automatically. So, I used some PHP code and tried to build it into the website, but something is not working and I cannot figure it out, as I am not very good with PHP.
functions.php:
<?php
$bilder = glob( "images/*.jpg" );
shuffle( $bilder );
$zufall = imagecreatefromjpeg($bilder[0]);
imagejpeg($zufall);
?>
... and simply in CSS of my Wordpress:
body {
background: url('<?php print $zufall ?>') no-repeat center center fixed;
}
But for some reason it just does not show the pictures and I am really off with my wisdom now. :(
Can you help me or tell me the error?
Thank you very much in advance.
This should work - you just need the filename of the image which is in the $bilder array
functions.php:
<?php
$bilder = glob( "images/*.jpg" );
shuffle( $bilder );
$zufall = $bilder[0];
?>
CSS:
body {
background: url('image/<?php print $zufall ?>') no-repeat center center fixed;
}
I am using WP 3.5.1, twenty twelve child theme and PHP 5.2 on my server.
I am trying to use a php script(that works on my other websites) in order to get random background-image but it's not working:
CSS:
body {
background: url(<?php include ("bg.php"); echo $selectedBg; ?>) no-repeat fixed;
}
PHP:
<?php
$bg = array('1.jpg','2.jpg','3.jpg','4.jpg','5.jpg');
$i = rand(0, count($bg)-1);
$selectedBg = "$bg[$i]";
?>
my php file is in the same folder as the jpg's.
Any ideas?
No errors. If I use background: url(1.jpg); (instead of php) it works fine but obviously shows 1 image.
Small solution:
We know that he have 5 images on the server:
'1.jpg','2.jpg','3.jpg','4.jpg','5.jpg'
So quick tip:
<body style="background: url('pahttoimages/<?= rand(1, 5) ?>.jpg') no-repeat top center;">
i think the CSS file can't explain your PHP code
try body {
background: url(<?php echo '1.jpg'; ?>) no-repeat fixed;
}
As far as I can see, your code is valid.
Except, you should really write the last line like:
$selectedBg = $bg[$i];
No need for quotes here.
I suspect this is what is causing the error:
my php file is in the same folder as the jpg's. Any ideas?
The background-image needs to be relative to the template-file you are using, not the PHP-file. You script will only work if the images are located in the same folder as the template-slices.
In my WP-installation, I have a template located in /wp-content/themes/mytemplate/ and template-graphics located in /wp-content/themes/mytemplate/images/. If I were to use your script, I would need to preappend /images/ before all the backgrounds in your array.
By the way, you should consider installing Firebug on Firefox and inspect the source. Is the background-name parsed into the template? Does loading the image return a 404 not found-error? Is the location and path correct?
background-image: url(<?php include ("bg.php"); echo $selectedBg; ?>);
background-position: fixed;
background-repeat: no-repeat;
Do this:
// bg.php
<?php
return array(
'1.jpg',
'2.jpg',
'3.jpg'
);
// Wordpress CSS
<?php
$imageUrls = include('bg.php');
$imageUrl = $imageUrls[ array_rand($imageUrls) ];
?>
.someClass {
background-image: url(<?php echo $imageUrl ?>);
}
background: url('<?php $a = array('darkred.jpg','red.gif','pink.png'); echo $a[array_rand($a)];?>');
There's a million tutorials for how to customize the TinyMCE panel on the WSYWIG editor... but that's not what I want to do.
I want to add a stand-alone button to the post edit view that will make an API call and auto-fill certain fields on the page. I closest I've come so far are the hooks simple_edit_form and advanced_edit_form which both allow me to add content to the very bottom of the edit form. It'd be much better to add it at the top, where the "add media" button lives.
Is this possible?
There is an action called media buttons. Below is basic example. I've take this example from the plugin gravity forms and changed it little. Good luck.
add_action( 'media_buttons', 'add_form_button' );
function add_form_button(){
$is_post_edit_page = in_array(RG_CURRENT_PAGE, array('post.php', 'page.php', 'page-new.php', 'post-new.php'));
if(!$is_post_edit_page)
return;
// do a version check for the new 3.5 UI
$version = get_bloginfo('version');
if ($version < 3.5) {
// show button for v 3.4 and below
$image_btn = GFCommon::get_base_url() . "/images/form-button.png";
echo '<img src="'.$image_btn.'" alt="' . __("Add Gravity Form", 'gravityform') . '" />';
} else {
// display button matching new UI
echo '<style>.gform_media_icon{
background:url(' . GFCommon::get_base_url() . '/images/gravity-admin-icon.png) no-repeat top left;
display: inline-block;
height: 16px;
margin: 0 2px 0 0;
vertical-align: text-top;
width: 16px;
}
.wp-core-ui a.gform_media_link{
padding-left: 0.4em;
}
</style>
<span class="gform_media_icon "></span> ' . __("Add Form", "gravityforms") . '';
}
}