- 浏览: 857017 次
- 性别:
- 来自: lanzhou
文章分类
最新评论
-
liu346435400:
楼主讲了实话啊,中国程序员的现状,也是只见中国程序员拼死拼活的 ...
中国的程序员为什么这么辛苦 -
qw8226718:
国内ASP.NET下功能比较完善,优化比较好的Spacebui ...
国内外开源sns源码大全 -
dotjar:
敢问兰州的大哥,Prism 现在在12.04LTS上可用么?我 ...
最佳 Ubuntu 下 WebQQ 聊天体验 -
coralsea:
兄弟,卫星通信不是这么简单的,单向接收卫星广播信号不需要太大的 ...
Google 上网 -
txin0814:
我成功安装chrome frame后 在IE地址栏前加上cf: ...
IE中使用Google Chrome Frame运行HTML 5
PDFlib
is not included with the default PHP 5.3 distribution, so you will have
to install it. Download the PHP version of the PHPlib library from here
. The Windows build of PHP 5 comes in many different varieties. I'll assume that you are using the VC9 non-thread safe build, and that you have installed PHP to the default location. Extract the libpdf_php.dll
file from the PDFlib-7.0.4p6-MSWin32-php\bind\php5\php-530-nozts_VS9\
directory in the PHPlib zip file to C:\Program Files\PHP\ext
. Then add the following two lines to the PHP.ini
file located in C:\Program Files\PHP
: [PHP_PDF]
extension=libpdf_php.dll
Open up a new try block, create a new PDFlib instance, and then start a new PDF document by calling begin_document
.
try {
$pdf=new PDFlib();
if(!$pdf->begin_document("",""))
{
throw new PDFlibException("Error creating PDF document. ".$pdf->get_errmsg());
}
The set_info
function allows you set some optional document properties. Here we define the author and title of the PDF document.
$pdf->set_info("Author","Matthew Casperson");
$pdf->set_info("Title","Create a PDF document with PHP");
The begin_page_ext
function
is called to start a new page in the PDF document. Here we have
specified the page to have dimensions of 595 x 842 points, making it an
A4 page.
$pdf->begin_page_ext(595,842,"");
Other common page sizes (in points) are:
a4
595 x 842
a5
421 x 595
a6
297 x 421
letter
612 x 792
legal
612 x 1008
ledger
1224 x 792
11x17
792 x 1224
To print any text to the PDF document we first need to prepare the font that will be used. The load_font
function takes a locally installed font and prepares it for use with PDFlib. The setfont
function specifies that we will be using this font when writing text.
$font=$pdf->load_font("Helvetica-Bold","winansi","");
$pdf->setfont($font,24.0);
Using the set_text_pos
and show
functions we can write some text to the PDF document at the specified location.
$pdf->set_text_pos(50,800);
$pdf->show("Hello World");
The end_page_ext
function ends the page that we started in step 4.
$pdf->end_page_ext("");
The end_document function ends the PDF document we started in step 2.
$pdf->end_document("");
Typically
a PHP script is used to send a HTML document. In this case we need to
override this default behaviour to tell the recieving browser that it
is about to recieve a PDF document. The following code creates the HTTP
headers required to identify the data being sent as a PDF document,
which will cause the browser to open up Adobe Reader (or the default
PDF application) when the data is transmitted.
$buffer=$pdf->get_buffer();
$len=strlen($buffer);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=example.pdf");
echo $buffer;
The try block is closed, and a catch block is created. If there were any errors creating the PDF document, the user is notified.
}
catch (PDFlibException $e)
{
echo 'Error Number:'.$e->get_errnum()."n";
echo 'Error Message:'.$e->get_errmsg();
}
PDFlib
makes creating PDF documents a breeze. You could extend this example to
allow users to download pre-filled PDF documents, or to create PDF
versions of a web page for easy printing.Step 1 - Install the PDFlib extension
Step 2 - Create the PDF document
Step 3 - Set the PDF properties
Step 4 - Create a new page
Step 5 - Prepare a font
Step 6 - Write some text
Step 7 - End the page
Step 8 - End the document
Step 9 - Send the PDF document
Step 10 - Deal with any errors
Conclusion
发表评论
-
26 Hints for Agile Software Development
2009-11-04 08:04 754I collect nuggets of wisdom on ... -
40个迹象表明你还是PHP菜鸟
2009-10-28 08:40 61240个迹象表明你还是PHP菜鸟 ... -
PHP performance tips
2009-10-21 09:15 757PHP performance tips Author: ... -
国外优秀开源PHP建站程序一览
2009-10-15 08:06 1339大量的PHP开源(开放源 ... -
十步让你成为一名优秀的Web开发人员
2009-10-15 08:03 855第一步:学好HTML HTML( ... -
What's Agile To You?
2009-10-09 08:34 803As a project manager, archite ... -
install Merb 1.0 on Windows
2009-10-05 17:25 932早期的Merb在Windows上安装是件很恶心的事,缺这少 ... -
WebWork敏捷开发尝试
2009-10-05 09:11 803WebWork是一个优秀的J2EE ... -
敏捷开发中常见的九大误解
2009-10-05 09:10 781一、敏捷是“一个” ... -
浅谈敏捷项目管理在软件开发中的应用
2009-10-05 09:09 1218一、使用传统项目管理技术管理软件开发项目的方法 按照 ... -
揭示PHP成功背后的秘密:PHP创始人访谈录
2009-10-01 12:47 926Rasmus Lerdorf可能是格陵兰最著名的电脑牛人,他1 ... -
GitHub: Speed matters
2009-09-29 22:25 884Impressions from the first arti ... -
PHP5 Database Iterators <2>
2009-09-29 22:15 1038Introducing the Db_Iterator Obj ... -
PHP5 Database Iterators <1>
2009-09-29 22:11 897One feature of PHP rarely seen ... -
REST-*组织
2009-09-29 11:10 867JBoss已在月初的JBoss世界大会上正式宣布了它的新项 ... -
Agile 2009 Conference Retrospective
2009-09-26 21:51 832A month has passed since Agile ... -
Bill Burke Discusses REST-*, SOA/ROA and REST
2009-09-26 21:49 1004InfoQ's recent post on REST-* ... -
git is great 2
2009-09-26 15:11 1494Git梳妆我们可以利用Git的config命令或者直接编辑~/ ... -
git is great
2009-09-26 15:08 1679Git是一个分布式的版本控制工具,本篇文章从介绍Git开始,重 ... -
FindBugs 1.3.9发布了
2009-09-26 08:03 1394由马里兰大学Bill Pugh教 ...
相关推荐
way it does is stored in the PDF file. So, no matter what fonts a balloter (or reader) has on their computer, they'll be able to see the file as you intended it to be seen. If you don't embed fonts, ...
标题 "Creating XML Documents with PL/SQL" 涉及到的是如何使用PL/SQL语言来创建、处理和解析XML文档。在Oracle数据库环境中,PL/SQL是常用的编程语言,它扩展了SQL的功能,使得开发者可以编写存储过程、函数、...
Complete example programs with colorized code illustrate each important aspect of Java programming - all in easy steps. This book assumes no previous knowledge of any programming language so it's ...
Jim Wilson作为本书的作者,是JWHedgehog, Inc.的总裁,该公司专注于为Android、iOS和Microsoft平台提供解决方案。作者拥有超过30年的软件工程经验,特别是在移动设备和基于位置的解决方案领域,已经有超过15年的...
- **标题**:“Creating Apps in Kivy.pdf” - **描述**:“Creating Apps in Kivy” 这两个部分简明扼要地指出了本书的主要内容:通过使用Kivy框架来开发应用程序。Kivy是一个用于构建高性能触摸应用的开源Python...
使用Python + Kivy 开发应用程序。 Kivy 是一个跨平台的GUI 支持Window、Linux、Mac、Android 虽然包含了代码,还是贴出代码下载地址: https://github.com/oreillymedia/creating_apps_in_kivy
[Microsoft Press] Creating Research and Scientific Documents Using Microsoft Word (英文版) [Microsoft Press] Creating Research and Scientific Documents Using Microsoft Word (E-Book) ☆ 图书概要:☆ ...
《学习C++通过创建Unreal Engine 4游戏》是一本专为希望掌握C++编程语言并利用Unreal Engine 4开发游戏的初学者和进阶者设计的书籍。Unreal Engine 4是一款强大的游戏开发引擎,由 Epic Games 开发,支持多平台游戏...
Long gone are the days of mobile apps with a static UI ...In this book, you'll learn how to use fragments to meet the challenges of creating dynamic UIs in the modern world of mobile app development.
iOS 10 SDK Development: Creating iPhone and iPad Apps with Swift by Chris Adamson English | 24 Mar. 2017 | ASIN: B071RRCK9R | 264 Pages | AZW3 | 5.24 MB All in on Swift! iOS 10 and Xcode 8 make it ...
关于PDF文件制作及操作的经典书籍,适用于java C#等多种语言,可以添加图片,水印,各种字体,报表,教你如何一步一步的成为PDF编程高手,真正的step by step,深入浅出,五步即可制作自己的PDF文件。
Chapter 10: Creating Audio for Games Chapter 11: Creating 3D Graphics with WebGL Part IV: Local Storage and Multiplayer Games Chapter 12: Local Storage and Caching Chapter 13: Going Online with ...
HTML5.Games.Creating.Fun.with.HTML5.CSS3.and.WebGL.pdf HTML5.Games.Creating.Fun.with.HTML5.CSS3.and.WebGL.pdf HTML5.Games.Creating.Fun.with.HTML5.CSS3.and.WebGL.pdf
在“Learning.C++.by.Creating.Games.with.UE4.Code.zip”这个压缩包中,我们可以推测它包含了一系列关于使用C++在虚幻4中开发游戏的教程代码。通过这些代码,学习者可以逐步理解如何利用C++在虚幻4环境下创建游戏。...