Tải bản đầy đủ (.pdf) (65 trang)

Tài liệu PDFLib''''s block tool pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.12 MB, 65 trang )

PDFLib’s
BLOCK TOOL
hp

p

Templating PDFs for maximum reusability

FPDI in Detail

Importing existing documents with Free PDF Import

2005 Look PHP world
Back
Reflecting on last year’s events in the
with PHP guru Derick Rethans

i18n
Internationalize your web application
with less PHP code

VOLUME 5 ISSUE 1

Secure your applications against Email Injection
Tips on Output Buffering
KOMODO - reviewed
and much more...


NEXCESS.NET Internet Solutions


304 1/2 S. State St.
Ann Arbor, MI 48104-2445



PHP / MySQL
SPECIALISTS!
Simple, Affordable, Reliable PHP / MySQL Web Hosting Solutions
P O P U L A R S H A R E D H O S T I N G PAC K A G E S

MINI-ME

$

6 95

SMALL BIZ $ 2195/mo

/mo

500 MB Storage
15 GB Transfer
50 E-Mail Accounts
25 Subdomains
25 MySQL Databases
PHP5 / MySQL 4.1.X
SITEWORX control panel

2000 MB Storage
50 GB Transfer

200 E-Mail Accounts
75 Subdomains
75 MySQL Databases
PHP5 / MySQL 4.1.X
SITEWORX control panel

POPULAR RES ELLER HO ST I NG PAC KA G ES
NEXRESELL 1 $16 95/mo
900 MB Storage
30 GB Transfer
Unlimited MySQL Databases
Host 30 Domains
PHP5 / MYSQL 4.1.X
NODEWORX Reseller Access

NEXRESELL 2 $ 59 95/mo
7500 MB Storage
100 GB Transfer
Unlimited MySQL Databases
Host Unlimited Domains
PHP5 / MySQL 4.1.X
NODEWORX Reseller Access

: CONTROL

PA N E L

All of our servers run our in-house developed PHP/MySQL
server control panel: INTERWORX-CP
INTERWORX-CP features include:

- Rigorous spam / virus filtering
- Detailed website usage stats (including realtime metrics)
- Superb file management; WYSIWYG HTML editor

INTERWORX-CP is also available for your dedicated server. Just visit
o for more information and to place your order.

WHY NEXCESS.NET? WE ARE PHP/MYSQL DEVELOPERS
LIKE YOU AND UNDERSTAND YOUR SUPPORT NEEDS!

NEW! PHP 5 & MYSQL 4.1.X

php 5

4.1.x

We'll install any PHP extension you
need! Just ask :)
PHP4 & MySQL 3.x/4.0.x options also available

php 4

3.x/4.0.x

128 BIT SSL CERTIFICATES
AS LOW AS $39.95 / YEAR
DOMAIN NAME REGISTRATION
FROM $10.00 / YEAR
GENEROUS AFFILIATE PROGRAM


UP TO 100% PAYBACK
PER REFERRAL

30 DAY
MONEY BACK GUARANTEE

FREE DOMAIN NAME
WITH ANY ANNUAL SIGNUP

ORDER TODAY AND GET 10% OFF ANY WEB HOSTING PACKAGE
VISIT HTTP://NEXCESS.NET/PHPARCH FOR DETAILS

De dicat ed & M an ag ed D edic at e d s e rv e r so lu t io ns a ls o av a ila ble
Serving the web since Y2K




TM

CONTENTS

Columns
6 EDITORIAL
8 php|news

Features
10

48 TEST PATTERN


Why is it Taking so Long?

Lead times and the rationale behind them

2005 Look Back

Reflecting on last year’s
events in the PHP world

by DERICK RETHANS

18

by MARKUS BAKER

53 SECURITY CORNER

Email Injection
by CHRIS SHIFLETT

PHPLib’s Block Tool

Templating PDF’s for Maximum Reusability

by RON GOFF

56 TIPS & TRICKS

Output Buffering

by BEN RAMSEY

26

FPDI in Detail

Importing existing documents
with Free PDF Import

60 PRODUCT REVIEW

Komodo

The Web Development IDE for All Platforms?

by JAN SLABON

by PETER MacINTYRE

38

i18n

Internationalize Your Web applications
with less PHP code

by CARL McDADE

64 exit(0);


2006: A Look Forward
by MARCO TABINI

Download this month’s code at: />
WRITE FOR US!

If you want to bring a php-related topic to the attention of the professional php community, whether it
is personal research, company software, or anything else, why not write an article for php|architect?
If you would like to contribute, contact us and one of our editors will be happy to help you hone
your idea and turn it into a beautiful article for our magazine. Visit www.phparch.com/writeforus.php
or contact our editorial team at and get started!


EDITORIAL

PLATFORM
DIVERSITY

I

n the past five (or so) years, especially, the desktop landscape has changed,
severely. Desktops have traditionally been dominated by Windows, but
alternatives are making their way into both the office and home.
Apple’s hit operating systems in the OS X series, and other chic products
(like the iPod) have not only fueled the sales of Macintosh computers, but
have opened consumers’ minds to the reality that there are alternatives to Windows.
The market is still strongly clutched by Microsoft, but more and more users are
making the “switch” to Mac (and to a much lesser extent, alternatives like Linux).
This diversity, while good, can cause portability problems, and as I’ve touched
on in past issues, developers can no longer target a single browser, but must become

more and more aware of standards and cross-browser/cross-platform compatibility
issues.
For the most part, developers seem to have the browser issue under control. I
personally never use Internet Explorer for anything but testing (I’m a Firefox fanboy),
and it’s very rare that I still run into sites that simply won’t work with FF. Even in
cases where it seems I’m out of luck, I can often spoof the User-Agent header, and
get a working site. Since Firefox is available on many platforms, it seems that the
HTML issue is (mostly) behind us—I say “mostly” because standards-compliance
and portability are things that we always need to strive for.
If you’ve tried to distribute a printable, offline-viewable, and well laid out
document, in the past, you know that HTML doesn’t cut it. There’s little provision
for the features that are necessary to build a professional document (there is hope
with CSS, though). This often leaves websites delivering “richer” documents, such
as MS Word documents or RTF files.
The distribution of proprietary format documents leads to its own set of
problems, primarily: document creation and portability. Have you tried to build a
Word document from your non-Windows Web server? It’s not fun. Equally tedious
is trying to get that document to render properly in different versions of Word, on
different platforms—worse is the rendering in non-Microsoft applications, such as
OpenOffice. Enter PDF.
Now, PDF is certainly not new technology. It does, however, seem to be becoming
more and more the de facto standard for document distribution. PDF is no stranger
to php|architect readers: if you’re not reading this on paper, you’re reading a PDF,
and we’ve brought you much PDF-centric content in the past, but we’ve certainly not
drained the PDF knowledge pool.
This month, we’re happy to focus on PDF, once again, but this time with a twist:
using PHP to modify existing PDFs, through various means.
It’s also our pleasure to be running Derick Rethans’ PHP Lookback, 2005. Marco
will touch more on this in exit(0).
On that note, we at php|architect wish you and your business a happy and

successful 2006. Here’s to another great year of PHP!

Volume 5 - Issue 1
Publisher
Marco Tabini

Editor-in-Chief
Sean Coates

Editorial Team
Arbi Arzoumani
Peter MacIntyre
Eddie Peloke

Graphics & Layout
Aleksandar Ilievski

Managing Editor
Emanuela Corso

News Editor
Leslie Hill


Authors
Marcus Baker, Ron Goff,
Peter B. MacIntyre, Carl McDade,
Ben Ramsey, Derick Rethans,
Chris Shiflett, Jan Slabon
php|architect (ISSN 1709-7169) is published

twelve times a year by Marco Tabini & Associates,
Inc., P.O. Box 54526, 1771 Avenue Road, Toronto,
ON M5M 4N5, Canada.
Although all possible care has been placed in
assuring the accuracy of the contents of this
magazine, including all associated source code,
listings and figures, the publisher assumes
no responsibilities with regards of use of the
information contained herein or in all associated
material.
php|architect, php|a, the php|architect logo, Marco
Tabini & Associates, Inc. and the Mta Logo are
trademarks of Marco Tabini & Associates, Inc.

Contact Information:

General mailbox:
Editorial:

Sales & advertising:

Printed in Canada
Copyright © 2003-2006
Marco Tabini & Associates, Inc.
All Rights Reserved

6 • php|architect • Volume 5 Issue 1




news
eZ components
ez components 1.0 beta2

PHP 5.1.2 RC1

Ilia Alshanetsky announces the release of php
5.1.2 RC1.
“I’ve just packaged PHP 5.1.2RC1, the first
release candidate for the next 5.1 version. A
small holiday present for all PHP users, from
the PHP developers. This is primarily a bug
fixing release with its major points being:
• Many fixes to the strtotime() function,
over 10 bugs have been resolved.
• A fair number of fixes to PDO and its
drivers
• New OCI8 that fixes large number of
bugs backported from head.
• A final fix for Apache 2 crash when
SSI includes are being used.
• A number of crash fixes in extensions
and core components.
• XMLwriter & Hash extensions were
added and enabled by default.”
Get all the info at />97-PHP-5.1.2RC1-Released!.html

FUDforum 2.7.4RC1
Released


The FUDforum team has announced the latest
release of their open source forum package,
version 2.7.4 RC1. Some of the new features
include:
• Added subscribed forum filter to
message navigator
• Added handling for in-lined
attachments in mailing list
import
• Added the ability to supply
custom signature to message
synchronized from the forum
back to mailing list or a news
group
• Added support for allowing the
user to select how many threads
they want to see per page
• Much more…
Visit FUDforum.org for all the latest info.

8 • php|architect • Volume 5 Issue 1

ez.no is proud to announce the release
of ez components. ez.no announces: ”Ez
components is an enterprise ready, general
purpose PHP platform. As a collection of high
quality independent building blocks for PHP
application development, ez components
will both speed up development and reduce
risks. An application can use one or more

components effortlessly, as they all adhere to
the same naming conventions and follow the
same structure. All components are based on
PHP 5.1, except for the ones that require the
new Unicode support that will be available
from PHP 6 on.”
Need to speed up your development?
Check out ez.no for more info.

xajax 0.2

xajaxproject.org announces the release of
version 0.2. What is it? The site describes it
as:” an open source PHP class library that
allows you to easily create powerful, webbased, Ajax applications using HTML, CSS,
JavaScript, and PHP. Applications developed
with xajax can asynchronously call server-side
PHP functions and update content without
reloading the page.”
To start working with xajax, visit
xajaxproject.org.

SQLiteManager 1.2.0RC2

If SQLite is the db of choice for your PHP
application, you may be interested in the latest
release of SQLiteManager. SQLiteManager.
org lists the features as:
• Management of several
databases (creation, access or

upload)
• Management of the attached
databases
• Create, edit and delete tables
and indexes
• Insert, edit, delete records in
these tables
• Management of views; create
views from SELECTs
• Management of triggers
• Management of user defined
functions
• Manual request and from file,
it is possible to define the
format of the requests, sqlite or
MySQL; a conversion is done in
order to directly import a MySQL
database in SQLite
• Importing of records from a
formatted text file
• Export of structure and the data
• Choice of several display skins
Check out SQLiteManager.org to start managing
your SQLite DB, today.

php|architect Releases New
PDFlib Book
We are proud to announce the release of our latest book
in the “Nanobooks” series called Beginning PDF Programming
with PHP and PDFlib.

Authored by Ron Goff, this book provides a thorough
introduction to the great capabilities provided by the PDFlib
library for the creation and manipulation of PDF files.
The book features a foreword by Thomas Merz, the
original author of PDFlib and founder of PDFlib GmbH, and
tackles topic like PDF file creation, fonts, text, shapes and
much more, including PDFlib’s Block Tool, which allows for
the manipulation of existing PDF documents.
For more information, />

MDB2_Drivers
Check out the hottest new releases from PEAR.

Image_Color2 0.1.4

PHP 5 color conversion and basic mixing.
Currently supported color models:
• CMYK - Used in printing
• Grayscale - Perceptively weighted
grayscale
• Hex - Hex RGB colors i.e. #abcdef
• HSL - Used in CSS3 to define colors
• HSV - Used by Photoshop and other
graphics packages
• Named - RGB value for named colors
like black, khaki, etc.
• WebsafeHex - Just like Hex but rounds
to websafe colors

Config 1.10.5


The Config package provides methods for
configuration manipulation.
• Creates configurations from scratch
• Parses and outputs different formats
(XML, PHP, INI, Apache...)
• Edits existing configurations
• Converts configurations to other
formats
• Allows manipulation of sections,
comments, directives...
• Parses configurations into a tree
structure
• Provides XPath like access to
directives

MDB2 drivers where released for:
• SQLite
• postgreSQL
• mysqli
• mysql
• Oracle

MDB2 2.0.0RC3

PEAR MDB2 is a merge of PEAR DB and
Metabase php database abstraction layers.
Note that the API will be adapted to better fit
with the new PHP 5-only PDO before the first
stable release.

It provides a common API for all supported
RDBMS. The main difference to most other
DB abstraction packages is that MDB2 goes
much further to ensure portability. Among
other things MDB2 features:
• An OO-style query API
• A DSN (data source name) or array
format for specifying database
servers
• Datatype abstraction and on demand
datatype conversion
• Various optional fetch modes to fix
portability issues
• Portable error codes
• Sequential and non sequential row
fetching as well as bulk fetching
• Ability to make buffered and
unbuffered queries
• Ordered array and associative array
for the fetched rows
• Prepare/execute (bind) emulation
• Sequence emulation
• Replace emulation
• Limited sub select emulation

Fileinfo 1.0.3
GDChart 0.2.0

The GDChart extension provides an interface
to the bundled gdchart library. This library

uses the (bundled) GD library to generate 20
different types of graphs, based on supplied
parameters.
The extension provides an OO interface
to gdchart exposing majority of options via
properties and complex (array) options via a
series of methods.
To use the current version of the extension
PHP 5.0.0 is required, and older PHP 4 only
version can be downloaded from CVS, by
checking out the extension with PECL_4_3
tag.

yaz 1.0.6

This extension implements a Z39.50 client for
PHP using the YAZ toolkit.

This extension allows retrieval of information
regarding vast majority of files. This
information may include dimensions, quality,
length etc...
Additionally, it can also be used to retrieve
the mime type for a particular file and for text
files, the proper language encoding.

pecl_http 0.21.0

It eases handling of HTTP URLs, dates,
redirects, headers and messages, provides

means for negotiation of clients preferred
language and charset, as well as a convenient
way to send any arbitrary data with caching
and resuming capabilities.
It provides powerful request functionality,
if built with CURL support. Parallel requests
are available for PHP-5 and greater.
PHP-5 classes: HttpUtil, HttpMessage,
HttpRequest,
HttpRequestPool,
HttpDeflateStream, HttpInflateStream
PHP-5.1 classes: HttpResponse














Row limit support
Transactions support
Large Object support
Index/Unique

Key/Primary
Key
support
Autoincrement emulation
Module framework to load advanced
functionality on demand
Ability to read the information
schema
RDBMS management methods
(creating, dropping, altering)
Reverse engineering schemas from
an existing DB
SQL function call abstraction
Full integration into the PEAR
Framework
PHPDoc API documentation

MDB2_Schema 0.4.1

PEAR::MDB2_Schema enables users to
maintain RDBMS independent schema files
in XML that can be used to create, alter and
drop database entities and insert data into
a database. Reverse engineering database
schemas from existing databases is also
supported. The format is compatible with
both PEAR::MDB and Metabase.

Validate_ptBR 0.5.2


Package contains locale validation for
ptBR such as:
• Postal Code
• CNPJ
• CPF
• Region (brazilian states)
• Phone Number
• Vehicle plates

Xdebug 2.0.0beta5

The Xdebug extension helps you debugging
your script by providing a lot of valuable
debug information. The debug information
that Xdebug can provide includes the
following:
• stack and function traces in error
messages with:
• full parameter display for user defined
functions
• function name, file name and line
indications
• support for member functions
• memory allocation
• protection for infinite recursions
Xdebug also provides:
• profiling information for PHP scripts
• script execution analysis
• capabilities to debug your scripts
interactively with a debug client


Volume 5 Issue 1 • php|architect •9


F EATU RE

2005
PHP

A new year is upon us, and
as is customary in the PHP
world, it is time to reflect

LOOK BACK

on the events of the past
year. Derick Rethans, a PHP
internals developer, has been
publishing a PHP Look Back
for a few years, now, and
this year, we saw it fitting to
publish it, here. Happy 2006!

by D E RIC K RE THAN S

W

elcome to the fourth installment of the PHP
Look Back. Just as in previous years, we’ll
look back on PHP development discussions,

bloopers and accomplishments of the last
year. This is not supposed to be a fully
objective review of last year—note that the opinions in
this article are that of the author, and not of the PHP
development team (nor of php|architect).

January
January was a quiet month, with not much going on.
After about 8 months [001], we finally added [002] a PIC/nonPIC detection mechanism to the configure script, that
will select non-PIC object generation for supported
platforms (Linux and FreeBSD). Non-PIC code is about
30% faster, as measured in earlier benchmarks.
10 • php|architect • Volume 5 Issue 1

TO DISCUSS THIS ARTICLE VISIT:
/>
A week later, Leonardo [003] was wondering whether we
planned on adding type hints for scalar types to PHP. As
PHP is a weakly-typed language, this is not something
we wanted to add, although we did add support for an
“array” type hint, later in the year. With PHP 5.1’s new
GOTO execution method (added last August), variable
name lookups are cached internally. This caused some
problems for Xdebug [004], as it needs some information to
find out which variables are used in a specific scope. Andi
committed [005] a patch that made Xdebug work properly,
again.
Michael started working on his HTTP extension (which



2005 Look Back
generates way too many commit mails ;-) and encountered
a problem with a naming clash [006] between PEAR’s HTTP
class and his PECL extension. Greg responded [007], and said
that this problem will be solved when PEAR 1.4 comes
out, with its channel support.

February
Andi started discussions in February by pointing out a
date for the first beta of PHP 5.1: March 1st. He declared
that “both PDO and Date should be included in the default
distribution”[008] and others suggested that XML Reader[009]
should be included by default, as well. In reply to Andi,
Rasmus mentioned [010] that he would like to see the

issue that—later in the year—warranted a new PHP
release, and Greg introduced [027] PEAR 1.4, with channel
support.
Halfway through the month, Marcus [028] mentioned a
few things that should go into PHP 5.1; most notably the
__toString() fix, which unfortunately, did not actually
make it into the release. Type hinting with “= NULL” did,
make it in [029], though.
Martin Sarsale reported [030] an issue with references
and segfaults, something which had been annoying us
at eZ systems [031] for quite some time, too. This issue got
fixed in PHP 4.4, albeit not without a little bickering
(more about that later).

Luckily, Debian’s PHP packages got rid of

some of the insanity that was present
in previous releases.
filter extension included, as well. The discussion about
this extension quickly transitioned to data mangling
of input request variables, and how they could not be
influenced by the script authors, but only by the system
administrator. In the end, this discussion made place
for the topic of Operator overloading [011], where certain
people kept reiterating that operator overloading is a
“good thing. [012]”
Andrei tried to stop this discussion by being funny [013],
but it didn’t work very well [014]. Around the same time, Wez
announced [015] the first beta of PDO—PHP Data Objects.
Wez wanted people to test [016] PDO, and of course, over the
next couple of months, there were various PDO-related
concerns [017] and issues raised.
Another discussion in February was about auto
boxing [018] in PHP. Auto boxing is the encapsulation of
all primitive types as objects. Naturally, people asked
why [019] we would want to have this, and no sound
reason was given. In the end, this discussion suggested
that phpDocumentor[020] should handle type determining,
instead. Having a doc block [021] parsing extension to the
reflection API would be nice, although a bit hard.
We also had an often-recurring discussion [022] on why
the GPL[023] is a bad idea for PECL[024] extensions.
John added the first version [025] of XMLRPCi to CVS;
why he chose this silly name is still unknown. Jani
wrote about a problem with overwriting globals [026], an


March
In March, Ilia proposed [032] a patch that adds a special
token that tells PHP’s parser to abort parsing when
the token is encountered. This allows us to attach
binary data to the end of a PHP script, which is highly
useful for one-script installers, such as the one that
FUDForum [033] uses.
On the 14th of the month, Zeev released the first
RCs [034] of both 5.0.4 and 4.3.11. We also encountered
further reference issues [035].
The same guy that mailed tons of “fixes” to the
internals list, last June [036], was back with more [037]
patches. Andrei, once again, pointed out [038] that it is
a good idea to check with an extension’s maintainer
before applying patches, and Greg published [039] the
package2.xml documentation.
Lukas, once more, pointed out [040] the weird naming
scheme that new extensions seem to be getting, and
luckily Debian’s PHP packages got rid [041] of some of the
insanity that was present in previous [042] releases by
not always building in ZTS mode. Unfortunately, their
packages still force PIC mode for the libraries.
A user brought up the idea of an upload meter
patch [043], again, and although we all seemed to
remember[044] that the original patch was rejected [044],
no one could find the original thread [046] where this was
discussed. Last year’s Look Back discussed this too, and
Volume 5 Issue 1 • php|architect • 11



2005 Look Back
there, the reason was mentioned [047].
In the last week of the month, we had some fuss [048]
about “FreeBSD doing stupid things [049]” regarding their
naming of auto tools executables [050].

April
April started with a suggestion [051] by Zeev to change
the way that __autoload() works, by allowing multiple
instances of this magic function. In the end we, didn’t
end up implementing this, and as Lukas described [052],
“Frameworks should provide __autoload() helper
methods, but should never implement the function itself.
It’s up to the end user to do this.” (This is exactly how
we implemented it for the eZ components [053]).
Andi wanted to release PHP 5.1 Beta 1[054] really soon,
but, as Jani mentioned [055], there were quite a few things
that were still not fully ready, and thus the suggestion to
call it “Alpha”[056] was made, instead. During this thread,
some pet-features [058] were brought up [059].
Kamesh, from the Netware porting team, found
another reference issue [060]. Marcus added the File [061] class
to his SPL extension, causing a small stir—the new class
clashed with any application that already defines its
own File class. Although this is a valid point, projects
defining a “File” class should know better, and would be
wise to prefix their class names. This same issue will pop
up later in the year.
A last, somewhat larger, discussion erupted when
a question [062] about whether APC could be used as a

content cache was posted to the list. Rasmus found it an
interesting idea [063], although this functionality can also
be accomplished in user space. In the last point of the
thread, Rasmus mentioned [064] that APC will soon support
PHP 5.

May
May had a slow start, and things only got interesting
at the end of the month. The first discussion that came
up was Ilia’s removal of dangling commas from enums,
something that “was in c language from the first day [065].”
Apparently, GCC 4 is “becoming worse and worse [066],” but
luckily, we can still just ignore the warnings [067].
After a small private discussion with Dmitry about
Marcus’ and my reference fix patch [068], he came to the
conclusion that this patch breaks binary compatibility
and that this problem warrants a PHP 4.4 release. As this
reference problem has been affecting many users, and
definitely eZ over the past months, I wrote an email [069]
to the list stating that it is “totally irresponsible” not to
release a fix for such a grave bug. Zeev[070] also said that
“we should probably not fix this at all in the 4.x tree”
because of the hassles that accompany “breaking module
12 • php|architect • Volume 5 Issue 1

binary compatibility.” He also seemed to think that the
bug can easily be worked around.
Other users were a bit happier[071] that we finally nailed
this bug, and Jani replied to Zeev that the magnitude [072]
of this bug is pretty high. Rasmus added that he “will

be deploying the patch and happily breaking binary
compatibility [073]” as soon as the patch is ready. Breaking
binary compatibility is only a “burden on the maintainers
of these packages” (of the various distributions). Wez
thought that “the only logical move forward is a 4.4
branch and release [074].” In the end, the Zeev almighty was
“tired of going through the reasons again and again [075]”
and noted that “everyone appears to prefer the upsides
to the downsides.” This resulted in the creation of the
PHP_4_4 branch [076] in the first week of June.

June
Wez added a new patch to our CVS server that allows
us to block access [077] to specific branches—with this,
we closed the PHP_4_3 branch for good. A week later,
I announced 4.4.0RC1[078], which features the reference
bug fix.
Andi wrote another PHP 5.1 mail [079], which spawned
a nice long discussion on adding goto [080] to PHP, and
comparing goto to exceptions. Magnus smartly added [081]
that “people are talking about hypothetical messy code
because of goto” and that they forget that you don’t
have to use a language construct simply because it is
available.
The same thread also went into a branch that
discussed [082] the ifsetor() language construct. After
Andi returned, he decided not to do anything with
goto or ifsetor()[083], and that it was now the time to
branch, so that we can merge the Unicode support that
was developed in parallel by mostly Andrei and Dmitry,

although Rasmus was “pretty sure the current discussions
will pale in comparison to the chaos that will be created
when the Unicode stuff goes into HEAD![084]”
Johannes wondered when the new date stuff[085] was
going in; it was added a week later, just before PHP 5.1
beta 2. Lukas suggested that we add [086] the public keyword
to PHP 4.4 for forward compatibility. Rasmus again
wondered about “the reasoning ... for not having var be
a synonym for public in PHP 5 [087].”. Andi mentioned [088]
that this “was meant to help people find vars so that
they can be explicit about the access modifiers” when
moving to PHP 5.
A few days later, Andi read a blog posting [089] which
described how PHP 4.4 is breaking backwards compatibility
by issuing an E_STRICT in cases where developers abuse
return-by-reference. This, however, was not actually the
case [090].


2005 Look Back
Yasuo started a long thread [091] on allow_url_fopen()
and claimed it was dangerous [092]. The main result of
this thread seemed to be that we wanted to split the
setting into two different privileges: one that allows
remote opening of URLs and one to allow include() on
remote URLs. However, this is something we could not
yet change.
The last thread of the month was by Andi, writing
about the PHP 5.1 release process [093]


July
In July, Jessie suggested [094] a String extension that
declares only one class: String. This class is meant to
prevent copying of the string’s data for most operations
(which is currently done with PHP’s string functions).
Most of the other developers where against it, for

where some people didn’t see [108] why we had to implement
this fix. Unfortunately, there were some quirks [109] that we
still had to sort out.
In this same month, Rasmus released APC 3.0.0 [110]
which came with PHP 5.1 support and numerous fixes.

August
August started with a discussion on instanceof[111] being
“broken,” as it raises a fatal error in the case where
the class that is being checked for doesn’t exist. Andi
declared “if you’re referencing classes/exceptions in
your code that don’t exist, then something is very bogus
with your code [112]” and “the only problem is if the class
does not exist in your code base, in which case, your
application should blow up![113]”
I raised a question about whether the new PHP with

If you’re referencing classes/exceptions
in your code that don’t exist,
then something is very bogus with your code.
different reasons: “String is such a generic name for a
non-core class [095]” and “the savings gained by this will be
more than offset by OO overhead [096],” so we will not let

“this get anywhere near the core [097].”
In the same week, I made more changes to the date
extension [098] that allows users to more easily select the
timezone that they want, instead of having to rely on
the TZ environment variable. This is also needed because
the TZ environment variable [099] can most likely not
be used in a thread safe way, and it is certainly not
portable [100]. Also in the same week, I proposed an API
for new Date and Timezone functionality [101]. After some
pressure [102], I added [103] an OO API, too. Near the end of
the month, I committed the implementation of the new
date functionality [104]. It was, however, #ifdef-ed out to
facilitate discussions at a later date.
Jessie came up with Yet Another Namespace
Proposal [105], and tried to come up with a solution for all
the previous problems we had with the implementation.
He also made several patches [106] that added namespaces
to PHP.
We had some more fuss [107] about PHP 4.4 breaking BC,

Unicode should be called PHP 5.5 or PHP 6.0 [114]. Andi
(amd the majority) wanted to go “with PHP 6 and aim to
release it before Perl 6 [115].”
After PHP_5_1 was branched, Andrei merged the
Unicode branch and gave us some instructions on how
to get started with it [116]. He also introduced the general
ideas behind the implementation [117].
PHP 5.1 RC1 was finally rolled, about half way through
the month, followed by PHP 5.0.5 RC2[118], a week later.
During the development of the eZ components [119],

we discovered various things in PHP’s OO model that we
wanted to see changed. One of those issues was described
in the Property Overloading RFC [120]. Unfortunately, not
everybody could be convinced [121], and no changes were
made. I will try again though :).
The other issue that we raised was that failed
typehints throw a fatal error[122], while that is not strictly
necessary. Instead of throwing exceptions [123] in this case,
the discussion turned towards adding a new error mode [124]
(E_RECOVERABLE[125]) that will be used for non-enginecorrupting fatal errors at the language level—this is
exactly the case with failed typehints.
Volume 5 Issue 1 • php|architect • 13


2005 Look Back
The longest thread of the month, was started by
Rasmus when he posted his PHP 6 [126] wish list, which
featured controversial changes such as “removing
magic_quotes” and “making identifiers case-sensitive,”

attempt detection in favour of the new date.timezone
setting [147]. After some discussion, we came up with a
solution [147], which was then implemented. It should
guess the timezone correctly in most cases, even on

The filter extension, which I’ve been
developing for quite some time,
did not make it into PHP 5.1...
to which most developers quickly agreed [127]. Following
his initial wish list, the crowd went wild and started

suggesting all kinds of weird changes, such as “Radically
change all of the operator syntaxes [128],” adding as a BC breaking mode, and “Named parameters [130].”
Marcus made a list of his own [131] which would later
become the first draft of the meeting agenda for a PHP
Developers Meeting.

September
In September, Antony committed [132] an upgraded OCI8
extension which fixes a lot of bugs [133]. We also decided
to play a bit nicer with version_compare(), regarding
naming [134] release candidates.
Zeev wanted to roll [135] PHP 5.0.5 but there was an
issue [136] with the shutdown order. The reference issues
returned, too. The first one [137] turned out to be an
incorrect merge to the PHP 5.0 branch, where suddenly
some of the notices turned into errors [138]. The second
one [139] is simply a small change in behaviour, which
previously created memory corruption. Rasmus explained
the issue a bit more [140], once again.
Ilia tried to implement a clever fix [141] which turned
out to be a problem later on. Pierre started a discussion
on supporting Unicode in identifiers, something he didn’t
want to see. PHP already supports using UTF-8 encoded
characters [142] in identifiers, so removing this feature
will break BC unnecessarily. Besides breaking BC, many
people simply want to use their own language for writing
code, as Tex [143] writes.
Zeev made another attempt at PHP 5.1.0 RC2[144] with
the latest PEAR being the only thing missing. Marcus

brought up the issue of __toString() again, and finally
managed to get it into CVS, but unfortunately not in time
for PHP 5.1.
Stanislav[146] noticed some problems with detecting
time zones, as the new date/time code did not try to
14 • php|architect • Volume 5 Issue 1

Windows. I also added support for an external timezone
database [149].

October
In October, I noticed some weird notices [150] with
“make install-pear,” without a clue as to why they were
showing up. This discussion turned into a “why does
PEAR not support PHP 5.1” thread [151]. In the end, Greg
managed to nail down the weird notices, though.
I also noticed a commit by Dmitry [152] that ignores “&”
when $this is passed. I pointed out that this should
not be supported (in PHP 5), as it doesn’t make really
sense that people won’t see a warning/notice/error when
they’re doing something silly. Dmitry explained [153] that
disallowing it would break code, but he also writes that
by “using ‘=& $this’, a user can break the $this value”—
which is something we definitely should prevent. He
suggested [154] we make this an E_STRICT warning, and Andi
suggested [155] we escalate this to an E_ERROR in PHP 6, but
neither of those things happened.
A week later, Piotr[156] asked for a tarball of our CVS to
make it “possible to convert it to Subversion repository
... so browsing the repositories would be much easier.”

We wondered [157] why he needed that, as we offer our own
browser[158], already.
Matthias [159] said that we “do not want to set off yet
another discussion about the changes 4.4 brought,” but
that is exactly what he did. Again, there was something
wrong with his code, and thus the warning is legal.
After resolving the timezone issues, last month,
we were surprised by a message from Zeev. He simply
missed [161] the conclusion in the “lengthly thread.”
As a result of the negative comments on the PHP 4.4.0
release, Lukas, Ilia and I set up a routine [162] for involving
some of the more known projects to the PHP 4 [163] and
PHP 5 [164] release processes. As part of this effort, we send
out [165] a mail to all participating projects whenever we


2005 Look Back
have a release candidate to test.
I raised [166] some concern regarding our current
Unicode implementation because of maintenance issues.
In part of my mail, I also indicated that I wanted “to
clean up PHP 6 for real, [167]” after private discussions
with Marcus and Ilia. Behind the scenes, we prepared
some material to organize a PHP Developers Meeting to
discuss the Unicode implementation and the extended
“PHP 6 Wishlist.” I also committed [168] a patch that allows
typehints for classes to work with = NULL[169].
Another guy raised the issue of “that new isset()-like
language construct, [170]” but this ended up going nowhere,
as people were suggesting very Perl-like [171] operators.

Jani replied to this thread with “How about a good ol’
beating with a large trout?[172]”
On the last day of the month, we released PHP 4.4.1[173]
which addresses some of the reference issues we’ve seen
in PHP 4.4.0.

November
In November, we prepared to finally release PHP 5.1,
and one of the efforts was to make an upgrade guide [174]
for people switching to PHP 5.1. Sean noticed [175] a
problem with the parameter parsing API’s automatic
type conversion. Like Andrei [176], many people think that
“passing ‘123abc’ and having it interpreted as 123” is still
wrong.
Dmitry implemented [177] support for “= null” as default
to array type hinting, something that I did not do [178] on
purpose because “= array()” is the logically correct way
of doing this. Andi agreed [179] with me on this.
Ilia implemented, in PHP 5.1RC5 [180], one of the items
that was on the outcome list of the PHP Developers
Meeting: adding a notice that warns people that curly
braces [181] for addressing a character in a string is now
deprecated in favour of the [] operator—contrary to the
current explanation in our manual. {} and [] are exactly
the same thing [182] and “having two constructs for the same
behaviour is silly and leads to confusing, hard to read
code.” The outcome of this discussion was the removal
of the notice in PHP 5.1 and the likely conclusion is that
it is not going to get removed.
Another change that as made PHP 5.1RC6 was the

creation of the “Date” class, which caused quite a stir
after the release of PHP 5.1[183]. The reason to introduce it
in 5.1 was simply to make sure that no applications were
going to break if we introduced the Date class later in the
5.1.x series. Unfortunately a lot of projects, including
PEAR, never heard of “prefixing” class names, causing
class name clashes. Marcus described the problem as
“PEAR ignores coding standards, [184]” but others suggested
that we renamed the internal class [185] to something silly

like php_date. Andrei [186] asked “what does renaming really
buy us? The only purpose of introducing this class in RC6,
as far as I can tell, was to reserve the ‘Date’ name for
future use.” Now that we know about this issue, it’s time
for PEAR to start prefixing its classes, so that we finally
can do the right thing and add our Date (and Timezone)
classes, code that has been around for months, now,
and I’m quite tired of waiting for it to be in a release
where I can use it. We ended up reverting the change
that claimed the Date and Timezone classes, and released
5.1.1 with this change.
After the PDM I posted [187] the meeting notes [188] to the
list. Most of the outcome was well appreciated, except
the curly braces idea which has already been discussed.
With these notes, we hope to make PHP 6 a success. The
notes also spawned numerous [189] polls [190] on the symbol to
use for separating namespaces from class names/function
names. We also discussed our version of a goto: labeled [191]
breaks [192].
The filter extension [193], which I’ve been developing for

quite some time, did not make it into PHP 5.1, although
it is a good idea [194] to add it, now, with an “experimental”
status, so that this wanted extension gets more testing.
Perhaps for PHP 5.1.2…

December
December was a quiet month with little action. Ilia
proposed [195] a plan for PHP 5.1.2 and released PHP
5.1.2RC1[196], Zeev committed [197] Dmitry’s re-implementation
of the FastCGI API and some user[198] was whining about
our “official” IRC channel (which doesn’t exist).
That was it for 2005 (as far as PHP internal
development is concerned)! I hope you enjoyed reading
this, and have a happy new year. Extra thanks go to Ilia,
for being the release master, Dmitry for maintaining the
engine, Jani for hunting down bug reports, Andrei for
his work on Unicode, Mike for his enormous stream of
useless commit messages ;-), and to all others who made
PHP happen this year. 

DERICK RETHANS provides solutions for Internet related problems. He
has contributed in a number of ways to the PHP project, including
the mcrypt, date and input-filter extensions, bug fixes, additions
and leading the QA team. He now works as project leader for the
eZ compoments project for eZ systems A.S. In his spare time he likes
to work on, xdebug watch movies, travel and practice photography.
You can reach him at

Volume 5 Issue 1 • php|architect • 15



2005 Look Back
046 />047 />
FOOTNOTES:
001 />002 />003 />004
005 />006 />007 />008 />009 />010 />011 />012 />013 />014 />015 />016 />017 />018 />019 />020
021 />022 />023 />024
025 />026 />027 />028 />029 />030 />031
032 />033
034 />035 />036 />037 />038 />039 />040 />041 />042 />043 />044 />045 />
16 • php|architect • Volume 5 Issue 1

048 />049 />050 />051 />052 />053 />054 />055 />056 />057 />058 />059 />060 />061 />062 />063 />064 />065 />066 />067 />068 />069 />070 />071 />072 />073 />074 />075 />076 />077 />078 />079 />080 />081 />082 />083 />084 />085 />086 />087 />088 />089 />090 />091 />092 />093 />094 />095 />096 />

2005 Look Back
097 />
148 />
098 />
149 />
099 />
150 />
100 />
151 />
101 />
152 />
102 />
153 />
103 />
154 />
104 />

155 />
105 />
156 />
106 />
157 />
107 />
158

108 />
159 />
109 />
160 />
110 />
161 />
111 />
162 />
112 />
163 />
113 />
164 />
114 />
165 />
115 />
166 />
116 />
167 />
117 />
168 />
118 />
169 />

119 />
170 />
120 />
171 />
121 />
172 />
122 />
173 />
123 />
174 />
124 />
175 />
125 />
176 />
126 />
177 />
127 />
178 />
128 />
179 />
129 />
180 />
130 />
181 />
131 />
182 />
132 />
183 />
133 />
184 />

134 />
185 />
135 />
186 />
136 />
187 />
137 />
188 />
138 />
189 />
139 />
190 />
140 />
191 />
141 />
192 />
142 />
193 />
143 />
194 />
144 />
195 />
145 />
196 />
146 />
197 />
147 />
198 />
Volume 5 Issue 1 • php|architect • 17



F EATUR E

PHPLib’s Block Tool

hp
?p
<

PDFLib’s
Block Tool

If you’ve been
developing for any length
of time, you’ve probably been tasked with
generating PDFs at some point. In this article, we’ll
discuss the process of combining data from many
sources into a single PDF—from installation of the
block tool, to creating the blocks in Adobe Acrobat,
and then finally working with the blocks via PDFlib.

b y R o n G of f

T

he PDFLib Block Tool—available for use only
with PDFlib Personalization Server (PPS)—helps
create PDF documents derived from large
amounts of variable data.
Before the block tool was added, it was a

difficult process to place variable data, images, and even
other PDFs into precise areas of a PDF that had been
designed previously. Now, adding variable data is very
simple and helps create great dynamic pieces for just
about any application.

Installing the Block Tool
Currently, the block tool plug-in for Adobe Acrobat is only
available on the Windows and Macintosh (both Mac OS 9
and Mac OS X) platforms. On either platform, you must
also have Version 6 or 7 of Adobe Acrobat Professional
or Adobe Acrobat Standard, or the full version of Adobe
Acrobat 5. Other versions of Adobe Acrobat—Acrobat
Reader, and Acrobat Elements—and all other PDF creation

18 • php|architect • Volume 5 Issue 1

CODE DIRECTORY: pdflib
TO DISCUSS THIS ARTICLE VISIT:
/>tools do not work with the block tool plug-in. (Check the
PDFlib web site for an up-to-date list of supported PDF
authoring tools.)

Windows OS Installation
If you’re using Windows, you can use the block tool
installer provided by PDFlib to get the plug-in installed
correctly into your version of Adobe Acrobat 5, 6,
or 7. The installer places the correct files into the
Acrobat plug-ins folder, which is typically found at
C:\Program Files\Adobe\Acrobat 6.0\Acrobat\plug_ins\

PDFlib. The Windows version of the block tool is

compatible only with PPS version 6.0.1.


PHPLib’s Block Tool

FIGURE 1

FIGURE 2

Mac OS Installation
You can install the block tool in either Mac OS 9 or OS X.
If you own Adobe Acrobat 5, place the files that comprise
the block tool into the Acrobat plug-in directory, typically
located at /Applications/Adobe Acrobat 5.0/Plug-Ins/.
If you’re using Adobe Acrobat version 6 or version 7, save
the files that comprise the block tool into a new directory
and then locate the Acrobat program, which is usually
found at /Applications/Adobe Acrobat 6.0 Professional.
Using the Finder, click once on the Acrobat application
to select it and then choose “File > Get Info” from the
menu bar. Locate the triangle next to the words “Plugins.” Expand the triangle, select “Add,” and then locate
the folder that contains the block tool plug-in files.

The New and Improved Block Tool

If you’ve used previous versions of the block tool,
you’ll notice that the new version is much more user
friendly. The export and import features have also been

updated, making it much quicker to apply blocks from
previously formatted PDFs.

FIGURE 3

Creating Blocks
After you install the block tool, you should see a new
menu called “PDFlib Blocks” in Acrobat’s main menubar.
You should also see a new icon that resembles [=])—this
is the block tool. (See the top of Figure 1.) You use the
block tool icon to create regions that you can fill with
variable data.
When you click the block tool icon and hover over the
PDF, your cursor turns into a crosshair. To create a block,
click the mouse and hold it while dragging your cursor.
As you drag your cursor, a lightly-outlined box should
appear. (See Figure 1.)
When you’re satisfied with the size of the box, release
the mouse button. A menu like the one shown in Figure
3 appears. The menu controls all of the properties of
the block, including the formatting of the data that will
be contained in the block (data that you will add via
Volume 5 Issue 1 • php|architect • 19


PHPLib’s Block Tool
PDFlib).
FIGURE 4
There are three types of blocks that can be created:
• The first and default type of block is text. It

handles any type of text, whether it’s a single
line of text or many lines of text.
• The second type of block is image. As its name
implies, an image block is a container for the
dynamic placement of images within the PDF.
• The third and last type is PDF, which is able to
contain other PDFs.
Each block has general properties (see Figure 2) and
FIGURE 5

type-specific properties. General properties set attributes
such as the placement of the block, its background and
border colours, and its orientation, to name just a few.
Some of the sections that follow describe the typespecific properties.
So what do you do with blocks? As you might have
inferred, already, you use blocks to mix dynamic content
amid static content. A designer can create a PDF, include
static text and images, and then place blocks wherever
dynamic content should appear. Your application “fills
in the blanks,” so to speak, and because blocks retain
properties such as typeface, font size, color, kerning, and
other settings, the block, once filled, looks exactly like
the rest of document—just as the designer intended.
Using blocks, the application that generates each
PDF document need not format anything. However,
if you want to customize a block on-the-fly, you can.
Pre-defined block attributes can be overwritten by your
code.

Editing Block Settings


FIGURE 6

To change a block property, select the block you want
to configure and then navigate to find the property you
want to change. For example, Figure 3 shows how to edit
the textflow property, which can be either true or false
(hence, the dropdown menu).
The purpose of most properties is obvious, but be
careful with attributes that specify font names. Unless
you’re running Acrobat on the same machine as your
PDFlib application, it’s likely that the set of fonts on
the two machines (say, your desktop and the server,
respectively) will differ. Be sure to use the name of fonts
that are installed on your server.

Text Flow Settings
If you want a block to flow (automatically wrap and
justify) arbitrary amounts of text, set the textflow
property to true. Once set to true, an additional button
named TextFlow appears next to the existing button
labeled Text. Click on TextFlow to examine and set specific
variables (such as leading and indents) that control how
text flows in the block. All other text attributes—those
for one line of text or a flow of text—remain in the same
pane as the textflow property.

Mac OS X “Tiger”

If you’re using a very recent version of Mac OS X, you

can find Acrobat’s plug-ins folder by control-clicking
the Acrobat application and selecting “Package
Content”.
20 • php|architect • Volume 5 Issue 1


PHPLib’s Block Tool

Image Settings
By changing the block option to image, you can use
PDFlib to place images dynamically in a PDF. There are far
fewer options for an image block than for a text block.
The options screen for an image block is shown in Figure
5.
The defaultimage attribute names a default image to
place if the image specified by PDFlib is unavailable.
The dpi setting, or the number of dots per inch, is
used to override the dpi of an image. PDFlib will use the
default dpi value of the image if it is available, or 72
dpi if this option isn’t set. If necessary, you can set the
horizontal and vertical dpi independently by supplying
two values instead of one, first horizontal dpi and then
vertical dpi.
The scale property controls the scaling of the
image. You can supply one value to scale horizontally
and vertically equally, or supply two values, one for the
horizontal and another for the vertical scale factor.

FIGURE 7


PDF Settings
The settings for a PDF block are very similar to the settings
for an image block, as shown in Figure 6. defaultpdf
specifies a default PDF to place if the PDF document that
PDFlib names cannot be found.
defaultpdfpage specifies which page of the default
PDF to place if the default PDF must be used.
scale controls the scaling of the PDF. As with an
image, you can specify one value to apply to both axes
or you can provide two values, one for horizontal scaling
and another for vertical scaling.

FIGURE 8

Custom Settings
When using any type of block, you can specify custom
attributes. Custom attributes do not affect the output
when using PDFlib, but can be retrieved by PDFlib for
interpretation by your code. Custom attributes are good
for passing information to the PDFlib program, or even
for just better record keeping.
As an example, say that you want to create a text
block that’s limited to ten characters or less. Create the
text block, add a custom property named length, set it
to 10, and then retrieve the value via PDFlib at runtime.
Your code can verify the length of a string before filling
the block and react accordingly, perhaps truncating the
string or asking the user to provide a new value.

FIGURE 9


The PDFlib Blocks Menu
To make setting up blocks easier, the “PDFlib Blocks”
menu has a few handy tools. You can export and import
blocks to re-use complex blocks, you can align elements,
and more.
Volume 5 Issue 1 • php|architect • 21


PHPLib’s Block Tool

Exporting
The “Export” feature is a huge timesaver when dealing
with multiple PDFs that require the same types of blocks.
Once you’ve finished setting up blocks in a single “master”
PDF, you can export those blocks and then import them
over and over again into other PDFs. There are several
different settings in the “Export” dialog (see Figure 7):
• You can export blocks from all pages of the
PDF or from a subset of them.
• You can export blocks to a new PDF or to an
existing PDF. Selecting “New File on Disk”
creates a blank PDF with the blocks set in
the new file. If you want to export blocks to
a document that you already have opened
in Adobe Acrobat, select “Open Document”
and click “Choose” to see a list of all open
documents. If you choose “Replace Existing
Files”, the block tool will overwrite the target
file with blank pages with the blocks in the

proper place.
• The next option is “Export Which Blocks?” This
section allows you to control which blocks
are exported. You can export all blocks—
depending on the number of pages you choose
in the first section—or just the blocks that
you highlight before exporting. You can also
choose to delete the blocks that exist on the
target PDF.

that it’s your primary choice. Then choose another block;
it should turn blue, indicating that it’s your secondary
choice. When you select “Align,” the blue block should
align with the pink block. Figure 9 shows two blocks,
Block_1, the secondary block, left-aligned to the primary
block, Block_0.
The “Size” alignment option only works when more
than one block is selected. You can change all secondary
blocks (blue) to be either the same width or height as
the primary block (pink).
The “Center” alignment option aligns all blocks
selected either horizontally or vertically, and even both
horizontally and vertically.

Defining Blocks and Detecting
Settings
Two other time savers are available in the “PDFlib Block”
menu: one creates a block from a placed object like an
image, and another creates blocks that automatically
detect the font settings and font color of the font that

the block is being created over.
Click on “Click Object to Define Block” and then click
on an object such as an image to create a block of the
same dimension in the exact same position.
Or, if you click on “Detect Underlying Font and Color”
before you create a block, the block’s font settings are
automatically set to match the style and size of the text
below the new block. This feature is especially useful

Whatever text you “insert” assumes the
formatting of the block.
Importing
You can import blocks from another PDF using the import
option in the “PDFlib Blocks” menu. When you choose
“Import,” you will be presented with a screen to choose
the file that contains the blocks you want to import
(Figure 8).
After you choose the appropriate file, you can
determine which pages the blocks should be applied to.

Alignment Options
The alignment option in the “PDFlib Blocks” menu allows
you to align two blocks.
To align, choose a block. It should turn pink, reflecting

22 • php|architect • Volume 5 Issue 1

when dealing with a lot of text and specific colors. (You
may have to adjust the font name to match a font located
on the server running PDFlib.)


Using Blocks
As you might imagine, working with blocks from within
your code makes placing text, images, and PDFs into a
dynamic PDF far simpler than writing code to control the
pointer, stroke text line-by-line, and so on. With blocks,
formatting is separated from your code, leaving all of the
aesthetics to the designer creating the PDF. Better yet,
a change to the design of the page doesn’t (necessarily)


Anytime

Anytime

Anytime


PHPLib’s Block Tool
necessitate tweaking your code.
Setting up the dynamic PDF document is similar to
what’s been shown in prior chapters, except you need to
pull in the PDF that contains the blocks. First, specify
the basic information:
if (!extension_loaded(‘pdf’)) {
dl(‘libpdf_php.so’);
}
$p = PDF_new();
PDF_begin_document($p, “”, “”);
PDF_set_info($p, “Creator”, “block_tool.php”);

PDF_set_info($p, “Author”, “Ron Goff”);
PDF_set_info($p, “Title”, “Block Tool”);

Next, pull in the PDF page that contains the blocks, place
it into memory, and create a new blank page:
$block_file = “block_file.pdf”;
$blockcontainer = PDF_open_pdi($p, $block_file, “”, 0);
//Page standard 8.5 x 11
PDF_begin_page_ext($p, 612, 792, “”);

Continuing, call up the actual page that you want to use.
In the line of code below, the 1 (numeral one) refers to
page one of the PDF that contains the blocks.
$page = PDF_open_pdi_page($p, $blockcontainer, 1, “”);

If you want to use another page from the “template”
PDF, just specify that page number instead of 1.
Finally, the page with blocks is “copied” to the new
page in the new PDF.
PDF_fit_pdi_page($p, $page, 0.0, 0.0, “adjustpage”);

The adjustpage option adjusts the size of the new
page to match the page size of the template PDF.
adjustpage overrides any page settings that have been
set previously.
From here, you are ready to use the blocks.

Text Blocks
Whether working with a line of text or a text flow, text is
easy to fill in: just specify the name of the block and the

text to render and call PDF_fill_textblock().
$block = “Block_1”;
$text = “All the pie in the sky wasn’t enough to fill my plate”;
PDF_fill_textblock($p, $page, $block, $text, “encoding=winansi”);

The block name, here Block_1, is the name that was
assigned to the block when it was created in the
template PDF. (Block names are unique and the default
name is Block_#, but a block name can be any string of
alphanumeric characters.)
Notice that there are no extra formatting options.
Whatever text you “insert” assumes the formatting of
the block.

24 • php|architect • Volume 5 Issue 1

Form Conversion

You may be familiar with the Adobe Acrobat “Form
Tool,” a great way to create fillable areas of your
PDF. So, why not just use forms to define variable
data placement? Because the form tool is limited:
it cannot specify advanced font settings, whereas
the block tool has been designed specifically to
customize all aspects of your text. However, if
you have a PDF that used the form tool to define
areas for text, there is an option within the “PDFlib
Blocks” menu to convert your pre-made forms into
blocks (Figure 5.4).
If you want to override a block’s formatting, you can.

Where encoding=winansi appears, add the options that
you want to override. For example, to override the font
size, specify encoding=winansi fontsize=12.
You should also enable embedding as needed. You
can enable embedding by adding embedding=true as in
encoding=winansi embedding=true.

Image Blocks
The process of placing an image in an image block
resembles that of placing the image “manually”: the
image is loaded and then placed.
$block4 = “Block_4”;
$image_load = “image.jpg”;
$image = PDF_load_image($p, “auto”, $image_load, “”);
PDF_fill_imageblock($p, $page, $block4, $image, “”);
PDF_close_image($p, $image);

In this example, the image image.jpg is placed in Block_4
using the function PDF_fill_imageblock().

PDF Blocks
The steps to place a PDF document within the dynamicallygenerated PDF are similar to the steps required to set up
a page to work with blocks. You identify which block you
want to “fill,” identify the PDF and the page you want
to extract from, and then fill the named block with that
content.
$block5 = “Block_5”;
$pdf_load = “basic_pdf.pdf”;
$pdf = PDF_open_pdi($p, $pdf_load, “”, 0);
$pdf_fill = PDF_open_pdi_page($p, $pdf, 1, “”);

PDF_fill_pdfblock($p, $page, $block5, $pdf_fill, “”);
PDF_close_pdi($p, $pdf);

PDF_open_pdi() opens the PDF, while PDF_open_pdi_page()
loads the correct page. The function PDF_fill_pdfblock()

puts it all together, placing the actual PDF onto the page.
Finally, close the open PDF by calling PDF_close_pdi(),
which frees the resources consumed by the open PDF.


PHPLib’s Block Tool

Closing the Page
After you’ve filled all of the appropriate blocks on the
open page, you must close that page.
PDF_close_pdi_page($p, $page);

This line closes the PDF and you can start a new page, or
end the entire document after this is called.

Putting All Together
A complete example using the PDF_fill_textblock()
function can be seen in Listing 1.
The PDFlib block tool is easy to use and provides
for complex layouts without extensive programming.
Using blocks, a designer can assign where dynamic text,
images, and even PDFs are to be placed, yielding a much
more professional result. 


RON GOFF is the technical director/senior programmer for Conveyor
Group (www.conveyorgroup.com), a Southern-California based
web development firm. He is the author of several articles for
PHP|Architect magazine and other online publications. Ron’s lives in
California with his wife Nadia and 2 children. You can contact him at


LISTING 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

if (!extension_loaded(‘pdf’)) {
dl(‘libpdf_php.so’);
}
$p = PDF_new();
PDF_begin_document($p, “”, “”);
PDF_set_info($p, “Creator”, “block_tool.php”);

PDF_set_info($p, “Author”, “Ron Goff”);
PDF_set_info($p, “Title”, “Block Tool”);
$block_file = “block_file.pdf”;
$blockcontainer = PDF_open_pdi($p, $block_file, “”, 0);
PDF_begin_page_ext($p, 612, 792, “”);
$page = PDF_open_pdi_page($p, $blockcontainer, 1, “”);
PDF_fit_pdi_page($p, $page, 0.0, 0.0, “adjustpage”);
$block = “Block_1”;
$text = “All the pie in the sky wasn’t enough to “
.”fill my plate”;
PDF_fill_textblock($p, $page, $block, $text, “”);
PDF_close_pdi($p, $blockcontainer);
PDF_close_pdi_page($p, $page);
PDF_end_page_ext($p, “”);
PDF_end_document($p, “”);
$buf = PDF_get_buffer($p);
$len = strlen($buf);
header(“Content-type: application/pdf”);
header(“Content-Length: $len”);
header(“Content-Disposition: inline; “
.”filename=block_pdf.pdf”);
print $buf;
PDF_delete($p);
?>

Volume 5 Issue 1 • php|architect • 25


×