pdf文件codeigniter中的tcpdf打印选项启用

时间:2017-03-14 11:09:16

标签: php codeigniter pdf

$pdf->SetProtection($permissions=array('print', 'copy'),
$user_pass=$otp, $owner_pass=$otp, $mode=0, $pubkeys=null);

我在Codeigniter中使用TCPDF生成了PDF文件。打印选项是通过使用上面的代码启用但它不起作用?为什么?请帮帮我。

2 个答案:

答案 0 :(得分:0)

That is how pdf generates :

require_once('tcpdf_include.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Ken');
$pdf->SetTitle('Upgraded Images');
$pdf->SetSubject('Order Label');
$pdf->SetKeywords('upgraded images, PDF, ken greenle, upgradedimages.com, print label');

// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 049', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins


// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set font
$pdf->SetFont('helvetica', '', 10);

// add a page
$pdf->AddPage();


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

IMPORTANT:
If you are printing user-generated content, tcpdf tag can be unsafe.
You can disable this tag by setting to false the K_TCPDF_CALLS_IN_HTML
constant on TCPDF configuration file.

For security reasons, the parameters for the 'params' attribute of TCPDF
tag must be prepared as an array and encoded with the
serializeTCPDFtagParameters() method (see the example below).

 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
$order_id = $_GET['order_id'];
/* get order details here*/
$sql = "select o.*,u.`first_name`,u.`last_name` from `tbl_orders` as o inner join `tbl_users` as u on o.`client_id` = u.`user_id` where o.`order_id` = '".$order_id."'";
$query = mysqli_query($con,$sql);
$result = mysqli_fetch_assoc($query);
$customer_name = $result['first_name'].' '.$result['last_name'];
$order_number = $result['order_number'];
$instructions = $result['instructions'];
$product_return_option = $result['product_return_option'];
$number_of_packages = $result['number_of_packages'];
$order_date = date("jS F", strtotime($result['order_date']));
if($result['rush_service'] != '')
{
    $rush_service = 'RUSH';
}
else
{
    $rush_service = '';
}

/* end here */
$html = '
<div style="border:2px solid #222; padding-right:10px;">
<table cellpadding="0" border="0" cellspacing="0" style="font-size:14px;">
 <tr>
 <td>
    <table width="100%">
    <tr>
    <td align="left">
    <span style="color:#000; text-align: left; font-size:24px;text-transform: uppercase;max-width: 200px;"><strong>'.$customer_name.'</strong></span><br>
    </td>
    <td align="left">
    <br>
    <span style="color:#000; text-align: right; font-size:14px;"><strong>'.$order_number.'</strong></span><br>
    <span>&nbsp;</span><span>&nbsp;</span><span style="color:#000; text-align: right; font-size:14px;"><strong>'.$order_date.'</strong></span>
    <br>
    </td>
    </tr>
    </table>
 </td>
 </tr>

 <tr>
 <td>
    <table width="100%">
    <tr>
        <td style="height:10px;">&nbsp;</td>
    </tr>
    <tr>
    <td align="left" style="color:#000; text-align: left; #000;font-weight: bold; font-size:14px;">
    '.$instructions.'
    </td>
    </tr>
    <tr>
        <td style="height:10px;">&nbsp;</td>
    </tr>
    </table>
 </td>
 </tr>
 <tr>
 <td>
    <table width="100%">
    <tr>
    <td style="">

    <span style="color:#000; text-align: left; font-size:54px;"><strong>'.$rush_service.'</strong></span><br>
    </td>
    <td align="left" style="padding-right:20px;">
    <span style="color:#000; text-align: right; font-size:14px;"><strong>'.$product_return_option.'</strong></span><br>
    </td>
    <td align="left" style="padding-right:20px;">
    <span style="color:#000; text-align: right; font-size:14px;"><strong>['.$number_of_packages.']</strong></span><br>
    </td>
    </tr>
    </table>
 </td>
 </tr>
  </table>
  </div>';


// output the HTML content
$pdf->writeHTML($html, true, 0, true, 0);

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

// reset pointer to the last page
$pdf->lastPage();

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output('text.pdf', 'D');exit;
// D for download and when you write I it will get opened.

答案 1 :(得分:0)

是的,我得到了它。实际上最新的版本代码不支持“montserrat”字体每当我们使用这个字体打印选项不起作用。使用“helvetica”font.it将起作用。