Product updates, tips & tricks

Category - Tutorials

The Pdfcrowd HTML to PDF API makes it easy to programmatically create fillable PDF forms from standard HTML forms. The API supports most of the HTML form features and, together with support for digital signatures (see Create Digital Signature in PDF), provides an easy way to create PDF forms.

This feature is available starting with Pdfcrowd API client libraries version 5.6.

Simple Example

Add an HTML form field, for example a text input:

<p>Enter name: <input type="text"></p>

Enable generation of fillable PDF forms with the setEnablePdfForms() method:

client.setEnablePdfForms(true)

The resulting PDF will display an interactive input text field.

A digital signature is a piece of information placed in a PDF document that makes it possible to verify the authenticity of the document. The Pdfcrowd API allows you to programmatically create PDFs containing a digital signature field. Such PDFs can be digitally signed in, for example, Adobe Reader or Preview.

This feature is available starting with Pdfcrowd API client libraries version 5.0.

Quick Start

To add a signature field to a document, set the pdfcrowd-signature class on a DIV element and specify its dimensions.

<div class="pdfcrowd-signature" 
     style="width: 2in; height: 1in; border: 1pt solid black;">
</div>

Our HTML to PDF API will transform this element to a signature field in the resulting PDF.

Postman is a platform for using APIs. You can use it to interact with the Pdfcrowd API and convert between PDF, HTML and various image formats.

Let's first configure the API endpoint and the credentials. This configuration is common for all conversion types.

API endpoint - Select the HTTP POST method and enter the API endpoint: https://api.pdfcrowd.com/convert/

Postman - Pdfcrowd API endpoint

API credentials. The authorization method is Basic Auth. You can use either the demo credentials or your personal API credentials.

In this tutorial you will learn how to add header and footer to PDF created by Pdfcrowd API. We will use PHP for illustrative purposes, but the code would be essentially the same in all languages the API supports.

Step-by-Step Example

Let's start with instantiating the Pdfcrowd client and setting the page format to Letter:

$client = new \Pdfcrowd\HtmlToPdfClient($user_name, $api_key);
$client->setPageSize('Letter');

The next step is to design our HTML footer and header. We can use special CSS classes that will be expanded as follows:

  • pdfcrowd-page-count - the total page count of printed pages
  • pdfcrowd-page-number - the current page number
  • pdfcrowd-source-url - the source URL of the main document

Overview

The Pdfcrowd API v2 is the new generation of our API. It is not 100% backward compatible but the changes are mostly syntactic and the migration from API v1 should be straightforward.

If you want to switch your current API v1 plan to API v2, please follow these steps:

  1. Activate the free API v2 trial in your account page.
  2. Follow the instructions below and migrate your API v1 implementation to API v2.
  3. If the API v2 works to your satisfaction, choose from our API v2 plans.
  4. If you no longer need the API v1 implementation, you can cancel the API v1 plan.

In this tutorial you will learn how to easily convert web pages and raw HTML documents to PDF in your PHP applications. We will use the Pdfcrowd API for PDF generation. The API offers these benefits:

  • The API is easy to use and fully supports HTML/CSS3/JavaScript.
  • The integration takes only a few minutes.
  • No third-party libraries are needed, just a single tiny PHP file.
  • It does not consume CPU/memory on your computer, PDFs are created on the Pdfcrowd servers.

Introduction

Let's start with an example:

<?php
require 'pdfcrowd.php';

$client = new \Pdfcrowd\HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d");
$pdf = $client->convertUrl('https://en.wikipedia.org/');
?>