This is a PHP package for using DocRaptor API to convert HTML to PDF and XLSX.
composer require docraptor/docraptorIf you do not wish to use Composer, you can download the latest
release, unzip in your project and require autoload.php.
require_once('/path/to/docraptor-php/autoload.php');See examples for runnable examples with file output, error handling, etc.
$configuration = DocRaptor\Configuration::getDefaultConfiguration();
$configuration->setUsername("YOUR_API_KEY_HERE"); // this key works for test documents
// $configuration->setDebug(true);
$docraptor = new DocRaptor\DocApi();
$doc = new DocRaptor\Doc();
$doc->setTest(true); // test documents are free but watermarked
$doc->setDocumentContent("<html><body>Hello World</body></html>"); // supply content directly
// $doc->setDocumentUrl("http://docraptor.com/examples/invoice.html"); // or use a url
$doc->setName("docraptor-php.pdf"); // help you find a document later
$doc->setDocumentType("pdf"); // pdf or xls or xlsx
// $doc->setJavascript(true); // enable JavaScript processing
// $prince_options = new DocRaptor\PrinceOptions(); // pdf-specific options
// $doc->setPrinceOptions($prince_options);
// $prince_options->setMedia("screen"); // use screen styles instead of print styles
// $prince_options->setBaseurl("http://hello.com"); // pretend URL when using document_content
$create_response = $docraptor->createDoc($doc);Docs created like this are limited to 60 seconds to render, check out the async example which allows 10 minutes.
We have guides for doing some of the common things:
- Headers and Footers including page skipping
- CSS Media Selector to make the page look exactly as it does in your browser
- Protect content with HTTP authentication or proxies so only DocRaptor can access them
DocRaptor has a lot more styling and implementation options.
Stuck? We're experts at using DocRaptor so please email our support team if you run into trouble.
The majority of the code in this repo is generated using swagger-codegen on docraptor.yaml. You can modify this file and regenerate the client using script/generate_language php.
- Pull latest master
- Merge feature branch(es) into master
script/test- Increment version in code:
swagger-config.jsonlib/Configuration.php(2 places)
- Update CHANGELOG.md
- Commit "Release version vX.Y.Z"
- Push to GitHub
- Tag version:
git tag 'vX.Y.Z' && git push --tags(GitHub webhook will tell packagist and release a new version) - Verify update on https://packagist.org/packages/docraptor/docraptor
- Refresh documentation on docraptor.com
This library follows Semantic Versioning 2.0.0.