The Bit&Black PrintCSS Renderer library provides a consistent API to handle all existing PrintCSS renderers in the same way.
This library was written in PHP and requires a token before it can be installed. The use of the library is subject to a fee.
Once you received a token you can add the library to your project by running $ composer require bitandblack/printcss-renderer
.
Initialize the Renderer with an instance of the renderer you want to use:
<?php
use BitAndBlack\PrintCSS\Renderer\Renderer;
use BitAndBlack\PrintCSS\Renderer\Renderer\PDFreactor;
$pdfReactor = new PDFreactor('my-license');
$renderer = new Renderer($pdfReactor);
Configure the renderer with the needed settings:
<?php
use BitAndBlack\ICCProfile\File;
use BitAndBlack\ICCProfile\FileEnum;
use BitAndBlack\ICCProfile\ICCProfile;
use BitAndBlack\PrintCSS\Renderer\Enum\OutputIntentEnum;
$renderer
->setOutputIntent(OutputIntentEnum::PDF_X_4())
->setICCProfile(new ICCProfile(
new File(FileEnum::PROFILE_PSOcoated_v3())
))
->setColorConversionEnabled(true)
;
Use the convert
method then to get PDF files from HTML:
<?php
$document = (string) file_get_contents('my-input-file.html');
$response = $renderer->convert($document);
file_put_contents(
'my-output-file.pdf',
$response
);