If you've been asked to "do something with these AFP files," you've entered a world that most modern developers have never seen. AFP (Advanced Function Presentation) is IBM's binary document format, born in the mainframe era, still running in production at banks, insurers, governments, and telecoms worldwide. Every month, billions of pages of statements, policies, and notices are generated as AFP.
The problem? Nobody outside that ecosystem can read an AFP file. This guide covers what AFP actually is, why converting it to PDF is harder than it looks, and how to do it with a single API call.
What Is an AFP File?
AFP stands for Advanced Function Presentation, also known as MO:DCA (Mixed Object Document Content Architecture). IBM created it in the 1980s as a device-independent page description language for high-speed line printers and production printing systems.
Unlike PDF (which is designed to be read on screen), AFP was designed for print production at massive scale — think millions of bank statements per night, printed at 1,000+ pages per minute on continuous-form printers.
An AFP file is a binary stream of structured fields. Each structured field has a fixed header:
- Carriage control byte (0x5A) — marks the start of each field
- 2-byte length — total field length including header
- 3-byte type code — identifies the field (e.g., BDT = Begin Document, BPG = Begin Page Group)
- Flag and reserved bytes
- Data payload — variable-length content: text, images, metadata
The document model is hierarchical: a Document contains Page Groups, which contain Pages, which contain Active Environment Groups (fonts, colors, layout), Text Objects, Image Objects, and Graphics Objects.
Why AFP-to-PDF Is Hard
AFP isn't just "a different file format." It's an entirely different paradigm. Here's what makes conversion non-trivial:
1. Binary Format, Not Text
AFP is a packed binary stream. There are no tags, no XML, no JSON. Every byte matters. A single off-by-one error in parsing a structured field length will cascade through the entire document. You need a state machine that tracks document scope (document → page group → page → text object) and handles nesting correctly.
2. PTOCA Text Encoding
Text in AFP is encoded using PTOCA (Presentation Text Object Content Architecture). PTOCA is its own mini-language of control sequences that position text absolutely on the page, set fonts by local ID, change colors, and handle inline direction (horizontal, vertical, bidirectional). Each text run carries X/Y coordinates in L-units (logical units — typically 1/1440 of an inch).
3. EBCDIC Encoding
Because AFP was born on IBM mainframes, text is often EBCDIC-encoded, not ASCII or UTF-8. A robust converter needs multi-encoding fallback: try ASCII, then UTF-16BE, then EBCDIC, and pick the best result with a scoring heuristic.
4. Embedded Resources
AFP files embed fonts, images, overlays, and page segments as internal resources. Images can be IOCA (Image Object Content Architecture) in raw raster, CCITT Group 4 compressed, or JPEG. Font mappings connect local IDs to character sets and code pages. Overlays and page segments are essentially sub-documents that get composited onto pages at specific positions. All of this must be resolved correctly or the output PDF will have missing content.
5. Coordinate System Differences
AFP uses a top-left origin coordinate system. PDF uses bottom-left origin. Every Y coordinate must be flipped: pdfY = pageHeight - afpY. Get this wrong and your text renders upside-down or off-page.
Skip the complexity. Use the API.
Scribo handles all of this — binary parsing, PTOCA, EBCDIC, image extraction, coordinate flipping — in a single endpoint. 100 free conversions/month, no credit card.
Get Your Free API Key →Converting AFP to PDF with Scribo's API
Scribo exposes a single REST endpoint. Send your AFP file, get a PDF back. No SDKs to install, no Java runtimes, no configuration.
Endpoint
POST https://scribo-i9ld.polsia.app/api/convert
Content-Type: application/octet-stream
Authorization: Bearer YOUR_API_KEY
curl
# Convert an AFP file to PDF
curl -X POST https://scribo-i9ld.polsia.app/api/convert \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/octet-stream" \
--data-binary @statement.afp \
--output statement.pdf
That's it. The response body is the PDF. Status 200 = success. Save the response to a file and you're done.
Node.js
const fs = require('fs');
async function convertAfpToPdf(inputPath, outputPath) {
const afpBuffer = fs.readFileSync(inputPath);
const res = await fetch('https://scribo-i9ld.polsia.app/api/convert', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/octet-stream',
},
body: afpBuffer,
});
if (!res.ok) throw new Error(`Conversion failed: ${res.status}`);
const pdf = Buffer.from(await res.arrayBuffer());
fs.writeFileSync(outputPath, pdf);
console.log(`Converted: ${outputPath}`);
}
convertAfpToPdf('statement.afp', 'statement.pdf');
Python
import requests
def convert_afp_to_pdf(input_path, output_path, api_key):
with open(input_path, 'rb') as f:
afp_data = f.read()
response = requests.post(
'https://scribo-i9ld.polsia.app/api/convert',
headers={
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/octet-stream',
},
data=afp_data,
)
response.raise_for_status()
with open(output_path, 'wb') as f:
f.write(response.content)
print(f'Converted: {output_path}')
convert_afp_to_pdf('statement.afp', 'statement.pdf', 'YOUR_API_KEY')
What Scribo Handles Under the Hood
When your AFP file hits the /api/convert endpoint, here's what happens in milliseconds:
- Stream parsing — The binary AFP stream is split into structured fields, each validated for correct length and type code.
- Document assembly — A state machine builds the document hierarchy: page groups, pages, active environment groups, text objects, image objects.
- Resource resolution — Font maps (MCF), page segments (MPS), and overlays (MMO) are resolved. Resource groups are collected and composited onto pages at their specified positions.
- PTOCA text extraction — Text objects are decoded from PTOCA control sequences. Absolute positioning, font switching, color changes, and multi-encoding fallback are all handled.
- Image processing — IOCA images are extracted and converted: raw raster to PDF image XObjects, CCITT Group 4 compressed data with correct decode parameters, and JPEG passthrough.
- PDF generation — A valid PDF 1.4 document is constructed with proper page tree, font dictionaries, content streams, cross-reference table, and trailer.
Performance
Scribo's parser is written in optimized JavaScript, processing AFP at near-native speed. Here are real benchmarks from production:
| Document | Pages | File Size | Conversion Time |
|---|---|---|---|
| Single-page statement | 1 | 12 KB | < 1 ms |
| Multi-page letter with images | 4 | 85 KB | 3 ms |
| Complex form with overlays | 8 | 340 KB | 8 ms |
| Batch statement run | 50 | 2.1 MB | 45 ms |
Sub-millisecond for single pages. Under 50ms for a 50-page batch. Fast enough to convert on-the-fly in a request pipeline — no need for background jobs or queues.
Error Handling
The API returns structured JSON errors when something goes wrong:
// 400 — Invalid AFP file
{ "error": "Invalid AFP file: no structured fields found" }
// 401 — Missing or invalid API key
{ "error": "Invalid API key" }
// 413 — File too large
{ "error": "File exceeds maximum size of 50MB" }
// 429 — Rate limit exceeded
{ "error": "Monthly conversion limit exceeded" }
Pricing
Scribo is built for developers who need to get this done, not evaluate enterprise software for six months:
- Free tier — 100 conversions/month. No credit card required. Full API access.
- Pro ($49/mo) — 10,000 conversions/month. Priority support.
- Enterprise — Unlimited volume, SLA, dedicated support. Contact us.
Try it free — 100 conversions/month
Get your API key in 30 seconds. No credit card, no sales call, no Java runtime.
Get Your Free API Key →Who Uses AFP in 2026?
AFP isn't legacy — it's entrenched. Organizations that print millions of pages per month don't switch formats casually. If you work in or around any of these industries, you'll eventually encounter AFP:
- Banking & financial services — Account statements, trade confirmations, regulatory notices
- Insurance — Policy documents, explanation of benefits, claim correspondence
- Government — Tax notices, benefits statements, compliance documents
- Healthcare — Patient statements, EOB forms, provider correspondence
- Telecommunications — Monthly bills, service agreements, usage reports
These organizations are modernizing. They need their AFP archives accessible as PDF for web portals, email delivery, mobile apps, and compliance. That's where conversion APIs like Scribo come in.
Getting Started
- Get an API key — Sign up for free (30 seconds, no credit card)
- Send your first AFP file — Use the curl example above
- Or try the demo — Drag and drop an AFP file on our homepage to see instant conversion with no signup
Questions? Email scribo@polsia.app. We built Scribo because we spent years dealing with AFP internals and wanted a tool that just works. Now it does.