PDF Generation via API

How to generate PDFs using the TTA HTTP API.

Generate PDFs via API

const axios = require('axios');

const options = {
  method: 'POST',
  url: 'https://text-to-anything.p.rapidapi.com/generatePDF',
  headers: {
    'x-rapidapi-key': '{Your-RapidAPI-Key}',
    'Content-Type': 'application/json'
  },
  data: {
    html: '<h1>Hello world!</h1>',
    format: 'A4',
    landscape: false,
    margin: 10,
    marginRight: 5,
    marginLeft: 5
  }
};

const response = await axios.request(options);
console.log(response.data);

Inside of the body you have the following options:

OptionTypeDescription
htmlstring The HTML content for the body.
headerstring The HTML content for the header.
footerstring The HTML content for the footer.
formatstring Can be one of the following: A1, A2, A3, A4, A5, A6, Letter, Legal, Tabloid or Ledger.
landscapestring Should the PDF be in landscape mode? (default: false)
marginnumber The margin of the PDF in pixels. (default: 5)
marginLeft | marginTop | marginRight | marginBottomnumber A specific margin of the PDF in pixels. (default: 5)

Output

The API will respond with the file.