I am creating a pdf using TCPDF and everything is rendering the way that I want it. There is an area that is dynamic where it writes a variable number of lines. This area is rendered using writeHTMLCell. After this is rendered I want to place a signature image using $pdf->ImageSVG in the area marked '{SIGNATURE HERE}'. What are the dynamic coordinates based on variable lines ahead of it to place it in the correct position.
Thank you for any help.
$tbl = '<p>It is hereby requested that you prepare for use on (check one) ';
if($appeal_non=='appeal') {
$tbl .= ' <u>[X] appeal</u> [ ]non-appeal* ';
}else{
$tbl .= ' [ ]appeal <u>[X] non-appeal*</u> ';
}
$tbl .= ' an original and <u>'.$quant.'</u> copies of the following:</p>';
$tbl .='<table cellspacing="0" cellpadding="1" border="0" >
<tr>
<td>DATE OF PROCEEDING</td>
<td>TYPE OF PROCEEDING <br />(e.g., trial, sentencing, motion, etc.)</td>
<td>NAME OF JUDGE</td>
</tr>';
$p=0;
foreach($proc_date as $proc){
$tbl .= '<tr>
<td>'.$proc.'</td>
<td>'.$proc_type[$p].'</td>
<td>'.$proc_judge[$p].'</td>
</tr>';
$p = $p + 1;
}
$tbl .= '</table>
<p>I agree to pay for the preparation and any copies ordered of the transcript(s) for the above date(s) pursuant to R. 2:5-3(d).</p>
<table cellspacing="0" cellpadding="1" border="0" >
<tr>
<td><p> <br />{SIGNATURE HERE}<br/> </p></td>
<td>'.$sig_date.'</td>
</tr>
<tr>
<td><hr />SIGNATURE OF REQUESTING PARTY</td>
<td><hr />DATE</td>
</tr>
</table>
<p>Transcript fees are set by New Jersey Statute 2B:7-4. An additional sum or reimbursement may be required prior to or at the
completion of the transcript order.</p>
<p style="text-align:center;">DEPOSIT ATTACHED: $<u>'.$depositAmount.'</u></p>
';
$pdf->writeHTMLCell(0, '', '', '', $tbl, 1, 1, false, true, 'L', true);
$tbl = '<table cellspacing="0" cellpadding="1" border="0" >
<tr>
<td colspan="2">* Only the Supervisor of Court Reporters should receive copies of non-appeal transcript requests.</td>
</tr>
<tr>
<td width="5%">CC:</td>
<td width="95%">1. CLERK, Appellate Division, or CLERK, Supreme Court (see INSTRUCTIONS above)</td>
</tr>
<tr>
<td width="5%"></td>
<td width="95%">2. County Supervisor of Court Reporters _______</td>
</tr>
<tr>
<td width="5%"></td>
<td width="95%">3. Other attorneys/<span style="border-bottom: 1px solid;">Pro</span> <span style="border-bottom: 1px solid;">Se</span> parties _________</td>
</tr>
</table>';
//$sigY = $pdf->SetY($sigY);
$pdf->writeHTMLCell(0, '', '', '', $tbl, 1, 1, false, true, 'L', true);
//$sigY = $pdf->GetY();
//$sigY2 = $sigY - 40.2;
//$pdf->writeHTMLCell(0, '', '', '', '<p>'.$sigY.'<p>', 1, 1, false, true, 'L', true);
$pdf->ImageSVG($file='#'.$sig_code, $x='', $y='$sigY2', $w='80', $h='50', $link='', $align='B', $palign='L', $border=0, $fitonpage=true);
Related
I am trying to create a PDF with the data from my database. I divide my data to be displayed with many tables like shown below. I tried to fetch the data from my database with the $output and fetch data.
How can I do for each data to display below the corresponding that are in my tables with the same name?
Because i have different tables, should I do multiple function to fetch my data from database with each function for each table?
$session_id ="0";
function fetch_data()
{
$output = '';
$conn = mysqli_connect("localhost", "root", "", "thermoform_data");
$sql = "SELECT * FROM form_data WHERE id = '1' ORDER BY id ASC";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result))
{
$output .= '<tr>
<td>'.$row["id"].'</td>
<td>'.$row["session_id"].'</td>
<td>'.$row["manufacturing_name"].'</td>
<td>'.$row["head_office"].'</td>
<td>'.$row["legal_form"].'</td>
<td>'.$row["activity"].'</td>
<td>'.$row["filiales"].'</td>
<td>'.$row["products"].'</td>
<td>'.$row["website"].'</td>
<td>'.$row["telephone"].'</td>
<td>'.$row["fax"].'</td>
<td>'.$row["email"].'</td>
<td>'.$row["project_name"].'</td>
<td>'.$row["first_last_name_manager"].'</td>
<td>'.$row["title_manager"].'</td>
<td>'.$row["tel_manager"].'</td>
<td>'.$row["email_manager"].'</td>
<td>'.$row["country_manager"].'</td>
<td>'.$row["zip_code_manager"].'</td>
<td>'.$row["first_last_name_collaborator1"].'</td>
<td>'.$row["title_collaborator1"].'</td>
<td>'.$row["tel_collaborator1"].'</td>
<td>'.$row["email_collaborator1"].'</td>
<td>'.$row["country_collaborator1"].'</td>
<td>'.$row["zip_code_collaborator1"].'</td>
<td>'.$row["first_last_name_collaborator2"].'</td>
<td>'.$row["title_collaborator2"].'</td>
<td>'.$row["tel_collaborator2"].'</td>
<td>'.$row["email_collaborator2"].'</td>
<td>'.$row["country_collaborator2"].'</td>
<td>'.$row["zip_code_collaborator2"].'</td>
<td>'.$row["project_charter"].'</td>
<td>'.$row["project_management_plan"].'</td>
<td>'.$row["project_scope_plan"].'</td>
<td>'.$row["project_schedule_plan"].'</td>
<td>'.$row["project_risk_plan"].'</td>
<td>'.$row["project_work_plan"].'</td>
<td>'.$row["project_team_plan"].'</td>
<td>'.$row["material_type"].'</td>
<td>'.$row["manufacturer"].'</td>
<td>'.$row["trade_name"].'</td>
<td>'.$row["physical_properties"].'</td>
<td>'.$row["chemical_properties"].'</td>
<td>'.$row["alloy_composition"].'</td>
<td>'.$row["technology_solutions"].'</td>
<td>'.$row["reporting_and_dashboards"].'</td>
<td>'.$row["data_analysis"].'</td>
<td>'.$row["software_consulting"].'</td>
<td>'.$row["system_analysis"].'</td>
<td>'.$row["training"].'</td>
<td>'.$row["accounting_services"].'</td>
</tr>
';
}
return $output;
}
if(isset($_POST["generate_pdf"]))
{
require_once('TCPDF-master/tcpdf.php');
$obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$obj_pdf->SetCreator(PDF_CREATOR);
$obj_pdf->SetTitle("Form data");
$obj_pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);
$obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$obj_pdf->SetDefaultMonospacedFont('helvetica');
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
/*$obj_pdf->SetMargins(PDF_MARGIN_LEFT, '0', PDF_MARGIN_RIGHT); */
$obj_pdf->setPrintHeader(false);
$obj_pdf->setPrintFooter(false);
$obj_pdf->SetAutoPageBreak(TRUE, 10);
$obj_pdf->SetFont('helvetica', '', 9);
$obj_pdf->AddPage('L');
$content = '';
$content .= '
<h4 align="center">Form data</h4><br />
<table border="1" cellspacing="0" cellpadding="2">
<tr>
<th>Id</th>
<th>session_id</th>
<th>manufacturing_name</th>
<th>head_office</th>
<th>legal_form</th>
<th>activity</th>
<th>filiales</th>
<th>products</th>
<th>website</th>
<th>telephone</th>
<th>fax</th>
<th>email</th>
<th>project_name</th>
<th>first_last_name_manager</th>
<th>title_manager</th>
<th>tel_manager</th>
<th>email_manager</th>
<th>country_manager</th>
<th>zip_code_manager</th>
<th>first_last_name_collaborator1</th>
<th>title_collaborator1</th>
<th>tel_collaborator1</th>
<th>email_collaborator1</th>
<th>country_collaborator1</th>
<th>zip_code_collaborator1</th>
<th>first_last_name_collaborator2</th>
<th>title_collaborator2</th>
<th>tel_collaborator2</th>
<th>email_collaborator2</th>
<th>country_collaborator2</th>
<th>zip_code_collaborator2</th>
<th>project_charter</th>
<th>project_management_plan</th>
<th>project_scope_plan</th>
<th>project_schedule_plan</th>
<th>project_risk_plan</th>
<th>project_work_plan</th>
<th>project_team_plan</th>
<th>material_type</th>
<th>manufacturer</th>
<th>trade_name</th>
<th>physical_properties</th>
<th>chemical_properties</th>
<th>alloy_composition</th>
<th>technology_solutions</th>
<th>reporting_and_dashboards</th>
<th>data_analysis</th>
<th>software_consulting</th>
<th>system_analysis</th>
<th>training</th>
<th>accounting_services</th>
</tr>
';
$tbl1 = '';
$tbl1 .= '
<table border="1" cellpadding="2" cellspacing="2" nobr="true">
<tr>
<th colspan="11" align="center">NON-BREAKING TABLE</th>
</tr>
<tr>
<td>Id</td>
<td>session_id</td>
<td>manufacturing_name</td>
<td>head_office</td>
<td>legal_form</td>
<td>activity</td>
<td>filiales</td>
<td>products</td>
<td>websites</td>
<td>fax</td>
<td>email</td>
</tr>
</table>
';
$obj_pdf->writeHTML($tbl1, true, false, false, false, '');
$tbl2="";
$tbl2 .= '
<table border="1" cellpadding="2" cellspacing="2" nobr="true">
<tr>
<th colspan="7" align="center">NON-BREAKING TABLE</th>
</tr>
<tr>
<td>project_name</td>
<td>first_last_name_manager</td>
<td>title_manager</td>
<td>tel_manager</td>
<td>email_manager</td>
<td>country_manager</td>
<td>zip_code_manager</td>
</tr>
<tr>
<td>first_last_name_collaborator1</td>
<td>title_collaborator1</td>
<td>tel_collaborator1</td>
<td>email_collaborator1</td>
<td>country_collaborator1</td>
<td>zip_code_collaborator1</td>
</tr>
<tr>
<td>first_last_name_collaborator2</td>
<td>title_collaborator2</td>
<td>tel_collaborator2</td>
<td>email_collaborator2</td>
<td>country_collaborator2</td>
<td>zip_code_collaborator2</td>
</tr>
</table>
';
$obj_pdf->writeHTML($tbl2, true, false, false, false, '');
$tbl3="";
$tbl3 .='
<table border="1" cellpadding="2" cellspacing="2" nobr="true">
<tr>
<th colspan="7" align="center">NON-BREAKING TABLE</th>
</tr>
<tr>
<td>project_charter</td>
<td>project_management_plan</td>
<td>project_scope_plan</td>
<td>pproject_schedule_plan</td>
<td>project_risk_plan</td>
<td>project_work_plan</td>
<td>project_team_plan</td>
</tr>
</table>
';
$obj_pdf->writeHTML($tbl3, true, false, false, false, '');
$tbl4="";
$tbl4 .='
<table border="1" cellpadding="2" cellspacing="2" nobr="true">
<tr>
<th colspan="6" align="center">NON-BREAKING TABLE</th>
</tr>
<tr>
<td>material_type</td>
<td>manufacturer</td>
<td>trade_name</td>
<td>physical_properties</td>
<td>chemical_properties</td>
<td>alloy_composition</td>
</tr>
</table>
';
$obj_pdf->writeHTML($tbl4);
$tbl5="";
$tbl5 ='
<table border="1" cellpadding="2" cellspacing="2" nobr="true">
<tr>
<th colspan="6" align="center">NON-BREAKING TABLE</th>
</tr>
<tr>
<td>technology_solutions</td>
<td>reporting_and_dashboards</td>
<td>data_analysis</td>
<td>software_consulting</td>
<td>system_analysis</td>
<td>training</td>
<td>accounting_services</td>
</tr>
</table>
';
$obj_pdf->writeHTML($tbl5, true, false, false, false, '');
// -----------------------------------------------------------------------------
/* header('Content-type: application/pdf');*/
ob_get_clean();
$obj_pdf->setAutoPageBreak(true, 0);
$content .= fetch_data();
$content .= '</table>';
$obj_pdf->writeHTML($content);
$obj_pdf->Output('file.pdf', 'I');
}
?>
<!DOCTYPE html>
<html>
<head>
<title>SoftAOX | Generate HTML Table Data To PDF From MySQL Database Using TCPDF In PHP</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
</head>
<body>
<br />
<div class="container">
<h4 align="center"> Generate HTML Table Data To PDF From MySQL Database Using TCPDF In PHP</h4><br />
<div class="table-responsive">
<div class="col-md-12" align="right">
<form method="post" action="{{URL('index3')}}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<!-- <input type="number" name="session_id">-->
<input type="submit" name="generate_pdf" class="btn btn-success" value="Generate PDF" />
</form>
</div>
<br />
<br />
<table class="table table-bordered">
<tr>
<th width="5%">Id</th>
<th width="30%">Name</th>
<th width="15%">Age</th>
<th width="50%">Email</th>
</tr>
<?php
echo fetch_data();
?>
</table>
</div>
</div>
</body>
</html>
Right now, none of my data are showing, I only have the row and my table but no data from database inside. I expected to see the data below each rows of my table with the corresponding names.
I am trying to generate pdf with database values using tcpdf.
I have a function to fetch data like this
function fetch_data()
{
$output = '';
include('../connection.php');
// Colors, line width and bold font
//My sql
$sql ="";
$query = mysqli_query($con, $sql) or die (mysqli_error($con));
$total_amt = 0;
$tax_amt = 0;
while($row = mysqli_fetch_array($query)) {
$output .= '<tr>
<td style="border-bottom:1px thin #666; font-size:12px; font-weight:normal; font-style:normal;">'.$row["product"].' - '.$row['description'].'</td>
<td style="border-bottom:1px thin #666"; align="center">'.$row["uom"].'</td>
<td style="border-bottom:1px thin #666"; align="center">'.$row["price"].'</td>
<td style="border-bottom:1px thin #666"; align="center">'.$row["qty"].'</td>
<td style="border-bottom:1px thin #666"; align="center">'.$row["discount"].'</td>
<td style="border-bottom:1px thin #666"; align="center">'.$row["taxation"].'%</td>
<td style="border-bottom:1px thin #666"; align="center">'.$row["total"].'</td>
</tr>
';
$total_amt += $row['total'];
$tax_amt += $row['tax_amount'];
}
$output .= '<tr><td colspan="7" style="border-top:1px thin #666";></td></tr><tr><td colspan="5" align="left"><strong>Total</strong></td><td align="center">'.number_format($tax_amt,2).'</td><td align="center">'.number_format($total_amt,2).'</td></tr>';
return $output;
}
And i display it
$content = '';
$content .= '
<table border="1"><tr><td width="100%">
<table border="0">
<tr bgcolor="#796799" style="color:#FFF;">' ;
$pdf->SetFont('arsenalb', 'B', 12);
$content .= '
<th width="40%" style="border-left-width:14px;border-left-color:#796799;" height="30" align="center">Description</th>
<th width="10%" align="center">UOM</th>
<th width="13%" align="center">Price</th>
<th width="7%" align="center">Qty</th>
<th width="7%" align="center">Disc</th>
<th width="10%" align="center">Tax</th>
<th width="13%" align="center">Total</th>
</tr>
';
$pdf->SetFont('arsenal', '', 10);
$content .= fetch_data();
$content .= '</table></td></tr></table>';
$pdf->writeHTML($content);
I want only the table headers to be bold, so i have used $pdf->SetFont('arsenal', '', 10); after the header . But it is making the header also normal, not bold. if i remove this, then whole table data is becoming bold.
is there any way to separate the table something like this? https://tcpdf.org/examples/example_011/
The reason this wont work is quite simpel. You write all $content to the $pdf AFTER the second SetFont line. Meaning that the first line is used, but since no content is added to the pdf, it wont show anything.
Since tcpdf allows you to write HTML, wyy not use HTML to make the header bold? with the <b> tag. Another option is that you make two tables. One for the header and one for the content. Since you define the width of the columns, you can do this.
You'll get something like:
$hdr = 'full table with header data';
$pdf->SetFont('arsenalb', 'B', 12);
$pdf->writeHTML($hdr);
$content .= 'new table, with column with defined';
$content .= fetch_data();
$content .= '</table></td></tr></table>';
$pdf->SetFont('arsenal', '', 10);
$pdf->writeHTML($content);
but that might work depending on if you need that second outer table. If you need it, it will most likely not possilbe, unless you can write partial HTML yo $pdf->writeHTML(). I'm not sure you can/cannot.
I am using TCPDF to generate the pdf file.
<form method='post'>
<input type='submit' name='create_pdf' class='gs-btn-3' value='Create PDF'/>
</form>
<?php
if (isset($_POST["create_pdf"]))
{
require_once("myPDF/TCPDF/tcpdf.php");
$obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$obj_pdf->SetCreator(PDF_CREATOR);
$obj_pdf->SetTitle('Thisi is Serena first PDF example');
$obj_pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);
$obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '',PDF_FONT_SIZE_MAIN));
$obj_pdf->SetFooterFont(Array(PDF_FONT_NAME_DATA, '',PDF_FONT_SIZE_DATA));
$obj_pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$obj_pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$obj_pdf->SetMargins(PDF_MARGIN_LEFT, '5', PDF_MARGIN_RIGHT);
$obj_pdf->SetPrintHeader(false);
$obj_pdf->SetPrintFooter(false); //true
$obj_pdf->SetAutoPageBreak(TRUE, 10);
$obj_pdf->SetFont('dejavusans', '', 14);
$obj_pdf->AddPage();
$content = '
<h3 align="center"> Export HTML Table data to PDF using TCPDF in PHP</h3>
<table border="1" cellspacing="6" cellpadding="4">
<tr>
<th width="25%" align="center">Company Name</th>
<th width="25%">Contact</th>
<th width="10%">Address</th>
<th width="10%">Phone</th>
<th width="10%">Modify by</th>
<th width="10%">Modify on</th>
<th width="10%">EDIT</th>
</tr>
if(isset($this->culist) && is_array($this->culist) && sizeOf($this->culist) > 0) {
foreach($this->culist as $key=>$value) {
<tr>
<td style="width: 25%;">
<?php echo $value->companyname; ?>
</td>
<td style="width: 25%;">
<?php echo $value->firstname; ?>
</td>
<td style="width: 10%;">
<?php echo $value->address; ?>
</td>
<td style="width: 10%;">
<?php echo $value->phone; ?>
</td>
<td style="width: 10%;">
<?php echo $value->modified_by; ?>
</td>
<td style="width: 10%;">
<?php echo $value->modified_on; ?>
</td>
</tr>
}
</table>
';
$obj_pdf->WriteHTML($content, true, false, true, false, '');
ob_end_clean();
$obj_pdf->Output('sample.pdf', 'I');
}
?>
There are two errors,
First is the "TCPDF ERROR: Some data has already been output, can't send PDF file". I tried "ob_end_clean();" before "$obj_pdf->Output('sample.pdf', 'I');", it shows so many unreadable code.
Second is that the generated table is not from the scripts which showed above, rather the table comes from the the view.
Anyone who can help me? Thanks in advance.
I know this is a very old question. I do have an answer, atleast in my scenario .
same errors occur even with ob_end_clean() and no output.
strangely, when i remove ob_end_clean(); it gets output to pdf
I am saving my records as PDF but I want them saved by using name_empnumber like abc_123
I am using the code below and library TCFPDF
if (isset($_POST['submit'])){
require_once 'includes/practice.php';
//practice.php is using library tcfpdf
$pdf->SetFont('times', '', 15);
$tb1 = '</br></br>
<b>2- Printer:</b><br /><br />
<table cellspacing="0" cellpadding="0" border="1">
<tr style="background-color:#f7f7f7;color:#333; ">
<td width="300">SN</td>
<td width="300">TYPE</td>
</tr>
</table>';
$result= mysql_query("SELECT * FROM accessories where emp_number='".$emp_number."' && is_accessory='Printer'");
while($row = mysql_fetch_assoc($result)){
$tb2 = '<table cellspacing="0" cellpadding="2" border="1">
<tr>
<td width="300">'.$row['serial'].'</td>
<td width="300">'.$row['model'].'</td>
</tr>
</table>';
$tb1 = $tb1.$tb2;
}
$pdf->writeHTML($tb1, true, false, false, false, '');
ob_end_clean();
$pdf->Output('Report.pdf', 'D');
}
See this is saving as Report.PDF.
I want to save as name_empnumber.pdf like abc-123.pdf
I am using the TCPDF library to export Album / Catalog Release information for a music site, the Album consists of songs labels that could be in English, chinese or any other language, I am having a problem to print the non-English character correctly inside the tcpdf. Some points I would like to tell.
I am using Zend framework 1.12.
Database Connection collation utf8 .
Table field collation utf8_unicode_ci .
My scenario is that the information is coming from the database and I use a view to display information related to the album in a specific format along with the HTML. The release name is in Chinese 奥马尔阿斯拉姆, I tried all the options by searching on stackoverflow which were related to setting the font and changing character collation while initializing the TCPDF object, but whenever I print it displays the name like this 奥马尔阿斯拠i tried to utf8_encode() and utf8_decode() around the Release Name inside the HTML but nothing helps.
Another is an example is with the Latin characters where the name of the album is Extraña EP and when printed inside the pdf it displays it like Extraña EP.
Here is the HTML I use inside my view.
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top">
<img src="/images/release_details.png">
</td>
</tr>
<tr>
<td align="left" valign="top">
<table width="100%" cellpadding="0" cellspacing="0" class="release_table">
<tr>
<td align="left" valign="top" class="label">CATALOG #:</td>
<td align="right" valign="top" class="data"><?=$this->release->Catalog?></td>
</tr>
<tr>
<td align="left" valign="top" class="label">RELEASE NAME:</td>
<td align="right" valign="top" class="data"><?=$this->release->Name?></td>
</tr>
<tr>
<td align="left" valign="top" class="label">RELEASE TYPE:</td>
<td align="right" valign="top" class="data"><?=$releaseType?></td>
</tr>
<tr>
<td align="left" valign="top" class="label">UPC CODE:</td>
<td align="right" valign="top" class="data"><?=$this->release->UPCCode?></td>
</tr>
<tr>
<td align="left" valign="top" class="label">NUMBER OF SONGS:</td>
<td align="right" valign="top" class="data"><?=$this->release->TracksQty?></td>
</tr>
<tr>
<td align="left" valign="top" class="label">PRIMARY ARTIST:</td>
<td align="right" valign="top"
class="data"><?=$this->release->PrimaryArtist?></td>
</tr>
<tr>
<td align="left" valign="top" class="label">LABEL:</td>
<td align="right" valign="top" class="data"><?=$this->release->LabelName?></td>
</tr>
<tr>
<td align="left" valign="top" class="label">MAIN GENRE:</td>
<td align="right" valign="top" class="data"><?=$this->release->MainGenre?></td>
</tr>
<tr>
<td align="left" valign="top" class="label">GENRE:</td>
<td align="right" valign="top" class="data"><?=$this->release->Genre?></td>
</tr>
<tr>
<td align="left" valign="top" class="label">(C):</td>
<td align="right" valign="top"
class="data"><?=$this->release->CLine . " " . $this->release->CYear?></td>
</tr>
<tr>
<td align="left" valign="top" class="label">(P):</td>
<td align="right" valign="top"
class="data"><?=$this->release->PLine . " " . $this->release->PYear?></td>
</tr>
<?php if ($this->release->Howlong > 0 && $this->release->EffectiveDate > 0) {?>
<tr>
<td align="left" valign="top" class="label">EXCLUSIVE DATE:</td>
<td align="right" valign="top"
class="data"><?=$this->release->EffectiveDate?></td>
</tr>
<?php }?>
<tr>
<td align="left" valign="top" class="label">RELEASE DATE:</td>
<td align="right" valign="top" class="data"><?=$this->release->ReleaseDate?></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" valign="middle"> </td>
</tr>
<tr>
<td align="center" valign="middle">
<img src="/images/symphonic_logo.png"/>
</td>
</tr>
</table>
And here is the code where i call this view before i send the content to print in the pdf.
require_once APPLICATION_PATH . 'library/tcpdf/tcpdf.php';
$pdf = new TCPDF("L", "mm", "A4", false, 'ISO-8859-1', false);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetFont('helvetica', '', 11, '', true);
$pdf->SetMargins(1, -1, -1, false);
//$pdf->SetFont('dejavusans', '', 12);
//whole TCPDF's settings goes here
$this->view->songs = $releaseSongs;
$this->view->release = $releasInformation;
$htmlcontent = $this->view->render('exportpdf.phtml');
// output the HTML content
$pdf->AddPage();
$pdf->writeHTML($htmlcontent, true, false, true, false, '');
$pdf->lastPage();
$pdf->deletePage($pages + 1);
$pdf->Output($filename, 'D');
exit();
here are the few things that i did to correct my code.
used the custom fonts option to add the Ms arial unicode true type font.
I was adding the style tag with css classes where i was setting the font family inside the view which resulted in the garbage characters in case of non-english characters. This was the main mistake.
Here is he final working code
require_once(APPLICATION_PATH . 'library/tcpdf/tcpdf.php');
$pdf = new TCPDF("L", "mm", "A4", TRUE, 'utf-8', false);
$fontname = TCPDF_FONTS::addTTFfont(APPLICATION_PATH.'/../library/tcpdf/fonts/ARIALUNI.TTF','TrueTypeUnicode', '', 32);
$pdf->AddFont($fontname);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->setFontSubsetting(true);
$pdf->SetFont($fontname, '', 12, '', true);
$pdf->SetMargins(1, -1, -1, false);
//$pdf->SetFont('dejavusans', '', 12);
//whole TCPDF's settings goes here
$htmlcontent = $this->view->render('exportpdf.phtml');
// output the HTML content
$pdf->AddPage();
$pdf->writeHTML($htmlcontent, true, false, true, false, '');
$pdf->lastPage();
$pdf->deletePage($pages + 1);
$pdf->Output($filename, 'D');
The collation doesn't help if you want to work with UTF-8, it only determines the sorting order. What you propably need is to set the charset of the database connection, this you should set before you do any query/inserts:
// tells the mysqli connection to deliver UTF-8 encoded strings.
$db = new mysqli($dbHost, $dbUser, $dbPassword, $dbName);
$db->set_charset('utf8');
// tells the pdo connection to deliver UTF-8 encoded strings.
$dsn = "mysql:host=$dbHost;dbname=$dbName;charset=utf8";
$db = new PDO($dsn, $dbUser, $dbPassword);
Reading and writing your data with this connection, you should be able to set the encoding of your PDF to UTF-8.