Tools to Capture and Convert the Web

Convert URL's and HTML to DOCX

PHP API

Adding the ability to convert HTML or web pages into Word documents to your app has never been easier with GrabzIt's PHP API. However before you start remember that after calling the URLToDOCX, HTMLToDOCX or FileToDOCX methods. The Save or SaveTo method must be called to actually create the DOCX.

Basic Options

Capturing web pages as DOCX converts the entire web page into a Word document that can consist of many pages. In the below examples PHP converts HTML to DOCX and a web page into a Word document, with only one required parameter.

$grabzIt->URLToDOCX("https://www.tesla.com");
//Then call the Save or SaveTo method
$grabzIt->HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>");
//Then call the Save or SaveTo method
$grabzIt->FileToDOCX("example.html");
//Then call the Save or SaveTo method

Custom Identifier

You can pass a custom identifier to the DOCX methods as shown below, this value is then returned to your GrabzIt PHP handler. For instance this custom identifier could be a database identifier, allowing a DOCX document to be associated with a particular database record.

$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setCustomId(123456);

$grabzIt->URLToDOCX("https://www.tesla.com", $options);
//Then call the Save method
$grabzIt->Save("http://www.example.com/handler.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setCustomId(123456);

$grabzIt->HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>", $options);
//Then call the Save method
$grabzIt->Save("http://www.example.com/handler.php");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setCustomId(123456);

$grabzIt->FileToDOCX("example.html", $options);
//Then call the Save method
$grabzIt->Save("http://www.example.com/handler.php");

Headers and Footers

While GrabzIt doesn't support the traditional Word Template. When adding headers or footers to a Word document you can request that you want to apply a template to the DOCX being generated. This template must be saved in advance and will specify the contents of the header and footer along with any special variables. In the example code below the user is using a template they created called "my template".

$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setTemplateId("my template");

$grabzIt->URLToDOCX("https://www.tesla.com", $options);
//Then call the Save or SaveTo method
$grabzIt->SaveTo("result.docx");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setTemplateId("my template");

$grabzIt->HTMLToDOCX("<html><body><h1>Hello World!</h1></body></html>", $options);
//Then call the Save or SaveTo method
$grabzIt->SaveTo("result.docx");
$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setTemplateId("my template");

$grabzIt->FileToDOCX("example.html", $options);
//Then call the Save or SaveTo method
$grabzIt->SaveTo("result.docx");

Convert HTML element to DOCX

If you want to just convert an HTML element such as a div or span directly into a Word document you can with GrabzIt's PHP library. You must pass the CSS selector of the HTML element you wish to convert to the setTargetElement method of GrabzItDOCXOptions class.

...
<span id="Article">
<p>This is the content I am interested in.</p>
<img src="myimage.jpg">
</span>
...

In this example, we wish to capture all the content in the span which has the id of Article. By passing this to GrabzIt as, shown below.

$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");

$options = new \GrabzIt\GrabzItDOCXOptions();
$options->setTargetElement("#Article");

$grabzIt->URLToDOCX("http://www.bbc.co.uk/news", $options);
//Then call the Save or SaveTo method
$grabzIt->SaveTo("result.docx");

It doesn’t matter if you are converting a URL to Word as shown in the example or HTML to Word. Both target HTML elements in exactly the same way.