php使用tcpdf结合xhtml生成pdf文档代码

代码语言:php

所属分类:其他

代码描述:php使用tcpdf结合xhtml生成pdf文档代码,支持style及xhtml元素布局。

代码标签: php tcpdf xhtml 生成 pdf 文档 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<?php
require('../lib/php/vendor/autoload.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('pdf作者');
$pdf->SetTitle('PDF标题');
$pdf->setCreator('bfwstudio工具');
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

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

// set margins
$pdf->SetMargins(10, 10, 10);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

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

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

// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();

// set default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('msyh', '', 11, '', true);

// set text shadow effect
$pdf->setTextShadow(array('enabled'=>false));
// Set some content to print
$html ='
<style>
input{
border:0;
border-bottom: 1px solid #cccccc;
padding:5px;
}
</style>
<div >
<h1>测试生成PDF</h1>

<table cellspacing="0" border="1px"> 
  <tbody>
    <tr>
        <td>AAAA</td>
        <td>BBBB</td>
        <td>CCCC</td>
    </tr> 
       <tr>
        <td>AAAA</td>
        <td>BBBB</td>
        <td>CCCC</td>
    </tr> 
       <tr>
        <td>AAAA</td>
        <td>BBBB</td>
        <td>.........完整代码请登录后点击上方下载按钮下载查看

网友评论0