Download the PHP package its404/php-puppeteer without Composer

On this page you can find all versions of the php package its404/php-puppeteer. 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?
its404/php-puppeteer
Rate from 1 - 5
Rated 4.00 based on 1 reviews

Informations about the package php-puppeteer

PHP Puppeteer

This project provides the ability to generate PDF with Puppeteer in PHP

Dependencies

The library is running based on Nodejs(7.6 above) and Puppeteer It is tested under NodeJS 8.

Installation on CentOS 7:

Installation on Ubuntu 16.04:

Installation

Install its404/php-puppeteer using Composer.

composer require its404/php-puppeteer

Usage

Parameters

The library has set some default parameter values to support basic features, you can set the customized parameters to override the default ones, it supports all parameters of Puppeteer API

Sample parameter array:

$config  = [
    'html' => "<h1>Hello World</h1>",
    'pdf' => [
        'path' => '/tmp/test.pdf',
        'margin' => [
            'top' => '10mm',
            'right' => '10mm',
            'bottom' => '10mm',
            'left' => '10mm',
        ]
    ]
];

Note:

  1. If both $config['pdf']['html'] and $config['pdf']['url'] are set, html will be picked up.
  2. If $config['pdf']['path'] is not set, will return pdf data

Import

You need to import this namespace at the top of your PHP class

use Its404\PhpPuppeteer\Browser;

PDF by URL

You can generate PDF by URL through pdf function:

public function actionTest1()
{
    $config = [
        "url" => "https://www.highcharts.com/demo/line-basic",
    ];
    $browser = new Browser();
    $browser->isDebug = true;
    $content = $browser->pdf($config);

    header("Content-type:application/pdf");
    echo $content;
}

You can set any parameter in $config to override the default values

PDF by HTML

You can generate PDF by html code through pdf function:

public function actionTest2()
{
    $config = [
        "html" => "<h1>Hello Wolrd</h1>"
    ];
    $browser = new Browser();
    $content = $browser->pdf($config);

    header("Content-type:application/pdf");
    echo $content;
}

Debug The class Browser has one parameter $isDebug, it would be debug mode if it's true, detailed error messages would be returned from pdf function if an error happened during Puppeteer running.

PDF to specific path

You can generate PDF to a specific path by setting $config['pdf']['path']

public function actionTest3()
{
    $config = [
        "html" => "<h1>Hello Wolrd</h1>",
        'pdf' => [
            'path' => '/tmp/test.pdf',
        ]
    ];
    $browser = new Browser();
    $browser->isDebug = true;
    $result = $browser->pdf($params);

    if (isset($result['returnVal'])&& $result['returnVal'] == 0) {
        echo "PDF generated successfully";
    } else {
        echo "Failed to generate PDF";
        var_dump($result['output']);
    }
}

Start a new page on PDF

You can add following html code in the html where you'd like to start a new page for PDF.

<div style="page-break-after:always;"></div>

More Examples?

You can find more examples from here


All versions of php-puppeteer with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.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 its404/php-puppeteer contains the following files

Loading the files please wait ....