TCPDF的example_001.php的参数解释

<?php
//============================================================+
// File name   : example_001.php
// Begin       : 2008-03-04
// Last Update : 2013-05-14
//
// Description : Example 001 for TCPDF class
//               Default Header and Footer
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com LTD
//               www.tecnick.com
//               info@tecnick.com
//============================================================+

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: Default Header and Footer
 * @author Nicola Asuni
 * @since 2008-03-04
 */

// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');

// create new PDF document
/**
 * 参数解释
 * 1 样式排版 P/L 竖向/横向
 * 2 测量单位 pt(point)/mm(millimeter)/cm(centimeter)/in(inch) 磅/毫米/厘米/英寸
 * 3 输入的文字内容是否经过编码 true/false 默认true
 * 4 文字的编码格式,因为输入html的时候,是可以指定页面的编码方式的,所以特别针对那个设置了这个参数 默认 UTF-8
 * 5 是否开启磁盘存储 true/false 建议不开启 默认 false
 * 6 pdfa是pdf格式的一种,主要为了长期保存,所以关闭了一些功能,这里就是询问是否开启PDF/A 模式,默认false
 * getPageSizeFromFormat(), setPageFormat(),说去看这两个函数,再说吧
 */
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);// 创建者
$pdf->SetAuthor('Nicola Asuni');// 作者
$pdf->SetTitle('TCPDF Example 001');// 标题
$pdf->SetSubject('TCPDF Tutorial');// 主题
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');// 关键字

// set default header data
/**
 * 参数解释
 * 1 页面顶部logo的url地址
 * 2 页面顶部logo的宽度
 * 3 页面顶部的标题
 * 4 页面顶部的文字
 * 5 RGB,文字颜色
 * 6 RGB,行颜色
 */
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
/**
 * 参数解释
 * 1 底部文字颜色
 * 2 底部行的颜色
 */
$pdf->setFooterData(array(0,64,0), array(0,64,128));

// 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
/**
 * 参数解释,左,上,右的缩进距离,
 * 最后一个参数是是否所有页面都按照这个值,如果是true的话,则接下来页面的单独设置将失效
 */
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
/**
 * 参数解释,设置顶部文字到页面顶部之间的距离
 */
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
/**
 * 参数解释,设置底部文字到页面底部之间的距离
 */
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
/**
 * 参数解释
 * 是否开启自动截断模式,如果页面底部的元素超过设定值,则自动跳转到下一页,这个值默认是2cm
 * 1 是否开启这个设定
 * 2 距离
 */
$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 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.
/**
 * 设置字体
 * 参数解释
 * 1 字体名字
 * 2 字体样式,支持一些快捷设置,但是还是直接写CSS吧,还有一些效果对一些特殊字体没有效果
 * 3 字体大小,单位是points,默认是12英镑
 * 4 字体库文件
 * 5 子集库是否开启
 */
$pdf->SetFont('dejavusans', '', 14, '', true);

// Add a page
// This method has several options, check the source code documentation for more information.
/**
 * 新建一个页面
 * 参数解释
 * 1 方向 P/L
 * 2 页面大小,可以是 getPageSizeFromFormat()/setPageFormat()
 * 3 是否依旧采用$pdf设置的左,上,右的偏移量
 * 这里再说一下getPageSizeFromFormat()函数就是返回一个两个值的数组
 */
$pdf->AddPage();

// set text shadow effect
/**
 * 设置文字的阴影效果,我用不到,所以自己去搜源码吧
 */
$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));

// Set some content to print
$html = <<<EOD
<h1>Welcome to <a href="http://www.tcpdf.org" style="text-decoration:none;background-color:#CC0000;color:black;">&nbsp;<span style="color:black;">TC</span><span style="color:white;">PDF</span>&nbsp;</a>!</h1>
<i>This is the first example of TCPDF library.</i>
<p>This text is printed using the <i>writeHTMLCell()</i> method but you can also use: <i>Multicell(), writeHTML(), Write(), Cell() and Text()</i>.</p>
<p>Please check the source code documentation and other examples for further information.</p>
<p style="color:#CC0000;">TO IMPROVE AND EXPAND TCPDF I NEED YOUR SUPPORT, PLEASE <a href="http://sourceforge.net/donate/index.php?group_id=128076">MAKE A DONATION!</a></p>
EOD;

// Print text using writeHTMLCell()
/**
 * 参数解释
 * 1 宽度,0的话,就配合左右的偏移量,充满整个屏幕
 * 2 最小高度,如果内容超过则会自动增加
 * 3 距离左上角,在X轴上的距离
 * 4 距离左上角,在Y轴上的距离
 * 5 $html,传入的输入值
 * 6 边框,可选值为 0 无边框 1 有边框,或者一个包含以下内容的字符串,或者一个数组,他只给了数组的例子,所以直接看数组吧:
 * array('LTRB' => array('width' => 2, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)))
 * 7 该部分内容填充完成后,接下来将从哪里开始输出内容,可选值有 0 右侧 1 另起一行 2 下一页
 * 8 该部分内容的背景是否要采用$html设置的值,还是采用系统定义好的值
 * 9 是否重新计算底部的高度?
 * 10 文字的对齐方式 L 左对齐 C 居中 R 右对齐
 * 11 系统将计算padding值,保证每行的宽度都是一致的
 */
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);

// ---------------------------------------------------------
$filePath="/Users/yangqingxian/Desktop/PDFExample/";
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
/**
 * 参数解释
 * 1 保存的文件名
 * 2 文件的输出方式 I 预览模式 D 下载模式 F 保存到本地文件夹 S 将文件内容作为字符串返回,FI=F+I,FD=F+D,E,将返回email的附件形式
 */
$pdf->Output('example_001.pdf', 'F');

//============================================================+
// END OF FILE
//============================================================+

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值