Generate professional contract PDFs from HTML templates. Consistent formatting, custom fonts, and page numbering on every request, at any scale.
Start freeKeep your contract logic in HTML. It's versioned, testable, and editable by anyone. Render to a string, POST to the API, stream the bytes to the client or store in S3.
<?php
use HtmlToPdfApi\HtmlToPdf;
class ContractService
{
public function generate(Contract $contract): string
{
$html = view('contracts.template', ['contract' => $contract])->render();
$sdk = new HtmlToPdf(['api_key' => config('services.htmltopdfapi.key')]);
return $sdk->html($html)
->paperSize('a4')
->orientation('portrait')
->margins(top: 40, right: 32, bottom: 40, left: 32)
->footer('<div style="font-size:8px;color:#999;text-align:center;padding:4px 0">
Page <span class="pageNumber"></span> of <span class="totalPages"></span>
· Contract #' . $contract->reference . '
</div>')
->generate()
->content();
}
}200 pages/day on the free tier. No credit card required.
Get your free API key