Look at this code:
$pdf->Ln(4);
$pdf->SetFont('helvetica', '', 14);
$pdf->SetFillColor(200, 220, 255);
$pdf->Cell(180, 6, 'Education', 0, 1, '', 1);
$pdf->Ln(4);
$pdf->SetFont('helvetica', '', 10);
$html = '
Degree ...................... <strong>' . $education->degree_title . '</strong>
<br/>
Graduation Date ............. ' . date('m-d-Y', strtotime($education->award_date)) . '
<br/>
Attendance .................. ' . date('m-d-Y', strtotime($education->school_start_date)) . ' - ' . date('m-d-Y', strtotime($education->school_end_date)) . '
<br/>';
$pdf->writeHTML($html, true, false, true, false, '');
Because it's running when the setting is:
$pdf->setCellMargins(30, 0, 0, 0);
The end result is:
As you can see, the html <strong> causes the part of the HTML that is to be bolded, to be influenced by the "30" value in the setCellMargins. IF you don't use <strong> or any other HTML element for that matter the formatting is fine.
Is there any way around this bug? I don't want to stop using the left cell margin, and i certainly don't want to discontinue using bold in my PDF.
Related
I have a website made by previous developed( Now he is not available ).
I have to access to CMS, payment backend everything, But old developer didnt left any records of database.
I am trying to rename or replace some of the text(company details) in receipt, but I dont know what am i doing wrong.
If I had an access to DB , it would be ease like butter.
Here is what I want to do :
You can see that I tried to include direct text "www.transit.com" , but it didnt show up on receipt .
Instead it showed blank.
I know its pointing to DB name like 'shop_name' and so on. But since I dont have any details on DB , I cant change it from DB.
function setShopData() {
// ショップ情報
$objDb = new SC_Helper_DB_Ex();
$arrInfo = $objDb->sfGetBasisData();
// ショップ名
$this->lfText(125, 60, $arrInfo['shop_name'], 8, 'B');
// URL
$this->lfText(125, 63, $arrInfo['www.transit.com'], 8);
// 会社名
$this->lfText(125, 68, $arrInfo['law_company'], 8);
// 郵便番号
$text = '〒 ' . $arrInfo['law_zip01'] . ' - ' . $arrInfo['law_zip02'];
$this->lfText(125, 71, $text, 8);
// 都道府県+所在地
$text = $this->arrPref[$arrInfo['law_pref']] . $arrInfo['law_addr01'];
$this->lfText(125, 74, $text, 8);
$this->lfText(125, 77, $arrInfo['law_addr02'], 8);
$text = 'TEL: '.$arrInfo['law_tel01'].'-'.$arrInfo['law_tel02'].'-'.$arrInfo['law_tel03'];
//FAX番号が存在する場合、表示する
if (strlen($arrInfo['law_fax01']) > 0) {
$text .= ' FAX: '.$arrInfo['law_fax01'].'-'.$arrInfo['law_fax02'].'-'.$arrInfo['law_fax03'];
}
$this->lfText(125, 80, $text, 8); //TEL・FAX
if (strlen($arrInfo['media-support.transit-grp.com']) > 0) {
$text = 'Email: '.'media-support.transit-grp.com';
$this->lfText(125, 83, $text, 8); //Email
}
So is there anyway I can replace these code, so that it would reflect on receipt?
Thank you
Try:
$this->lfText(125, 63, 'www.transit.com', 8);
You were referring to your array, but it didn't contain that key, you simply wanted to use a hardcoded string instead.
For the email (for instance) do:
$text = 'Email: mycompany#gmail.com';
$this->lfText(125, 83, $text, 8);
I suppose the best option is to replace the value in the array, that way any other places where this name is used will also be replaced.
function setShopData() {
// ショップ情報
// Here is the change:
$arrInfo['shop_name'] = "something else";
$objDb = new SC_Helper_DB_Ex();
$arrInfo = $objDb->sfGetBasisData();
// ショップ名
$this->lfText(125, 60, $arrInfo['shop_name'], 8, 'B');
// URL
$this->lfText(125, 63, $arrInfo['www.transit.com'], 8);
// 会社名
$this->lfText(125, 68, $arrInfo['law_company'], 8);
// 郵便番号
$text = '〒 ' . $arrInfo['law_zip01'] . ' - ' . $arrInfo['law_zip02'];
$this->lfText(125, 71, $text, 8);
// 都道府県+所在地
$text = $this->arrPref[$arrInfo['law_pref']] . $arrInfo['law_addr01'];
$this->lfText(125, 74, $text, 8);
$this->lfText(125, 77, $arrInfo['law_addr02'], 8);
$text = 'TEL: '.$arrInfo['law_tel01'].'-'.$arrInfo['law_tel02'].'-'.$arrInfo['law_tel03'];
//FAX番号が存在する場合、表示する
if (strlen($arrInfo['law_fax01']) > 0) {
$text .= ' FAX: '.$arrInfo['law_fax01'].'-'.$arrInfo['law_fax02'].'-'.$arrInfo['law_fax03'];
}
$this->lfText(125, 80, $text, 8); //TEL・FAX
if (strlen($arrInfo['law_email']) > 0) {
$text = 'Email: '.$arrInfo['law_email'];
$this->lfText(125, 83, $text, 8); //Email
}
One thing that I find odd is function setShopData() { that is usually function setShopData($arrInfo) {.
Since that is missing I assume the array is global and is set somewhere else.
At some point in the code there is a line like:
$arrInfo['shop_name'] =<database value>
If you place the line above in the code just below this any changes in the rest of the code will have the new shopname everywhere, not just on the receipt.
I am facing problem to generate japanese text based pdf using TCPDF. Previously I was working in raw php, html and css and tcpdf was working just fine with the following code:
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
if (#file_exists(APPPATH . 'libraries/tcpdf/examples/lang/eng.php')) {
require_once(APPPATH . 'libraries/tcpdf/examples/lang/eng.php');
$pdf->setLanguageArray($l);
}
if (#file_exists(APPPATH . 'libraries/tcpdf/examples/lang/jpn.php')) {
require_once(APPPATH . 'libraries/tcpdf/examples/lang/jpn.php');
$pdf->setLanguageArray($l);
}
$pdf->setLanguageArray($l);
$pdf->setPrintHeader(false);
$pdf->setFontSubsetting(true);
$pdf->SetFont('cid0jp', '', 11);
$pdf->AddPage();
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output('result.pdf', 'I');
which can generate my desired pdf with japanese text.
氏名
(全角・名字と名前の間に字スペー
ス)
Name
(Last Name/First name)
But when I tried to include this in codeigniter controller, the japanese texts are showing question marks in the generated pdf:
require_once(APPPATH . 'libraries/tcpdf/tcpdf.php');
The pdf output becomes like the following:
??
(?????????????????)
Name
(Last Name/First name)
What I am missing? Can anybody give me a solution? I will greatly appreciate a help here.
You can try any one from listed (because I'm not sure which one works for you):-
1) $pdf->SetFont('kozgopromedium', '', 11);
2) $pdf->SetFont('kozminproregular', '', 11);
3) $pdf->SetFont('cid0jp', '', 11);
4) $pdf->SetFont('arialunicid0', '', 11);
5) $pdf->SetFont('arialuni', '', 12);
If you have font file(.ttf) in your system, then you can give path also like :-
$pdf->addTTFfont('path/myfont.ttf', '', '', 11);
I am trying to set up a labeling printing system in PHP and on each label I would like to add a logo on top of it and I can't manage to work it, because on fpdf images are treated as a cell it doesn't work
EDIT:
The code is as follows:
for($i=1;$i<=$nolabels;$i++) {
$text = sprintf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s%s%s", "", "","","", "$destination", "$label", "USE BY: $date", "$i", '/', "$nolabels");
$pdf->Add_Label($text);}
for($i=1;$i<=$nolabels2;$i++) {
$text = sprintf("%s\n%s\n%s\n%s%s%s", "$destination", "$label2", "USE BY: $date", "$i", '/', "$nolabels2");
$pdf->Add_Label($text);
You can make additional "addHeader" and call it on each page. Here is one example with using X and Y coordinates
public function addHeader($pdf, $addPageNum)
{
// Header
if ($addPageNum) {
$pdf->SetFont('Arial', '', 10);
$pdf->SetTextColor(168, 168, 168);
$pdf->SetXY(20, 265);
$pdf->Cell(0, 5, __('Page') . ' ' . $pdf->PageNo() . ' von ' . '{nb}', 0, 1, 'C', 0);
}
// Footer photo
$pdf->Image(ROOT . '/webroot/img/companyLogo.png', 0, 270, 210);
}
I am trying to add a landscape page in the middle of a portrait PDF generated from HTML. I have set AutoPageBreak to true, but this results in the pages overlapping when I call AddPage(). For example:
$pageBody = "<h1>Test</h1><p>Long content here so that auto page break comes into effect</p>";
$pageBody .= "<br pagebreak=\"true\" /><h2>Page Two</h2>";
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->AddPage();
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->writeHTMLCell(170, '', 20, 50, $pageBody, 0, 0, false, true, '', true);
$pdf->endPage();
$pageBody2 = "<h1>Test Page 3 Landscape</h1>";
$pdf->AddPage('L');
$pdf->writeHTMLCell(170, '', 20, 50, $pageBody2, 0, 0, false, true, '', true);
$pdf->endPage();
$pdf->Output('my.pdf', 'I');
That results in the first pages displaying correctly (after being auto page broken), but the second content, pageBody2, being overlapped on top of the first set of page(s).
You need to change the $ln (7th) parameter of the writeHTMLCell() calls in your AutoPageBreak-broken pages from 0 to 1 (or 2):
$pdf->writeHTMLCell(170, '', 20, 50, $pageBody, 0, 1, false, true, '', true);
so that the new landscape page goes to the beginning of the next line (1) or below (2) the last box of $pageBody instead of to the right of it.
for adding pagebreak,use
<br pagebreak="true"/>
or
<tcpdf method="AddPage" />
I am having an issue with generating pdf documents. My tabulator characters are not displayed properly. I already tried different fonts, or encodings (UTF-8, Windows1552).
With some fonts the character is completely hidden. With some I get a square symbol displayed instead of my tab "\t".
Here is my code.
The question is "How to display tabs using Zend_PDF?"
public function generate()
{
$pdf = new Zend_Pdf();
$page = new Zend_Pdf_Page( Zend_Pdf_Page::SIZE_A4 );
//render basic template
$template = Zend_Pdf_Image::imageWithPath( APPLICATION_PATH . '/resources/pdf/template.png' );
$page->drawImage( $template, 0 ,0, 595, 842 );
//render document title
$font = Zend_Pdf_Font::fontWithPath( APPLICATION_PATH . '/resources/pdf/arial-bold.ttf' );
$page ->setFont($font, 14)
->drawText( 'Rechnung', 390, 700, 'utf-8' );
//render reciever adress
$font = Zend_Pdf_Font::fontWithPath( APPLICATION_PATH . '/resources/pdf/arial.ttf' );
$adressText = array(
'Kundennummer' . "\t" . $this->_user->getUserIdString(),
'Belegnummer' . "\t" . $this->_payin->getPayinIdString(),
'Datum' . "\t\t\t" . $this->_payin->getDateCreated()->format( 'd.m.Y' ),
'Seite' . "\t\t\t" . '1/1'
);
$page ->setFont($font, 12);
$adressY = 680;
foreach( $adressText as $line )
{
$page->drawText( $line, 390, $adressY , 'utf-8' );
$adressY -= 12;
}
//add page to pdf document
$pdf->pages[] = $page;
//save pdf
$pdf->save( $this->getOption( 'path' ) );
}
It could be that the pdf doesn't understand \t.
Try replacing it with 'chr(9)' which is the ascii value of the tab character. For example:-
$tab = chr(9);
$adressText = array(
'Kundennummer' . $tab . $this->_user->getUserIdString(),
'Belegnummer' . $tab . $this->_payin->getPayinIdString(),
// etc..
);
Correction:
As you have to supply the x,y coordinates to Zend_Pdf_Page::drawText() things like tabs, line feeds, etc will not work.
You will have to set fixed coordinates for your tab stops.
For example:-
$tabs = array(5, 20, 30, 50);
$page->drawText("At 1st tab", $tabs[0], 10);
$page->drawText("At 2nd Tab", $tabs[1], 10);
$page->drawText("At 3rd Tab", $tabs[2], 10);
Hopefully you get the idea.