All Projects → asyncphp → Paper

asyncphp / Paper

Licence: mit
Hassle-free HTML to PDF conversion abstraction library.

Projects that are alternatives of or similar to Paper

Docconv
Converts PDF, DOC, DOCX, XML, HTML, RTF, etc to plain text
Stars: ✭ 735 (+275%)
Mutual labels:  pdf, conversion
Svg2pdf.js
A javascript-only SVG to PDF conversion utility that runs in the browser. Brought to you by yWorks - the diagramming experts
Stars: ✭ 231 (+17.86%)
Mutual labels:  pdf, conversion
Gotenberg
A Docker-powered stateless API for PDF files.
Stars: ✭ 3,272 (+1569.39%)
Mutual labels:  pdf, conversion
Nb pdf template
A more accurate representation of jupyter notebooks when converting to pdfs.
Stars: ✭ 109 (-44.39%)
Mutual labels:  pdf, conversion
Diffadapter
A high-performance , easy-to-use Adapter for RecyclerView ,using diffutil
Stars: ✭ 193 (-1.53%)
Mutual labels:  async
Androidpdf
Stars: ✭ 190 (-3.06%)
Mutual labels:  pdf
Http Kit
http-kit is a minimalist, event-driven, high-performance Clojure HTTP server/client library with WebSocket and asynchronous support
Stars: ✭ 2,234 (+1039.8%)
Mutual labels:  async
Algorithms
This repository is for learning and understanding how algorithms work.
Stars: ✭ 189 (-3.57%)
Mutual labels:  pdf
Gmqtt
Python MQTT v5.0 async client
Stars: ✭ 195 (-0.51%)
Mutual labels:  async
Trilogy
TypeScript SQLite layer with support for both native C++ & pure JavaScript drivers.
Stars: ✭ 195 (-0.51%)
Mutual labels:  async
Actix Extras
A collection of additional crates supporting the actix and actix-web frameworks.
Stars: ✭ 190 (-3.06%)
Mutual labels:  async
Thirtyfour
Selenium WebDriver client for Rust, for automated testing of websites
Stars: ✭ 191 (-2.55%)
Mutual labels:  async
Stripe
Typed .NET clients for stripe.com REST APIs
Stars: ✭ 193 (-1.53%)
Mutual labels:  async
Comics Downloader
tool to download comics and manga in pdf/epub/cbr/cbz from a website
Stars: ✭ 190 (-3.06%)
Mutual labels:  pdf
Markdown Pdf
📄 Markdown to PDF converter
Stars: ✭ 2,365 (+1106.63%)
Mutual labels:  pdf
Vkbottle
Homogenic! Customizable asynchronous VK API framework
Stars: ✭ 191 (-2.55%)
Mutual labels:  async
Ppipe
pipes values through functions, an alternative to using the proposed pipe operator ( |> ) for ES
Stars: ✭ 192 (-2.04%)
Mutual labels:  async
Fooproxy
稳健高效的评分制-针对性- IP代理池 + API服务,可以自己插入采集器进行代理IP的爬取,针对你的爬虫的一个或多个目标网站分别生成有效的IP代理数据库,支持MongoDB 4.0 使用 Python3.7(Scored IP proxy pool ,customise proxy data crawler can be added anytime)
Stars: ✭ 195 (-0.51%)
Mutual labels:  async
Vim Signify
➕ Show a diff using Vim its sign column.
Stars: ✭ 2,390 (+1119.39%)
Mutual labels:  async
Html To Pdfmake
This module permits to convert HTML to the PDFMake format
Stars: ✭ 190 (-3.06%)
Mutual labels:  pdf

Paper

Hassle-free HTML to PDF conversion abstraction library.

Installation

composer require asyncphp/paper

For best results, you should also install Prince and WKHTMLtoDPF. To run the tests, you'll also need to install diff-pdf. If you don't have the latter installed, you'll not be able to run the tests. If you don't have the former installed, the relevant tests will be skipped, and drivers unusable.

Usage

You can use any of the drivers directly:

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;
}));

However, it's must easier to use the factory, to create pre-configured drivers:

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);

Paper takes an async-first approach. Operations, like rendering PDF files, are particularly suited to parallel processing architecture. You may be stuck rending PDF files in a synchronous architecture, in which case you can use the SyncDriver decorator:

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

// ...or with the factory

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

Drivers

Here's a list of the drivers to currently support:

DOMPDF

  • Requires command-line utilities: no
  • Supports modern CSS: no
  • Supports modern JS: no
  • Produces vector files: yes
  • Open + free: yes

WKHTMLtoDPF

  • Requires command-line utilities: yes
  • Supports modern CSS: yes
  • Supports modern JS: yes
  • Produces vector files: yes
  • Open + free: yes

Prince

  • Requires command-line utilities: yes
  • Supports modern CSS: yes
  • Supports modern JS: yes
  • Produces vector files: yes
  • Open + free: no

Runners

Paper supports Amp and React, to package and run the async code. You have to install one of the following library groups:

Amp

composer require amphp/loop
composer require amphp/parallel
composer require async-interop/event-loop

React

composer require react/event-loop
composer require react/child-process
composer require jeremeamia/superclosure

Take a look at the examples folder to find out more about using the async drivers.

Roadmap

  • Setters for default margin
  • Setters for header HTML
  • Setters for footer HTML
  • More drivers (especially DocRaptor – a SaaS version of Prince)

Versioning

This library follows Semver. According to Semver, you will be able to upgrade to any minor or patch version of this library without any breaking changes to the public API. Semver also requires that we clearly define the public API for this library.

All methods, with public visibility, are part of the public API. All other methods are not part of the public API. Where possible, we'll try to keep protected methods backwards-compatible in minor/patch versions, but if you're overriding methods then please test your work before upgrading.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].