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!
Related
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);
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 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'm editing my invoices file in
/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php
And I'm running into a problem with columns running into and overlapping other columns if they have long content. eg Product description running over the next column. I'm trying to figure out how to limit the width / word wrap / create a new line for content.
Code is:
// draw Product name
$lines[0] = array(array(
'text' => Mage::helper('core/string')->str_split($item->getName(), 60, true, true),
'feed' => 35,
));
// draw SKU
// $lines[0][] = array(
// 'text' => Mage::helper('core/string')->str_split($this->getSku($item), 25),
// 'feed' => 255
// );
// draw Brand (Added by James)
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $this->getSku($item), array('manufacturer'));
if ($product) {
$lines[0][] = array(
'text' => Mage::helper('core/string')->str_split($product->getAttributeText('manufacturer'), 15),
'feed' => 220
);
}
// draw Colour (Added by James)
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $this->getSku($item), array('pos_short_colour'));
if ($product) {
$lines[0][] = array(
'text' => Mage::helper('core/string')->str_split($product->getAttributeText('pos_short_colour'), 15),
'feed' => 320
);
}
I know that 'feed' is what sets how far in from the left the array starts (pretty much = to a margin-left if all items were 'absolute' in css terms).
But I'm not sure how I can limit their width and word-wrap so that if I have a long manufacturer it won't run into the colour. There isn't enough space on the invoice to just simply give each attribute more room.
The answer was right there:
$lines[0] = array(array(
'text' => Mage::helper('core/string')->str_split($item->getName(), 60, true, true),
'feed' => 35,
));
The 60 here is how many characters will be displayed per line ->getName(), 60, true,
I had the same issue. When I added a new column, Product description column disappeared. I solved this by reducing a number (length) in str_split function of $productDescr.
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