Sfoglia il codice sorgente

Body styles can now be used to set backgroud color on requested page

Jonny Wenmoth 9 anni fa
parent
commit
8dede48c74
2 ha cambiato i file con 35 aggiunte e 11 eliminazioni
  1. 23 0
      _version_4/3-usage.md
  2. 12 11
      _version_4/4-custom-scripts.md

+ 23 - 0
_version_4/3-usage.md

@@ -17,6 +17,7 @@ This page contains some common examples of how to use the PHP PhantomJS library.
 * [Screen Captures](#screen-captures)
 * [Output To PDF](#output-to-pdf)
 * [Set Viewport Size](#set-viewport-size)
+* [Set Background Color](#set-background-color)
 * [Custom Timeout](#custom-timeout)
 * [Delay Page Render](#delay-page-render)
 * [PhantomJS Options](#phantomjs-options)
@@ -313,6 +314,28 @@ You can easily set the viewport size for a request:
     
 {% endhighlight %}
 
+Set Background Color
+--------------------
+
+You can easily force the background color of the requested page by setting  a `backgroundColor` body style:
+
+{% highlight php %}
+
+    <?php
+
+    ...
+    
+    $request  = $client->getMessageFactory()->createRequest('http://jonnyw.me');
+    $request->setBodyStyles(array(
+        'backgroundColor' => '#ff0000'
+    ));
+    
+    ...
+    
+{% endhighlight %}
+
+The `setBackgroudColor` method can be used to set any valid CSS styles on the body tag; it is not limited to just background color.
+
 Custom Timeout
 --------------
 

+ 12 - 11
_version_4/4-custom-scripts.md

@@ -35,19 +35,20 @@ The following outlines the partial blocks that are compiled into a PHP PhantomJS
 
 | Block Name                                   | Description                                                                                      |
 | -------------------------------------------- | ------------------------------------------------------------------------------------------------ |
-| [global_variables.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/global_variables.partial)          | Allows any javascript variables to be injected at the top of the script.                         |
-| [page_clip_rect.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_clip_rect.partial)            | If the request is a screen capture, this will define the page clipping rectangle.                |
-| [page_custom_headers.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_custom_headers.partial)       | Set any custom headers on the page object.                                                       |
+| [global_variables.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/global_variables.partial)          | Allows any javascript variables to be injected at the top of the script.                      |
+| [page_clip_rect.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_clip_rect.partial)            | If the request is a screen capture, this will define the page clipping rectangle.               |
+| [page_custom_headers.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_custom_headers.partial)       | Set any custom headers on the page object.                                                 |
 | [page_on_error.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_on_error.partial)             | Defines the code that is executed on page error.                                                 |
-| [page_on_resource_received.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_on_resource_received.partial) | Defines the code that is executed on resource receive.                                           |
-| [page_on_resource_timeout.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_on_resource_timeout.partial)  | Defines the code that is executed on resource timeout.                                           |
-| [page_open.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_open.partial)                 | Defines the code that is executed on page open.                                                  |
-| [page_paper_size.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_paper_size.partial)           | If the request is PDF output, this will set up the paper size.                                   |
+| [page_on_resource_received.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_on_resource_received.partial) | Defines the code that is executed on resource receive.                               |
+| [page_on_resource_timeout.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_on_resource_timeout.partial)  | Defines the code that is executed on resource timeout.                                |
+| [page_open.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_open.partial)                 | Defines the code that is executed on page open.                                                      |
+| [page_paper_size.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_paper_size.partial)           | If the request is PDF output, this will set up the paper size.                                 |
 | [page_settings.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_settings.partial)             | Defines any page settings most notably the resource timeout value.                               |
-| [page_viewport_size.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_viewport_size.partial)        | Set up the viewport size if defined in the request.                                              |
-| [phantom_on_error.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/phantom_on_error.partial)          | Defines the code that is execute on PhantomJS error.                                             |
-| [procedure_capture.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/procedure_capture.partial)         | Defines the code that is executed if the request is a capture request.                           |
-| [procedure_default.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/procedure_default.partial)         | Defines the code that is executed for a default request.                                         |
+| [page_viewport_size.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_viewport_size.partial)        | Set up the viewport size if defined in the request.                                         |
+| [page_body_styles.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/page_body_styles.partial)        | Set CSS styles on the body tag of the requested page.                                           |
+| [phantom_on_error.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/phantom_on_error.partial)          | Defines the code that is execute on PhantomJS error.                                          |
+| [procedure_capture.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/procedure_capture.partial)         | Defines the code that is executed if the request is a capture request.                       |
+| [procedure_default.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/procedure_default.partial)         | Defines the code that is executed for a default request.                                     |
 | [procedure_pdf.partial](https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/procedure_pdf.partial)             | Defines the code that is executed if the request is a PDF request.                               |