-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
|
||
/vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
# To get started | ||
# wkhtmltopdf docker | ||
This is a docker micro-service which has a simple api to generate PDFs. | ||
|
||
## To set up the server | ||
``` | ||
docker build -t wkhtmltopdf . | ||
docker run -d -p 80:80 -v $(pwd)/api:/var/www/html wkhtmltopdf | ||
``` | ||
|
||
## To put in a PHP project | ||
|
||
```php | ||
require_once "vendor/autoload.php"; | ||
|
||
use GuzzleHttp\Client; | ||
use PDFGenerator\PDFGenerator; | ||
use PDFGenerator\Implementation\RemotePDF; | ||
|
||
$client = new Client(['base_uri' => 'http://192.168.0.1:8080']); | ||
$generator = new PDFGenerator(new RemotePDF($client)); | ||
|
||
header("Content-type:application/pdf"); | ||
|
||
echo $generator->fromURL('http://www.google.co.uk'); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "amonger/wkhtmltopdf-api", | ||
"authors": [ | ||
{ | ||
"name": "Alan Monger", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"guzzlehttp/guzzle": "^6.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"PDFGenerator\\" : "src/" | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace PDFGenerator; | ||
|
||
abstract class AbstractPDFGenerator implements PDFGeneratorInterface | ||
{ | ||
protected $generator; | ||
|
||
public function __construct(PDFGeneratorInterface $generator) | ||
{ | ||
$this->generator = $generator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace PDFGenerator\Implementation; | ||
|
||
use PDFGenerator\PDFGeneratorInterface; | ||
use GuzzleHttp\Client; | ||
|
||
class RemotePDF implements PDFGeneratorInterface | ||
{ | ||
private $client; | ||
|
||
public function __construct(Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
public function fromURL($url) | ||
{ | ||
$res = $this->client->post('/url', [ | ||
'query'=> [ | ||
'url' => $url | ||
] | ||
]); | ||
|
||
return base64_decode($res->getBody()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace PDFGenerator\Implementation; | ||
|
||
use PDFGenerator\PDFGeneratorInterface; | ||
use Knp\Snappy\Pdf; | ||
|
||
class WKHTMLToPDF implements PDFGeneratorInterface | ||
{ | ||
private $pdf; | ||
|
||
public function __construct(Pdf $pdf) | ||
{ | ||
$this->pdf = $pdf; | ||
} | ||
|
||
public function fromURL($url) | ||
{ | ||
return $this->pdf->getOutput($url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace PDFGenerator; | ||
|
||
class PDFGenerator extends AbstractPDFGenerator | ||
{ | ||
public function fromURL($url) | ||
{ | ||
return $this->generator->fromURL($url); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace PDFGenerator; | ||
|
||
interface PDFGeneratorInterface | ||
{ | ||
public function fromURL($url); | ||
} |