-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathasync-react-webkit.php
More file actions
46 lines (33 loc) · 976 Bytes
/
async-react-webkit.php
File metadata and controls
46 lines (33 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
require __DIR__ . "/../vendor/autoload.php";
use AsyncPHP\Paper\Factory;
use React\EventLoop\Factory as EventLoopFactory;
error_reporting(E_ERROR | E_PARSE);
// this too could be async...
$sample = file_get_contents(__DIR__ . "/sample.html");
$factory = new Factory();
$driver = $factory->createDriver([
"driver" => "webkit",
]);
$runner = $factory->createRunner([
"runner" => "react",
]);
$loop = EventLoopFactory::create();
// this is a React\ChildProcess\Process...
$process = $driver
->body($sample)
->size("A4")
->orientation("portrait")
->dpi(300)
->render($runner);
$process->on("exit", function() use ($loop) {
$loop->stop();
});
$loop->addTimer(0.001, function($timer) use ($process) {
$process->start($timer->getLoop());
$process->stdout->on("data", function($output) {
// this too could be async...
file_put_contents(__DIR__ . "/async-react-webkit.pdf", $output);
});
});
$loop->run();