curl -X POST https://api.html2pdf.app/v1/generate \
-H 'Content-Type: application/json' \
-d '{
"html": "http://www.example.com",
"apiKey": "your-api-key",
"landscape": true,
"format": "A4"
}'
<?php
$data = [
'html' => 'https://example.com',
'apiKey' => 'your-api-key',
];
$dataString = json_encode($data);
$ch = curl_init('https://api.html2pdf.app/v1/generate');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
]);
$response = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err) {
echo 'Error #:' . $err;
} else {
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="your-file-name.pdf"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
echo $response;
}
import axios from 'axios'; // install axios package "npm i axios"
import fs from 'fs';
// 1. This example saves generated pdf document to the file system
axios.post('https://api.html2pdf.app/v1/generate', {
html: '<h1>Hello world!</h1>',
apiKey: '{your-api-key}',
}, {responseType: 'arraybuffer'}).then((response) => {
fs.writeFileSync('./document.pdf', response.data);
}).catch((err) => {
console.log(err.message);
});
// 2. This example outputs generated pdf document content
axios.post('https://api.html2pdf.app/v1/generate', {
html: '<h1>Hello world!</h1>',
apiKey: '{your-api-key}',
}).then((response) => {
console.log(response.data);
}).catch((err) => {
console.log(err.message);
});
import requests
url = "https://en.wikipedia.org"
apiKey = "your-api-key"
linkRequests = "https://api.html2pdf.app/v1/generate?html={0}&apiKey={1}".format(url, apiKey)
result = requests.get(linkRequests).content
with open("document.pdf", "wb") as handler:
handler.write(result)
require 'net/http'
require 'uri'
require 'json'
uri = URI('https://api.html2pdf.app/v1/generate')
header = {'Content-Type': 'application/json'}
body = {
html: '<h1>Hello!</h1>',
apiKey: 'your-api-key'
}
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri, header)
request.body = body.to_json
response = http.request(request)
puts response.body
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
var message = "{\"html\": \"https://example.com\", \"apiKey\": \"d3a0264f708646450b79...\"}";
var request = HttpRequest.newBuilder().
uri(URI.create("https://api.html2pdf.app/v1/generate")).
POST(HttpRequest.BodyPublishers.ofString(message)).
header("Content-type", "application/json").
build();
var client = HttpClient.newHttpClient();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
}
}
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
)
type html2pdfRequest struct {
HTML string `json:"html"`
ApiKey string `json:"apiKey"`
CallbackURL string `json:"callBackUrl,omitempty"`
State string `json:"state,omitempty"`
Landscape bool `json:"landscape,omitempty"`
Format string `json:"format,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
MarginTop int `json:"marginTop,omitempty"`
MarginRight int `json:"marginRight,omitempty"`
MarginBottom int `json:"marginBottom,omitempty"`
MarginLeft int `json:"marginLeft,omitempty"`
Filename string `json:"filename,omitempty"`
WaitFor int `json:"waitFor,omitempty"`
Media string `json:"media,omitempty"`
Scale float64 `json:"scale,omitempty"`
HeaderTemplate string `json:"headerTemplate,omitempty"`
FooterTemplate string `json:"footerTemplate,omitempty"`
}
func main() {
req := html2pdfRequest{
HTML: "<h1>Hello world!</h1>",
ApiKey: "<your-api-key-here>",
MarginBottom: 40,
Landscape: true,
}
reqJson, _ := json.Marshal(&req)
reqBuf := bytes.NewReader(reqJson)
resp, err := http.Post("https://api.html2pdf.app/v1/generate", "application/json", reqBuf)
if err != nil {
return err
}
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
}