Skip to content

Commit 90395b0

Browse files
committed
Merge pull request #9 from Padam87/docs
Improved documentation
2 parents a427fd5 + b51d26c commit 90395b0

5 files changed

Lines changed: 102 additions & 29 deletions

File tree

README.md

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
A bundle to rasterize web pages with PhantomJS for Symfony2
1515

16-
## 1. Example ##
17-
1816
```php
1917
$response = new Response(
2018
$this->get('padam87_rasterize.rasterizer')->rasterize(
@@ -27,35 +25,13 @@ $response = new Response(
2725
);
2826
```
2927

30-
## 2. Installation ##
31-
32-
### 2.1. Composer ###
33-
34-
"padam87/rasterize-bundle": "~1.0",
28+
[Installation](Resources/docs/configuration_reference.md)
3529

36-
### 2.2. AppKernel ###
30+
[Configuration reference](Resources/docs/configuration_reference.md)
3731

38-
$bundles = array(
39-
...
40-
new Padam87\RasterizeBundle\Padam87RasterizeBundle(),
41-
);
32+
**How to...**
33+
- [pass arguments to the javascript file?](Resources/docs/how_to_pass_arguments.md)
34+
- [ignore SSL errors?](Resources/docs/how_to_ignore_ssl_errors.md)
4235

43-
### 2.3 Install assets ###
4436

45-
php app/console assets:install
4637

47-
## 3. Configuration reference ##
48-
49-
*NOTE: No configuration necessary by default*
50-
51-
```YAML
52-
padam87_rasterize:
53-
web_dir: /../web # Temp dir location related to %kernel.root_dir%.
54-
temp_dir: /bundles/padam87rasterize/temp # Temp dir location related to web dir. Must be in a location accessible by the web server.
55-
phantomjs:
56-
callable: phantomjs
57-
options: [] # https://github.com/ariya/phantomjs/wiki/API-Reference#wiki-command-line-options
58-
script: /bundles/padam87rasterize/js/rasterize.js # Relative to web dir
59-
arguments: # You can define your own custom arguments. Will be added by default to every process.
60-
format: pdf # Default, will always be added, even if you remove it from here.
61-
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Configuration reference ##
2+
3+
*NOTE: No configuration necessary by default*
4+
5+
```YAML
6+
padam87_rasterize:
7+
web_dir: /../web # Temp dir location related to %kernel.root_dir%.
8+
temp_dir: /bundles/padam87rasterize/temp # Temp dir location related to web dir. Must be in a location accessible by the web server.
9+
phantomjs:
10+
callable: phantomjs
11+
options: [] # https://github.com/ariya/phantomjs/wiki/API-Reference#wiki-command-line-options
12+
script: /bundles/padam87rasterize/js/rasterize.js # Relative to web dir
13+
arguments: # You can define your own custom arguments. Will be added by default to every process.
14+
format: pdf # Default, will always be added, even if you remove it from here.
15+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# How to ignore SSL errors
2+
3+
Phantomjs, by default does not play nice with Self-signed certificates.
4+
If you are working with one, you need to ignore ssl errors.
5+
6+
```yaml
7+
padam87_rasterize:
8+
phantomjs:
9+
options:
10+
--ssl-protocol: tlsv1
11+
--ignore-ssl-errors: true
12+
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# How to pass arguments to the javascript file
2+
3+
In this example, we will use arguments to programmatically set the orientation of the PDF.
4+
5+
First, the configuration should be changed
6+
7+
```yaml
8+
padam87_rasterize:
9+
script: /js/my-rasterize.js
10+
arguments:
11+
format: pdf
12+
orientation: portrait
13+
```
14+
15+
Note that the orientation argument has been added, by default it will be set as `portrait`.
16+
17+
A custom javascript is also necessary, to handle the newly received argument.
18+
19+
```js
20+
var page = require('webpage').create(),
21+
system = require('system'),
22+
address, output, format, orientation;
23+
24+
address = system.args[1];
25+
output = system.args[2];
26+
format = system.args[3];
27+
orientation = system.args[4];
28+
29+
page.viewportSize = { width: 1000, height: 3000 };
30+
page.paperSize = { format: 'A4', orientation: orientation, border: '1cm' };
31+
32+
page.open(address, function (status) {
33+
if (status !== 'success') {
34+
console.log('Unable to load the address!');
35+
phantom.exit(1);
36+
} else {
37+
window.setTimeout(function () {
38+
page.render(output, { format: format });
39+
phantom.exit(0);
40+
}, 200);
41+
}
42+
});
43+
```
44+
45+
To change the orientation to `landscape`, you need to add one more parameter to the rasterizer call.
46+
47+
```php
48+
$this->get('padam87_rasterize.rasterizer')->rasterize(
49+
$this->renderView('Bundle:Folder:template.pdf.twig')
50+
[
51+
'orientation' => 'landscape'
52+
]
53+
);
54+
```

Resources/docs/install.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## Installation ##
2+
3+
### Composer ###
4+
5+
"padam87/rasterize-bundle": "~1.0",
6+
7+
### AppKernel ###
8+
9+
$bundles = array(
10+
...
11+
new Padam87\RasterizeBundle\Padam87RasterizeBundle(),
12+
);
13+
14+
### Install assets ###
15+
16+
php app/console assets:install

0 commit comments

Comments
 (0)