I am using mPDF for exporting contents as a PDF file. For creating header, I am using $mpdf->SetHeader() function like this:
$arr = array (
'L' => array (
'content' => 'Bozmadan sonra ıslah yapılamaz kuralının istisnası, ...',
'font-size' => 10,
'font-style' => 'B',
'font-family' => 'serif'
),
'R' => array (
'content' => '{PAGENO}',
'font-size' => 10,
'font-style' => 'B',
'font-family' => 'serif',
'color'=>'#000000'
),
'line' => 1
);
$mpdf->SetHeader($arr, 'O');
This gives us like this:
You see, I don't want center area but it creates. How can I code for more wider left side, narrower right side and no center area.
If you use SetHTMLHeader() instead of SetHeader(), you can style it in HTML and have more control over the layout.
$header= '<table width="100%"><tr>
<td width="80%">Bozmadan sonra ıslah yapılamaz kuralının istisnası, ...</td>
<td width="20%">{PAGENO}</td>
</tr></table>';
$mpdf->SetHTMLHeader($header);
Related
I got a plugin for wordpress to show the most popular posts...
But when I add it via shortcode it always gets to the top of the page and not where I placed it... I changed every echo in the plugin PHPs to return but it didn't helped... Here is my shortcode in functions.php:
function top_news(){
$args = array(
'limit' => 15,
'range' => 'daily',
'freshness' => 1,
'order_by' => 'views',
'post_type' => 'post',
'stats_views' => 1,
'stats_author' => 1,
'stats_date' => 1,
'wpp_start' => '<table class="topnachrichten"><tr><th>Datum</th><th>Top Nachrichten von Heute</th><th>Leser</th></tr>',
'wpp_end' => '</table>',
'stats_date_format' => 'd',
'excerpt_by_words' => 1,
'excerpt_length' => 35,
'title_length' => 66,
'post_html' => '<tr><td class="datum">{date}. Aug</td><td class="stext"><details>
<summary>{title}<span class="plus">+</span></summary>{summary}<br>Weiterlesen</details></td><td class="views">{views}</td></tr>'
);
wpp_get_mostpopular( $args );
return $args;
}
add_shortcode( 'topnews', 'top_news' );
Do you know what I can do?
Thanks,
Till
Reading documentation of wpp_get_mostpopular, it states that the function actually prints the popular posts. Which means your popular posts are printed out before it returns anything and since all shortcodes are processed before the posts content is being printed that's why your popular posts always prints before (at top) of the post content.
So, what you can do is catch all the popular posts in a buffer.
function top_news(){
$args = array (
'limit' => 15,
'range' => 'daily',
'freshness' => 1,
'order_by' => 'views',
'post_type' => 'post',
'stats_views' => 1,
'stats_author' => 1,
'stats_date' => 1,
'wpp_start' => '<table class="topnachrichten"><tr><th>Datum</th><th>Top Nachrichten von Heute</th><th>Leser</th></tr>',
'wpp_end' => '</table>',
'stats_date_format' => 'd',
'excerpt_by_words' => 1,
'excerpt_length' => 35,
'title_length' => 66,
'post_html' => '<tr><td class="datum">{date}. Aug</td><td class="stext"><details>
<summary>{title}<span class="plus">+</span></summary>{summary}<br>Weiterlesen</details></td><td class="views">{views}</td></tr>'
);
ob_start();
wpp_get_mostpopular( $args );
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode( 'topnews', 'top_news' );
I can alternate bold and normal text in a footer (thanks to ejuhjav) but only if I don't try to style the text.
In the following example, the letter 'T' comes out bold because it's at the default size (12).
If I reduce the text, the bolding is dropped. I've also tried using named font styles and created font style objects. No luck.
Is there something simple I'm missing?
// create footer
$footer = $section->addFooter();
$textrun = $footer->addTextRun();
// define bold style
$boldFontStyleName = 'BoldText';
$phpWord->addFontStyle($boldFontStyleName, array('bold' => true));
// add content
$textrun->addText('T', $boldFontStyleName);
$textrun->addText(' ++353 1 555 0001 ',
array('name' => 'Helvetica', 'size' => 8));
$textrun->addText('E',
array('name' => 'Helvetica', 'size' => 8), $boldFontStyleName);
$textrun->addText(' abc.def#ghk.ie ',
array('name' => 'Helvetica', 'size' => 8));
$textrun->addText('W',
array('name' => 'Helvetica', 'size' => 8), $boldFontStyleName);
$textrun->addText(' abcd.ie/wxz',
array('name' => 'Helvetica', 'size' => 8));
and here goes the third time then :)
the addText function definition is:
addText(string $text, mixed $fStyle = null, mixed $pStyle = null)
i.e. the font styles are given with the second parameter and thus the rows where you have the $boldFontStyleName variable as third attribute the font is not bolded.
The easiest way to fix this would be to to just define couple of additional font styles:
// create footer
$footer = $section->addFooter();
$textrun = $footer->addTextRun();
// define font styles
$boldFontStyleName = 'BoldText';
$phpWord->addFontStyle($boldFontStyleName, array('bold' => true));
$smallFontStyleName = 'smallText';
$phpWord->addFontStyle($smallFontStyleName, array(
'name' => 'Helvetica',
'size' => 8,
));
$boldSmallFontStyleName = 'BoldSmallText';
$phpWord->addFontStyle($boldSmallFontStyleName, array(
'bold' => true,
'name' => 'Helvetica',
'size' => 8,
));
// add content
$textrun->addText('T', $boldFontStyleName);
$textrun->addText(' ++353 1 555 0001 ', $smallFontStyleName);
$textrun->addText('E', $boldSmallFontStyleName);
$textrun->addText(' abc.def#ghk.ie ', $smallFontStyleName);
$textrun->addText('W', $boldSmallFontStyleName);
$textrun->addText(' abcd.ie/wxz', $smallFontStyleName);
I want to have a footer that contains 3 lines of text, with a vertical space (like a blank line) between lines 2 and 3.
Because line 3 contains bold and normal text, I have to implement it as a textrun.
But there should be a line break between lines 1 and 2, so I use addText for both of these.
Unfortunately, the order in which the footer content is displayed is as follows:
textrun
footerText1
footerText2
The textrun gets processed first and appears above the other lines!
How do I get the order right?
My footer code is:
// create footer
$footer = $section->addFooter();
// textrun declaration removed from here
// create footer content
$footerText1 = "Blah blah blah.";
$footerText2 = "Ipsum loret Ipsum loret Ipsum loret.";
// define font styles
$smallFontStyleName = 'smallText';
$phpWord->addFontStyle($smallFontStyleName, array(
'name' => 'Helvetica',
'size' => 8,
));
$boldSmallFontStyleName = 'BoldSmallText';
$phpWord->addFontStyle($boldSmallFontStyleName, array(
'bold' => true,
'name' => 'Helvetica',
'size' => 8,
));
// define paragraph spacing styles
$phpWord->addParagraphStyle('line1FooterStyle', array( 'spaceAfter'=>20));
$phpWord->addParagraphStyle('line2FooterStyle', array( 'spaceAfter'=>380));
// add content
$footer->addText($footerText1,
array('name' => 'Helvetica', 'size' => 8),
array('space' => array('after' => 20))
);
$footer->addText($footerText2,
array('name' => 'Helvetica', 'size' => 8),
array('space' => array('after' => 380))
);
// textrun relocated to here
$textrun = $footer->addTextRun();
$textrun->addText('T', $boldSmallFontStyleName);
$textrun->addText(' ++353 1 555 0001 ', $smallFontStyleName);
$textrun->addText('E', $boldSmallFontStyleName);
$textrun->addText(' abc.def#ghk.ie ', $smallFontStyleName);
$textrun->addText('W', $boldSmallFontStyleName);
$textrun->addText(' abcd.ie/wxz', $smallFontStyleName);
OK, I saw the problem and fixed it. I had declared the textrun before the $footer->addText lines. Which means the textrun code was inserted first, incorrectly. D'oh!
I need to set the header for FIRST page only and the footer for every page. Can't figure a way and I've been search for the solution DAYS already. Currently my code goes like this
$mpdf=new mPDF();
$mpdf->useOddEven = true;
$mpdf->SetHTMLHeader('<div style="text-align: right;"><img src="var:images"
width="80px"/></div>', 'O');
$mpdf->SetHTMLFooter('<div style="text-align: left; font-family: Arial, Helvetica,
sans-serif; font-weight: bold;font-size: 7pt; ">Footer</div>');
$html = 'Content';
$mpdf->WriteHTML($html);
$mpdf->Output();
I've set the header to Odd however, both header and footer appears on other odd page (3, 5, 7,... page). Is there a way to make the header first page only but the footer appears in every page?
Currently using MPDF5.6
According to the Documentation:
https://mpdf.github.io/reference/mpdf-functions/sethtmlheader.html
The Third Parameter is:
write
If TRUE it forces the Header to be written immediately to the current page. Use if the header is being set after the new page has been added.
DEFAULT: FALSE
SO..
$mpdf->SetHTMLHeader('<div style="text-align: right;"><img src="var:images" width="80px"/></div>', 'O', true);
$mpdf->SetHTMLHeader('');
$footer = array (
'L' => array (
'content' => 'Footer',
'font-size' => 7,
'font-style' => 'B',
'font-family' => 'Arial, Helvetica, sans-serif',
'color'=>'#000000'
),
'C' => array (
'content' => '',
'font-size' => 10,
'font-style' => 'B',
'font-family' => 'serif',
'color'=>'#000000'
),
'R' => array (
'content' => '',
'font-size' => 10,
'font-style' => 'B',
'font-family' => 'serif',
'color'=>'#000000'
),
'line' => 1,
);
$mpdf->SetFooter($footer);
Only the SetFooter Method can set for the footer for both ODD & EVEN pages.
I am trying to make a PDF document with TCPDF using HTML code.
At the moment I use this code:
// set font
$pdf->SetFont('dejavusans', '', 36);
// add a page
$pdf->AddPage();
$html = '
<style>
.h1 {
color: #2B6999;
font-weight: normal;
}
</style>
<h1 class="h1">Test</h1>
';
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, 'C');
How can I position this text? I cannot use between the tags margin-top etc..
Can anyone help me with this problem?
You can add something like this:
$tagvs = array('h1' => array(0 => array('h' => 1, 'n' => 3), 1 => array('h' => 1, 'n' => 2)),
'h2' => array(0 => array('h' => 1, 'n' => 2), 1 => array('h' => 1, 'n' => 1)));
$pdf->setHtmlVSpace($tagvs);
And here is the format description from the docs / examples:
File: tcppdf.php :
/**
* Set the vertical spaces for HTML tags.
* The array must have the following structure (example):
* $tagvs = array('h1' => array(0 => array('h' => '', 'n' => 2), 1 => array('h' => 1.3, 'n' => 1)));
* The first array level contains the tag names,
* the second level contains 0 for opening tags or 1 for closing tags,
* the third level contains the vertical space unit (h) and the number spaces to add (n).
* If the h parameter is not specified, default values are used.
* #param $tagvs (array) array of tags and relative vertical spaces.
* #public
* #since 4.2.001 (2008-10-30)
*/
File http://www.tcpdf.org/examples/example_061.phps :
// REMOVE TAG TOP AND BOTTOM MARGINS
//
// $tagvs = array('p' => array(0 => array('h' => 0, 'n' => 0), 1 => array('h' => 0, 'n' => 0)));
// $pdf->setHtmlVSpace($tagvs);
//
// Since the CSS margin command is not yet implemented on TCPDF, you
// need to set the spacing of block tags using the above method.
You are using writeHTML which outupts the HTML exactly, you need to use the "$pdf->Cell" function. There are lots of example on this here http://www.tcpdf.org/examples.php