HTML to PDF API

High quality PDFs from web pages — Using your favourite framework or language

Try it now

Get started — Code samples

+
dev@localhost: ~ (bash)
$> curl -i https://api.sejda.com/v2/html-pdf\
  --fail --silent --show-error \
  --header "Content-Type: application/json" \
  --header "Authorization: Token: api_Y0URAP1K3YH3R3" \
  --data '{"url": "https://airtable.com", "viewportWidth":1200 }' > out.pdf
// npm install request
const request = require('request');
const fs = require('fs');

var opts = {
  uri: 'https://api.sejda.com/v2/html-pdf',
  headers: {
    'Authorization' : 'Token: ' + apiKey,
  },
  json: {
    'url': 'https://airtable.com',
    'viewportWidth': 1200
  }
};

request.post(opts)
  .on('error', function(err){
    return console.error(err);
  })
  .on('response', function(response) {
    if (response.statusCode === 200) {
      response.pipe(fs.createWriteStream('/tmp/out.pdf'))
        .on('finish', function () {
          console.log('PDF saved to disk');
        });
    } else {
      return console.error('Got code: ' + response.statusCode);
    }
  });
import requests

url = 'https://api.sejda.com/v2/html-pdf'
r = requests.post(url, json = {
    'url': 'https://airtable.com',
    'viewportWidth': 1200
  }, headers = {
    'Authorization': 'Token: {}'.format(apiKey)
  })
open('/tmp/out.pdf', 'wb').write(r.content)
<script src="//www.sejda.com/js/sejda-js-api.min.js"></script>
<script>
  document.getElementById('downloadPdfBtn')
    .addEventListener('click', function(e){
      SejdaJsApi.htmlToPdf({
        filename: 'out.pdf',
        /* leave blank for one long page */
        pageSize: 'a4',
        publishableKey: 'api_public_y0urap1k3yh3r3',
        htmlCode: document.querySelector('html').innerHTML,
        /* url: window.location.href */
        always: function(){
          // PDF download should have started
        }
      });
    })
</script>
/* Don't forget to configure your API Allowed domains, on your account page. */
<!-- Maven dependency -->
<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
	<version>4.5.8</version>
</dependency>

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;

CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost request = new HttpPost("https://api.sejda.com/v2/html-pdf");
request.setHeader(HttpHeaders.AUTHORIZATION, "Token: " + apiKey);
request.setEntity(new StringEntity(
    "{\"url\": \"https://airtable.com\", \"viewportWidth\":1200 }",
    ContentType.APPLICATION_JSON));

HttpResponse response = httpClient.execute(request);
if (response.getStatusLine().getStatusCode() == 200) {

    try (InputStream in = response.getEntity().getContent();
         OutputStream out = new FileOutputStream(new File("/tmp/out.pdf"))) {
        byte[] buffer = new byte[8 * 1024];
        int bytesRead;
        while ((bytesRead = in.read(buffer)) != -1) {
            out.write(buffer, 0, bytesRead);
        }
    }
}
$url = "https://api.sejda.com/v2/html-pdf";
$content = json_encode(array('url' => 'https://airtable.com'));

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl, CURLOPT_HTTPHEADER, array(
  "Content-type: application/json",
  "Authorization: Token: " . $apiKey));

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

$response = curl_exec($curl);

$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($status == 200) {
  $fp = fopen("out.pdf", "w");
  fwrite($fp, $response);
  fclose($fp);
  print("PDF saved to disk");
} else {
  print("Error: failed with status $status, response $response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
using System.Net.Http;
using Newtonsoft.Json.Linq;

var baseUrl = "https://api.sejda.com/v2/html-pdf";

using (var client = new HttpClient())
{
  client.DefaultRequestHeaders.TryAddWithoutValidation(
      "Authorization", "Token: " + apiKey
  );

  var json = new JObject();
  json.Add("url", "https://airtable.com");
  json.Add("viewportWidth", 1200);
  //json.Add("htmlCode", File.ReadAllText(@"c:\doc.html", Encoding.UTF8));

  var content = new StringContent(json.ToString(), Encoding.UTF8, "application/json");

  using (var res = await client.PostAsync(baseUrl, content))
  {
    var statusCode = (int)res.StatusCode;

    if (statusCode == 200)
    {
      var httpStream = await res.Content.ReadAsStreamAsync();
      var outputFilePath = Path.GetTempFileName();
      using (var fileStream = File.Create(outputFilePath))
      using (var reader = new StreamReader(httpStream))
      {
        httpStream.CopyTo(fileStream);
        fileStream.Flush();
      }
      // outputFilePath contains the PDF output
    }
    else
    {
      // retry, then handle error
      throw new Exception("Unexpected response code: " + statusCode);
    }
  }
}
HTML to PDF API Docs

Renders just like a browser

  1. Highly accurate, just like a browser
  2. CSS3, web fonts, javascript, SVG, flexbox, webGL, canvas — all supported

Simple to use
 

  1. REST API — works with your favourite language or framework
  2. Client side javascript integration (CORS)
  3. Hosted by us, on our infrastructure

Batteries included
 

  1. One long page & standard page size rendering
  2. Responsive viewports
  3. Lazy loading
  4. Rendering delay
  5. Print media
  6. Cookie notices

Pricing

Let us help with the PDF documents.
Your team can focus on your product's unique features.

Documents
Requests/hour
Concurrency
Monthly
price
300
4
$24
600
5
$48
1200
6
$96
2400
12
$192
4800
24
$384
9600
48
$768
Need a different plan? Please contact us

Require a Self-Hosted solution?

Self-managed option available. On premise HTML to PDF API

  1. Custom privacy and compliance requirements
  2. Convert documents on your servers
  3. No request per hour limits
  4. Docker based deployment
  5. Pricing starts at $384/mo.
Learn more

FAQ

Do you have any questions ?

What happens when I reach the plan limits?

If you reach your plan's requests per hour or concurrency limits we'll reject the request with a special HTTP response code (429).
We will not upgrade you automatically to the next plan.

What do you mean by Concurrency?

The maximum number of simultaneous requests that can be made in parallel, at the same time.

What do you mean by Requests per Hour?

The maximum number of requests that can be made in an hour.

What do you mean by ∞ documents?

We don't meter or limit the total number of documents converted.

How large can be the generated PDF documents?

Generated PDFs should be smaller than 50Mb.

How can I cancel my subscription?

To cancel a recurring subscription just click 'Stop auto-renewal' from your account page. You can also email hi@sejda.com.

Will my subscription be automatically renewed?

All plans are recurring subscriptions and will continue until you cancel.

Subscriptions auto-renew at the end of each term and you will be charged for the subsequent term.

No surprise charges

We won't automatically upgrade you to a higher plan when you reach your current plan's limits.

Do you have an SLA and status page?

Yes, here are our Service Level Agreement and Status page.

Is there a Self-hosted version?

Yes, a Self-hosted version is available. Pricing starts at $384/mo.

More questions? Contact us