Download the PHP package psliwa/php-pdf without Composer

On this page you can find all versions of the php package psliwa/php-pdf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-pdf

Information

Build Status

Examples

Sample documents are in the "examples" directory. "index.php" file is the web interface to browse examples, "cli.php" is a console interface. Via the web interface, the documents are available in pdf and jpeg format (the jpeg format requires Imagick).

Documentation

Table of contents

  1. Introduction
  2. Installation
  3. Symfony2 bundle
  4. FAQ
  5. Document parsing and creating pdf file
  6. Basic document structure
  7. Inheritance
  8. Stylesheet structure
  9. Palette of colors
  10. Standard tags
  11. Attributes
  12. Complex attributes
  13. Units
  14. Barcodes
  15. Charts
  16. Hyperlinks
  17. Bookmarks
  18. Sticky notes
  19. Repetitive headers and footers
  20. Watermarks
  21. Page numbering
  22. Using the pdf document as a template
  23. Separate page on columns
  24. Breaking pages and columns
  25. Metadata
  26. Configuration
  27. Markdown support
  28. [Image generation engine] (#image-generation)
  29. Known limitations
  30. TODO - plans
  31. Technical requirements

Introduction

PHPPdf is library that transforms an XML document to a PDF document or graphics files. The XML source document is similar to HTML, but there are lots of differences in names and properties of attributes, properties of tags, and there are a lot of not standard tags, not all tags from html are supported, stylesheet is described in an xml document, not in css.

Assumption of this library is not HTML -> PDF / JPEG / PNG, but XML -> PDF / JPEG / PNG transformation. Some tags and attributes are the same as in HTML in order decrease the learning curve of this library.

Installation

PHPPdf is available at packagist.org, so you can use composer to download this library and all dependencies.

(add to require section in your composer.json file)

You should choose last stable version (or wildcard of stable version), wildcard char ("*") is only an example.

If you want to use as features as barcodes or image generation, you should add extra dependencies:

Symfony2 bundle

There is a Symfony2 bundle which integrates this library with the Symfony2 framework.

FAQ

Diacritical marks are not displayed, what should I do?

You should set a font that supports the encoding that you are using, and set this encoding as "encoding" attribute for "page" and/or "dynamic-page" tags. PHPPdf provides some free fonts that support utf-8 encoding, for example, DejaVuSans. The "Font" example shows how to change the font type by using a stylesheet.

You can also add custom fonts, in order that you should prepare xml config file and configure Facade object as shown below:

You can find more datails in the Configuration section.

Generating of a simple pdf file with png images takes a lot of time and memory, what should I do?

PHPPdf uses the Zend_Pdf library that poorly supports png files without compression. You should compress the png files.

How can I change the page size/orientation?

To set the page dimensions you use the "page-size" attribute of the page or dynamic-page tags.

The value syntax of this attribute is "width:height".

There are however standard predefined values:

All formats are supported in portrait and lanscape.

Example:

Document parsing and creating a pdf file

The simplest way of using the library is:

Basic document structure

The library bases pages on an XML format similar to HTML, but this format isn't HTML - some tags are diffrent, interpretation of some attributes is not the as same as in the HTML and CSS standards, adding attributes is also different.

A simple document has following structure:

Adding a DOCTYPE declaration is strongly recommended in order to replace html entities on values:

The root name of a document must be "pdf". The "dynamic-page" tag is an auto breakable page. The "page" tag is an alternative, and represents only a single, no breakable page.

The way of attribute setting is different than in HTML.

In order to set a background and border you need to use complex attributes, where first part of attribute name is a complex attribute type, and the second part is the property of this attribute.

Complex attribute parts are separated by a dot (".").

An another way of setting complex attributes is by using the "complex-attribute" tag.

Example:

Alternative syntax ("stylesheet" tag):

Attributes can by set as XML attributes, directly after a tag name or by using the mentioned "stylesheet" tag. The HTML "style" attribute does not exist the PHPPdf XML dialect.

The library is very strict in respecting the corectness of tags and attributes. If an unexisted tag or attribute is detected, the document parser will stop and throw an exception.

Inheritance

The "id" attribute has an different usage than in HTML. The id attribute is used to identify tags when using inheritance.

The "name" attribute can also be used as an alias to "id".

An id must by unique throughout the document, otherwise a parsing error is thrown.

Example:

The Second layer inherits all attributes (simple and complex), and also those from external stylesheets.

Priorites in attributes setting:

  1. Stylesheet tag directly in an element tag
  2. Attributes directly after a tag name (XML attributes)
  3. Attributes from external stylesheets
  4. Inherited attributes from a parent tag

Example:

The second "div" will now have the following attributes:

Stylesheet structure

Stylesheets are defined in external files, stylesheet short and long declarations of attributes are supported.

Syntax of the stylesheet:

Short style:

Long style:

Palette of colors

PHPPdf supports color palettes, - mapping of logical names to real colors.

Color palettes gives you the opportunity to create or overwrite default named colors. By default, PHPPdf supports named colors from the W3C standard (for example "black" = "#000000").

You can use a palette for the DRY principle, because information about used colors will be kept in one place. And you can also generate one document with different palettes.

Example:

Standard tags

The library supports primary HTML tags:

In addition there are also not standard tags:

There are tags that are only bags for attributes, a set of tags etc:

Attributes

Complex attributes

Complex attributes can be set by notation "attributeName.attributeProperty" or "attributeName-attributeProperty"

For example: or

It is possible to add several complex attributes in the same type (for instance 3 different borders).

You can achieve that by using the "stylesheet" tag instead of the short notation.

In this example, the second border has a "borderLeftAndRight" indentifie, if this border had no id, the attributes from second border would be merged with the attributes from first border.

Remeber the default identifier "id" is as same as the "name" attribute. The "id" attributes for complex attributes has nothing to do with the "id" attribute of tags (used in inheritance).

It is possible to create complex borders the same as in the previous example (outerBorderLeftAndRight).

Units

Supported units for numerical attributes:

Currently unsupported units are: em and ex

When the unit is missing (for example: font-size="10"), then the default unit is points (pt). 1pt = 1/72 inch

Barcodes

Barcodes are supported by the tag.

PHPPdf uses the Zend\Barcode library in order to generate barcodes.

Example:

tag supports the most of standard attributes and has some other attributes:

You can find the description of these options and there default values in the Zend\Barcode documentation.

In order to render textual barcodes, you can't use to following embeded pdf fonts: courier, times-roman and helvetica. This will soon be fixed.

Charts

PHPPdf supports drawing simple charts.

For now there is only support for s simple pie chart.

Example:

The tag has three extra attributes:

Hyperlinks

The library supports external and internal hyperlinks.

External hyperlinks link to url's, while internal links link to other tags inside the pdf document.

Example:

Every element has a "href" and "ref" attribute, even div. You can't nest elements inside an "a" tag.

If you want to use img elements as a link, you should use the href (external link) or ref (internal link) attribute directly in img tag.

Bookmarks

The preferred way of creating bookmarks is by using the "behaviours" tag.

This doesn't restrict the structure of the document, the owner of a parent bookmark doesn't have to be a parent of a child's bookmark owner.

Example:

A shortcut for the "bookmark" behaviour is the "bookmark" attribute, if you assign some value to this attribute, bookmarks that refers to this tag will be automatically created.

The bookmark of a parent tag is also the parent of a children's bookmarks.

Example:

The above structures (both examples) will create this bookmarks structure:

Sticky notes

Sticky notes can be created by using the "note" attribute.

Example:

The XML parser normalizes values of attributes, wich results ignoring new line characters.

If you want to add a note with new line characters, you should use this syntax:

Repetitive headers and footers

"placeholders" can be used in for adding a repetitive header or/and footer.

Some elements have special "placeholders": page has header and footer, table also has header and footer (TODO: not implemented yet) etc.

Header and footer need to have a height attribute set. This height is pooled with page top and bottom margins.

Workspace is the page size reduced by page margins and placeholders (footer and header) height.

Watermarks

Page can have a "watermark" placeholder.

The watermark may be set on block's and container elements, for instance: div, p, h1 (no span, plain text or img).

If you want to use an image as a watermark, you should wrap the img tag in a div.

Example:

Page numbering

There are two tags that can be used to show page information in a footer, header or watermark: page-info and page-number.

This element only works with dynamic-page, not single pages. Page-info shows the current and total page number, page-number shows only the current page number.

Attributes of this tags:

Example:

Using a pdf document as a template

The "page" and "dynamic-page" tags can have a "document-template" attribute, that allows you to use an external pdf document as a template.

For the "page" tag, the page's template will be the first page of an external document.

For the "dynamic-page" tag, the template for each page will be the corresponding page of an external document.

Example:

Separate page on columns

Page can be separated on columns:

The above XML describes several pages of the pdf document, with green rectangles separated on two columns.

The "column-layout" tag has three additional parameters: number-of-columns, margin-between-columns and equals-columns.

Default values for this attributes are 2, 10 and false respectlivy. If the equals-columns attribute is set, columns will have more or less equals height.

Breaking pages and columns

Page and column may by manually broken using one of these tags: page-break, column-break, break.

All these tags are the same. These tags need to be direct children of the breaking element (dynamic-page or column-layout).

If you want to avoid automatic page or column break on certain tags, you should set the "breakable" attribute of this tag to "off.

Example:

Metadata

Metadata can be added by attributes at the document's root.

Supported metadata is: Creator, Keywords, Subject, Author, Title, ModDate, CreationDate and Trapped.

These attribute names are case sensitive.

Example:

Configuration

The library has four primary config files that allow you to adopt the library for specyfic needs and extending.

In order to change default the config files, you must pass to Facade constructor configured Loader object:

If you want to change only one config file, you should use LoaderImpl::set* method:

FacadeBuilder can be uset to build and configure Facade. FacadeBuilder is able to configure cache, rendering engine and document parser.

Markdown support

Library supports basic (official) markdown syntax. To convert markdown document to pdf, you should configure Facade object by MarkdownDocumentParser. You also might to use FacadeBuilder to do this for you.

Example:

By default, in markdown pdf document, helvetica font is used. If you want to use utf-8 characters or customize a pdf document, you should provide your own stylesheet by using the FacadeBuilder::setMarkdownStylesheetFilepath method.

The stylesheet structure has been described in the stylesheet chapter. By default the stylesheet is empty, if you want to set another font type, the stylesheet should look like this:

Internally the MarkdownDocumentParser converts a markdown document to html (via the PHP markdown library), then converts html to xml, and at last xml to a pdf document.

Be aware of that, if you in a markdown document use raw html that will be incompatible with the xml syntax of PHPPdf (for example unexistend attributes or tags), the parser will throw an exception then.

Not all tags used in the markdown implementation are propertly supported by PHPPdf, for example "pre" and "code" tags.
For now "pre" tag is an alias for "div", and "code" tag is an alias for "span", be aware of that.

Image generation engine

PHPPdf is able to generate image (jpg or png) files insted of a pdf document. To achieve that, you must configure the FacadeBuilder, example:

By default the GD library is used to render an image.

But you can also use Imagick, which offers a better quality, so it is recommended that if you have the opportiunity to install Imagick on your server. To switch the graphic library, you must configure the FacadeBuilder object using the setEngineOptions method:

Supported graphic libraries are: GD (default), imagick, gmagick. PHPPdf uses the Imagine library as an interface for graphics file generation.

Known limitations

Below is a list of known limitations of the current version of the library:

TODO - plans

Technical requirements

This library works with php 5.3 and up.


All versions of php-pdf with dependencies

PHP Build Version
Package Version
Requires zendframework/zendpdf Version ~2.0.0
zendframework/zend-cache Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package psliwa/php-pdf contains the following files

Loading the files please wait ....