Skip to content
pdfconversionapi

TXT to WebP API

POST /v2/convert/txt/to/webp draws each page of a text file and returns it as a lossless WebP. For the 2-page sample that is 76,590 and 40,014 bytes, against 263,446 and 153,231 for the same pages as PNG.

Endpoint
POST /v2/convert/txt/to/webp
Accepts
txt
Sample timing
57 ms median of 5 runsHow we measure
Request size
Up to 10 MB on the Free plan or 100 MB on paid plans, all files together

Request and response

Every sample below ran against the API before this page was published. Set PDFCONVERSIONAPI_KEY to your key and run it as is.

curl -sS -X POST \
  https://api.pdfconversionapi.com/v2/convert/txt/to/webp \
  -H "Authorization: Bearer $PDFCONVERSIONAPI_KEY" \
  -F File=@trail-crew-log.txt \
  -o response.json

# FileData is base64. Save the first file in converted/,
# or print the JSON error.
if jq -e '.Files' response.json > /dev/null; then
  mkdir -p converted
  name=$(jq -r '.Files[0].FileName' response.json)
  jq -r '.Files[0].FileData' response.json \
    | base64 --decode > "converted/$name"
else
  cat response.json
fi
200 OK57 ms median2 files, 114 KB
{
  "ConversionCost": 1,
  "ConversionTime": 0.057,
  "Files": [
    {
      "FileName": "trail-crew-log-1.webp",
      "FileExt": "webp",
      "FileSize": 76590,
      "FileData": "UklGRiYrAQBXRUJQVlA4TBor…"
    },
    {
      "FileName": "trail-crew-log-2.webp",
      "FileExt": "webp",
      "FileSize": 40014,
      "FileData": "UklGRkacAABXRUJQVlA4TDqc…"
    }
  ]
}

Response from our test run on 2026-11-03. ConversionTime shows the median of 5 runs. FileData is shortened here; the real response carries the whole file as base64.

The sample, converted

The same file the code sends. Download the input and the output and compare them yourself.

First page of trail-crew-log-1.webp, rendered by the API
Input
trail-crew-log.txt (1.4 KB)
Output
trail-crew-log-1.webp (75 KB)trail-crew-log-2.webp (39 KB)
Source
A two-page plain-text work log for a fictional volunteer trail crew, written by us, with a form feed before page 2 (CC0-1.0). How it was made
Made by
2026-11-04, API build 9eeeb0640aba

Parameters

Send these as form fields next to the file. Names are case-insensitive. If you set one of the documented options below that we don't support yet, the request fails with a 400 that names it instead of returning a file made without it.

ParameterWhat it does
ImageResolutioninteger, default 150Drawing resolution in DPI. 150 makes each Letter page 1,275 × 1,650 pixels. WebP has no DPI field, so the value only sets the pixel count.Values: 36 to 600
ImageWidthintegerScale each page to this many pixels across, keeping its shape; pair it with ImageHeight to fit inside a box.Values: 1 to 20,000
PageRangestringDraw only some pages, for example 1 for a cover thumbnail.Values: Page numbers and ranges
ColorSpaceenum, default defaultmonochrome turns every pixel black or white: page 1 of the sample shrank from 76,590 to 18,332 bytes. gray returned the page byte for byte unchanged, because a page of black text on white is already all gray shades, and so did rgb: whatever the setting, an opaque page is written as three-channel RGB.Values: default, rgb, gray, monochrome
TransparentColorstringMake one exact color transparent, such as white for text on a clear background; WebP keeps the alpha channel.Values: Color name, #RRGGBB or R,G,B
FileNamestringStem of the page files, trail-crew-log by default.
StoreFileboolean, default falseReturn 3-hour download links instead of the images.

What carries over, and what doesn't

Kept

  • Every pixel: the format is lossless WebP (VP8L), so letters have no compression noise
  • The page layout of the PDF route, with the form feed starting page 2
  • An alpha channel when you send TransparentColor; without it, pages are RGB with no alpha
  • One file per page: trail-crew-log-1.webp and trail-crew-log-2.webp

Lost or not yet supported

  • Lossy compression. ImageQuality has no effect here: ImageQuality=10 returned files byte for byte equal to the default ones.
  • Print size. WebP stores no DPI, so a 150 DPI page and a 300 DPI page differ only in pixels.
  • Selectable text and the fixed-width alignment of the text file.

Limits

  • 2,000 pages per request at most (413 otherwise), each up to 16,000 pixels per side and 100 million pixels.
  • Requests up to 10 MB on the Free plan or 100 MB on paid plans, all files and fields together. A conversion can run for up to 120 seconds; after that the API returns 504.

Where teams use it

Page previews on the web

Browsers display WebP directly, and lossless WebP keeps small text sharp at a fraction of PNG's size, which helps when a page shows many document previews.

Storing rendered pages cheaply

If you keep an image of every text page your system produces, the sample's WebP pages take about 28% of the bytes of the PNG pages with the same pixels.

Questions

Is the WebP lossy or lossless?

Lossless. Both sample pages start with a VP8L chunk, WebP's lossless format, and changing ImageQuality does not change a byte. If you need smaller lossy files, convert to JPG instead.

How much smaller than PNG is it?

For the sample, page 1 is 76,590 bytes as WebP and 263,446 as PNG, and page 2 is 40,014 against 153,231: 29% and 26%. Both formats hold the same 1,275 × 1,650 pixels.

Can I make thumbnails?

Add ImageWidth, for example 300, and PageRange=1 for the first page only. The page is drawn at the size needed and then scaled to exactly 300 pixels wide.

Convert your first TXT file in a minute.