Download the PHP package popphp/pop-pdf without Composer

On this page you can find all versions of the php package popphp/pop-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 pop-pdf

pop-pdf

Build Status Coverage Status

Join the chat at https://popphp.slack.com Join the chat at https://discord.gg/TZjgT74U7E

Overview

Pop PDF is a robust PDF processing component that's simple to use. With it, you can create PDF documents from scratch, or import existing ones and add to or modify them. It supports embedding images, fonts and URLs, as well as a set of drawing, effect and type features.

pop-pdf is a component of the Pop PHP Framework.

Top

Install

Install pop-pdf using Composer.

composer require popphp/pop-pdf

Or, require it in your composer.json file

"require": {
    "popphp/pop-pdf" : "^5.0.0"
}

Top

Quickstart

Create a simple PDF

Create a simple 1-page PDF document with the text "Hello World" on the page. The page size will be letter. The text string will be positioned (50, 50) from the top left and use the standard Arial font.

Embed an image

Using the same example from above, let's add an image to it:

Top

PDF

The PDF format specification is a vast and comprehensive format that has been around for a long time. It is comprised of other various media specifications such as fonts and images. The pop-pdf attempts to present all of these various components in an intuitive, object-oriented way so that a developer can assemble, build and compile valid PDF documents programmatically.

The main Pop\Pdf\Pdf class serves as a simple processing class with a set of static methods to route the various object components to the right place to be processed.

Write to File

Once a PDF document has been assembled, you can pass it to the writeToFile() method to compile the PDF and save it to a file on disk:

Output to HTTP

Alternatively, you can push the PDF document out to an HTTP client. Giving it a filename sets the Content-Disposition filename value. Setting $forceDownload to true sets the Content-Disposition value to "attachment" to force a download (vs display inline.) A fourth $headers parameter is available to output any additional HTTP headers.

Import from File

You can take an existing PDF and import it to add new content to it. It will translate the PDF document's content into the appropriate objects such as pages, fonts, images and text. From there, you can add more content to the PDF document object and save it.

You can also choose which pages of a PDF document to import:

Import from Raw Data

If you have a stream of raw data from a PDF file, you can import that as well. This method supports optional page selection as well

Import from Images

If you have an array of images, you can convert them into a PDF document object where each image becomes a page in the PDF document.

Extract Text

If you just want to extract the text from a PDF that contains text (not a PDF comprised of images with text in them), you can do so like this:

Top

Documents

The document object serves as the main collection object of all of the components that go into building and compiling a PDF document. This includes pages, fonts and forms.

Compression

A PDF document can be compressed if needed to attempt to reduce file size.

Page Origin

A potentially confusing aspect of PDF documents is that the default page origin is the bottom left. This means that all coordinates and any math based on the coordinates has to be calculated from the bottom left.

If you'd prefer to calculate the origin from a different place, you can set that with the setOrigin() method on the document object. This will automatically translate your preferred origin to the native PDF origin.

Options for setting the origin of the document are:

Top

Pages

Pages can be virtually any size, but there are a number of pre-defined sizes available as constants in the Pop\Pdf\Document\Page class:

Page (W x H) Page (W x H) Page (W x H)
ENVELOPE_10 (297 x 684) A1 (1684 x 2384) B1 (2064 x 2920)
ENVELOPE_C5 (461 x 648) A2 (1191 x 1684) B2 (1460 x 2064)
ENVELOPE_DL (312 x 624) A3 (842 x 1191) B3 (1032 x 1460)
FOLIO (595 x 935) A4 (595 x 842) B4 (729 x 1032)
EXECUTIVE (522 x 756) A5 (420 x 595) B5 (516 x 729)
LETTER (612 x 792) A6 (297 x 420) B6 (363 x 516)
LEGAL (612 x 1008) A7 (210 x 297) B7 (258 x 363)
LEDGER (1224 x 792) A8 (148 x 210) B8 (181 x 258)
TABLOID (792 x 1224) A9 (105 x 148) B9 (127 x 181)
A0 (2384 x 3370) B0 (2920 x 4127) B10 (91 x 127)

Alternatively, you can use the document object as a page factory, which will create a page object, automatically add the page to the document object and return the new page:

There are a number of other methods within the document object to assist with managing various components:

Top

Fonts

Fonts are required to be added to a document for any text that might be added to any page. The font that a text object uses will be defined when adding the text to a page object, but that font will need to be present in the document object. Once fonts are added to a document, they can be used repeatedly by any text objects on any pages of the document.

There are two types of supported fonts: standard and embedded.

Top

Standard

Part of the PDF specification is that a total of 25 standard fonts that are supported by PDF and PDF readers. This means that no additional font files have to be embedded and the fonts are available by default.

Standard PDF Fonts
Arial CourierNew,Bold Times-Bold
Arial,Italic Courier-BoldOblique Times-Italic
Arial,Bold CourierNew,BoldItalic Times-BoldItalic
Arial,BoldItalic Helvetica TimesNewRoman
Courier Helvetica-Oblique TimesNewRoman,Italic
CourierNew Helvetica-Bold TimesNewRoman,Bold
Courier-Oblique Helvetica-BoldOblique TimesNewRoman,BoldItalic
CourierNew,Italic Symbol ZapfDingbats
Courier-Bold Times-Roman

References to each of these standard fonts are available as constants on the main font class, Pop\Pdf\Document\Font:

Top

Embedded

If you require a font outside of the set of standard fonts, the PDF specification supports embedding a number of different external font formats:

Most fonts of these types should work, but there are situations were the font may not be parsable, such as when a font's embeddable flag is set to false.

Top

Text

Once font objects have been added to a document object, text objects can then be added to page objects, while referencing the available font objects in the document.

The constructor of the text object takes the string and the size:

There are a number of methods to assist in modifying the text object:

A basic character wrap can be set with the setCharWrap() method. The leading of the wrapped text can be either set with the second parameter or by the setLeading() method.

Top

Styles

Style objects can be added to the document to provide easier management of text and font styles used in multiple places across the PDF document and its pages.

So any text added to any page referencing the same style can easily be changed across the entire document by only changing the style object.

Top

Alignment

Alignment objects are objects that assist with handling more advanced alignment and wrapping of text based on geometric positioning. When creating an alignment object, you define a bounding areas to which the text will be confined.

Left-aligned box

Right-aligned box

Center-aligned box

Top

String Width

An important and useful tool with working with text and fonts to the ability to calculate the width of a string of characters rendered in a particular font. This is very helpful when attempting to correctly position text on the page.

There is a method on the font object that will allow you pass a string of text to it, as well as the desired size, to give you the approximate width those characters will take up rendered in that font at that size.

This works for both standard and embedded fonts.

This will give us the approximate width in points of the string Hello World in 12pt Helvetica Bold:

Top

Images

Images can be easily added to page objects. However, in a PDF document, the origin of an image is the bottom of the image. You will have to consider how the image's height affects the placement of the image on the page in relation to the page origin.

In this example below, the image is 320 x 320. If you place the $y value at 742 (top origin 792 - 50), then only the bottom 50 pixels of the image would display at the top of the page, while the remainder bleeds off the top page border. Therefore, the height should be taken into account and the $y value should be a value like 422 (top origin 792 - 50 - 320). This would make the image appear with the top of it starting at 50 pixels from the top of the page, and you would be able to safely see the entire image on the page.

In the above example, the image is pulled from a file. You can also import an image from a raw stream:

Top

Image Size

You can resize a larger image when adding it to a page.

The following methods are available to resize an image:

The $preserveResolution flag is set to false by default. This will resize the image resource, which will reduce it in not only dimensional size, but also reduce its data size as well.

If you wish to keep the image in its original higher quality, and only reduce the dimensions, you can set the $preserveResolution flag to true. This is typically a good method to keep the image clean and crisp when being reduced to a smaller dimension.

Top

Paths

You can add path objects to a page to draw vector lines and shapes on the page object.

The methods to control color and style include:

The setStyle() method can take one of the available style constants as its parameter:

The basic methods available to draw paths and shapes are:

Top

Annotations

Annotation objects provide a way to link to external URLs or an internal pointer within the document.

URLs

The following example will generate an invisible annotation box area over the text Visit Google that links to Google's home page:

Top

Internal

The following example will add 2 pages to the document and link from the first page to the second page. When creating an internal link, you can define the following:

Top

Forms

Forms and form fields are supported in Pop PDF, however, please note that not all browsers consistently support forms and form fields in their default PDF readers. It is recommended that if you generate a PDF with a form in it using Pop PDF, that your end user views it in an Adobe product.

The types of fields that are currently supported in Pop PDF are:

NOTE: A group of radio buttons is not supported at this time.

The following script below demonstrates how to add the various fields to a form in a PDF object. While lengthy, it includes text and graphic support for field names and borders:

The above code produces a PDF with a form like this:

Top

HTML

HTML rendering is available in pop-pdf, however it is still in an experimental beta stage.

Parsing HTML from a file:

If you have an HTML file, it will parse all of the HTML in it, as well as any linked CSS and images:

You can also parse HTML and CSS strings directly. The directory path is needed to give the parser a base folder to attempt to access other assets, such as images.

Top


All versions of pop-pdf with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1.0
popphp/pop-color Version ^1.0.0
popphp/pop-css Version ^2.0.0
popphp/pop-dom Version ^4.0.0
popphp/pop-utils Version ^2.1.0
smalot/pdfparser Version ^2.10.0
ext-gd Version *
ext-iconv Version *
ext-mbstring Version *
ext-zlib Version *
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 popphp/pop-pdf contains the following files

Loading the files please wait ....