Skip to content

Commit

Permalink
Add php integration
Browse files Browse the repository at this point in the history
  • Loading branch information
amonger committed Jan 20, 2016
1 parent 1eea758 commit 5292aea
Show file tree
Hide file tree
Showing 44 changed files with 120 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Created by .ignore support plugin (hsz.mobi)

/vendor/
22 changes: 21 additions & 1 deletion README.md
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');
```
17 changes: 17 additions & 0 deletions composer.json
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.
13 changes: 13 additions & 0 deletions src/AbstractPDFGenerator.php
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;
}
}
27 changes: 27 additions & 0 deletions src/Implementation/RemotePDF.php
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());
}
}
21 changes: 21 additions & 0 deletions src/Implementation/WKHTMLToPDF.php
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);
}
}
11 changes: 11 additions & 0 deletions src/PDFGenerator.php
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);
}
}
8 changes: 8 additions & 0 deletions src/PDFGeneratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace PDFGenerator;

interface PDFGeneratorInterface
{
public function fromURL($url);
}

0 comments on commit 5292aea

Please sign in to comment.