Installation

FeoPDF is a REST API that can be used with any programming language. Simply make HTTP requests to our API endpoints using your preferred HTTP client library.

Prerequisites

Before you begin, you'll need an API key. You can get one by creating an account.

Making Your First Request

Here's how to generate a PDF using our REST API in different programming languages:

curl -X POST https://feopdf.com/api/pdf \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Hello World</h1>",
    "options": {
      "format": "A4",
      "printBackground": true
    }
  }' \
  --output invoice.pdf
const axios = require('axios');
const fs = require('fs');

async function generatePDF() {
  try {
    const response = await axios.post(
      'https://feopdf.com/api/pdf',
      {
        html: '<h1>Hello World</h1>',
        options: {
          format: 'A4',
          printBackground: true
        }
      },
      {
        headers: {
          'Authorization': 'Bearer YOUR_API_KEY',
          'Content-Type': 'application/json'
        },
        responseType: 'arraybuffer'
      }
    );
    
    fs.writeFileSync('invoice.pdf', response.data);
    console.log('PDF generated successfully!');
  } catch (error) {
    console.error('Error:', error.response?.data || error.message);
  }
}

generatePDF();
<?php

$ch = curl_init('https://feopdf.com/api/pdf');

$data = [
    'html' => '<h1>Hello World</h1>',
    'options' => [
        'format' => 'A4',
        'printBackground' => true
    ]
];

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode($data),
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer YOUR_API_KEY',
        'Content-Type: application/json'
    ]
]);

$pdf = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode === 200) {
    file_put_contents('invoice.pdf', $pdf);
    echo "PDF generated successfully!";
} else {
    echo "Error: HTTP $httpCode";
}
import requests

url = 'https://feopdf.com/api/pdf'
headers = {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
}
data = {
    'html': '<h1>Hello World</h1>',
    'options': {
        'format': 'A4',
        'printBackground': True
    }
}

response = requests.post(url, json=data, headers=headers)

if response.status_code == 200:
    with open('invoice.pdf', 'wb') as f:
        f.write(response.content)
    print('PDF generated successfully!')
else:
    print(f'Error: {response.status_code}')
    print(response.json())
require 'net/http'
require 'json'
require 'uri'

uri = URI('https://feopdf.com/api/pdf')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == 'https'

request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer YOUR_API_KEY'
request['Content-Type'] = 'application/json'
request.body = {
  html: '<h1>Hello World</h1>',
  options: {
    format: 'A4',
    printBackground: true
  }
}.to_json

response = http.request(request)

if response.code == '200'
  File.write('invoice.pdf', response.body)
  puts 'PDF generated successfully!'
else
  puts "Error: #{response.code}"
end
package main

import (
    "bytes"
    "encoding/json"
    "io/ioutil"
    "net/http"
)

func main() {
    url := "https://feopdf.com/api/pdf"
    
    data := map[string]interface{}{
        "html": "<h1>Hello World</h1>",
        "options": map[string]interface{}{
            "format":          "A4",
            "printBackground": true,
        },
    }
    
    jsonData, _ := json.Marshal(data)
    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
    req.Header.Set("Authorization", "Bearer YOUR_API_KEY")
    req.Header.Set("Content-Type", "application/json")
    
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    
    if resp.StatusCode == 200 {
        body, _ := ioutil.ReadAll(resp.Body)
        ioutil.WriteFile("invoice.pdf", body, 0644)
        println("PDF generated successfully!")
    } else {
        println("Error:", resp.StatusCode)
    }
}
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import com.google.gson.Gson;
import java.util.Map;
import java.util.HashMap;

public class FeoPDF {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();
        
        Map<String, Object> options = new HashMap<>();
        options.put("format", "A4");
        options.put("printBackground", true);
        
        Map<String, Object> data = new HashMap<>();
        data.put("html", "<h1>Hello World</h1>");
        data.put("options", options);
        
        String json = new Gson().toJson(data);
        
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://feopdf.com/api/pdf"))
            .header("Authorization", "Bearer YOUR_API_KEY")
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(json))
            .build();
        
        HttpResponse<byte[]> response = client.send(request, 
            HttpResponse.BodyHandlers.ofByteArray());
        
        if (response.statusCode() == 200) {
            Files.write(Paths.get("invoice.pdf"), response.body());
            System.out.println("PDF generated successfully!");
        } else {
            System.out.println("Error: " + response.statusCode());
        }
    }
}
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.IO;

class Program
{
    static async Task Main()
    {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("Authorization", "Bearer YOUR_API_KEY");
        
        var data = new
        {
            html = "<h1>Hello World</h1>",
            options = new
            {
                format = "A4",
                printBackground = true
            }
        };
        
        var json = JsonSerializer.Serialize(data);
        var content = new StringContent(json, Encoding.UTF8, "application/json");
        
        var response = await client.PostAsync("https://feopdf.com/api/pdf", content);
        
        if (response.IsSuccessStatusCode)
        {
            var pdfBytes = await response.Content.ReadAsByteArrayAsync();
            await File.WriteAllBytesAsync("invoice.pdf", pdfBytes);
            Console.WriteLine("PDF generated successfully!");
        }
        else
        {
            Console.WriteLine($"Error: {response.StatusCode}");
        }
    }
}

Response Handling

The API returns the PDF as binary data with Content-Type: application/pdf. Simply save the response body to a file. If an error occurs, the API returns a JSON object with error details.

For more details on request parameters and error handling, see the PDF Generation and Errors documentation.