POST
/api/v1/convert/text-to-pdfText to PDF
Convert plain text into a clean, formatted PDF document. Control font size, alignment, line spacing, margins, and page layout.
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| text | string | Yes | - | Plain text content to convert to PDF. |
| font_size | int | No | 12 | Font size in points. Range: 8-72. |
| page_size | string | No | A4 | Page size: A4, LETTER, LEGAL, TABLOID, A3, A5, etc. |
| orientation | string | No | portrait | Page orientation: portrait or landscape. |
| margin_top | int | No | 72pts | Top margin in points. |
| margin_bottom | int | No | 72pts | Bottom margin in points. |
| margin_left | int | No | 72pts | Left margin in points. |
| margin_right | int | No | 72pts | Right margin in points. |
| alignment | string | No | left | Text alignment: left, center, right, or justify. |
| line_spacing | float | No | 1.2 | Line 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.pdfPython
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>