PHP code example of asyncphp / paper

1. Go to this page and download the library: Download asyncphp/paper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

asyncphp / paper example snippets


use AsyncInterop\Loop;
use AsyncPHP\Paper\Driver\DomDriver;
use AsyncPHP\Paper\Runner\AmpRunner;

Loop::execute(Amp\wrap(function() use ($sample) {
    $driver = new DomDriver();
    $runner = new AmpRunner();

    $promise = $driver
        ->html($sample)
        ->size("A4")
        ->orientation("portrait")
        ->dpi(300)
        ->render($runner);

    $results = yield $promise;
}));

use AsyncPHP\Paper\Factory;

$config = [
    "driver" => "dom",

    "dom" => [
        "options" => [
            "fontDir" => __DIR__ . "/fonts",
            // https://github.com/dompdf/dompdf/blob/master/src/Options.php
        ],
    ],

    "prince" => [
        "binary" => "/opt/prince/bin/prince",
        "tempPath" => __DIR__,
        "options" => [
            "--no-compress",
            "--http-timeout" => 10,
            // https://www.princexml.com/doc/command-line/#command-line
        ],
    ],

    "webkit" => [
        "binary" => "/usr/local/bin/wkhtmltopdf",
        "tempPath" => __DIR__,
        "options" => [
            "--grayscale",
            "--javascript-delay" => 500,
            // http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
        ],
    ],

    "runner" => "amp",
];

$factory = new Factory();
$driver = $factory->createDriver($config);
$runner = $factory->createRunner($config);

yield $driver->html($sample)->render($runner);

$driver = new SyncDriver(new DomDriver());

// ...or with the factory

$driver = $factory->createDriver([
    "driver" => "dom",
    "sync" => true,
]);