POST/api/v1/convert/text-to-pdf

Text to PDF

Convert plain text into a clean, formatted PDF document. Control font size, alignment, line spacing, margins, and page layout.

Parameters

NameTypeRequiredDefaultDescription
textstringYes-Plain text content to convert to PDF.
font_sizeintNo12Font size in points. Range: 8-72.
page_sizestringNoA4Page size: A4, LETTER, LEGAL, TABLOID, A3, A5, etc.
orientationstringNoportraitPage orientation: portrait or landscape.
margin_topintNo72ptsTop margin in points.
margin_bottomintNo72ptsBottom margin in points.
margin_leftintNo72ptsLeft margin in points.
margin_rightintNo72ptsRight margin in points.
alignmentstringNoleftText alignment: left, center, right, or justify.
line_spacingfloatNo1.2Line spacing multiplier. Range: 0.5-3.0.

Code Examples

cURL
curl -X POST "https://app.alternapdf.com/api/v1/convert/text-to-pdf" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Meeting Notes\n\n1. Q3 targets exceeded by 15%\n2. New product launch scheduled for October",
    "font_size": 12,
    "page_size": "LETTER",
    "alignment": "left",
    "line_spacing": 1.5
  }' \
  --output notes.pdf
Python
import requests

response = requests.post(
    "https://app.alternapdf.com/api/v1/convert/text-to-pdf",
    headers={"X-API-Key": "YOUR_API_KEY"},
    json={
        "text": "Meeting Notes\n\n1. Q3 targets exceeded by 15%\n2. New product launch in October",
        "font_size": 12,
        "page_size": "LETTER",
        "alignment": "left",
        "line_spacing": 1.5
    }
)

with open("notes.pdf", "wb") as f:
    f.write(response.content)
JavaScript
const response = await fetch("https://app.alternapdf.com/api/v1/convert/text-to-pdf", {
  method: "POST",
  headers: {
    "X-API-Key": "YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    text: "Meeting Notes\n\n1. Q3 targets exceeded\n2. New launch in October",
    font_size: 12,
    page_size: "LETTER",
  }),
});

fs.writeFileSync("notes.pdf", Buffer.from(await response.arrayBuffer()));

Response

Returns the PDF as a binary download with Content-Type: application/pdf.

HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Disposition: attachment; filename="converted.pdf"
X-Credits-Used: 1
X-Credits-Remaining: 4999

<binary PDF data>