Async PDF Processing
PDF Oxide ships first-class async APIs in Python, C#, and Node.js so extraction never blocks your event loop or HTTP request handler. The same PdfDocument methods are exposed as async wrappers that dispatch to a background thread / thread pool.
Python — AsyncPdfDocument
Every method on PdfDocument has an awaitable counterpart on AsyncPdfDocument. Each call wraps the sync method with asyncio.to_thread().
Python
import asyncio
from pdf_oxide import AsyncPdfDocument
async def extract(path):
doc = await AsyncPdfDocument.open(path)
text = await doc.extract_text(0)
return text
asyncio.run(extract("report.pdf"))
Fan-out across pages
Python
import asyncio
from pdf_oxide import AsyncPdfDocument
async def extract_all(path):
doc = await AsyncPdfDocument.open(path)
page_count = await doc.page_count()
pages = await asyncio.gather(*[doc.extract_text(i) for i in range(page_count)])
return pages
Creation
AsyncPdf mirrors the Pdf class for creation flows:
Python
from pdf_oxide import AsyncPdf
pdf = await AsyncPdf.from_markdown("# Hello")
await pdf.save_async("out.pdf")
Office conversion
AsyncOfficeConverter handles async DOCX / XLSX / PPTX → PDF.
Python
from pdf_oxide import AsyncOfficeConverter
converter = AsyncOfficeConverter()
pdf_bytes = await converter.docx_to_pdf_bytes("input.docx")
Free-threaded Python (cp314t)
The pdf_oxide extension module declares gil_used = false, making it safe to use under cp314t (Python 3.14 free-threaded builds). Multiple threads can call PdfDocument methods in parallel without GIL serialisation.
Python
from concurrent.futures import ThreadPoolExecutor
from pdf_oxide import PdfDocument
doc = PdfDocument("large.pdf")
with ThreadPoolExecutor(max_workers=8) as pool:
pages = list(pool.map(doc.extract_text, range(doc.page_count())))
C# — async Task<T> with CancellationToken
Every extraction and save method has an *Async variant returning Task<T> and accepting an optional CancellationToken.
C#
using PdfOxide.Core;
using var doc = PdfDocument.Open("report.pdf");
string text = await doc.ExtractTextAsync(0);
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
var tasks = Enumerable.Range(0, doc.PageCount)
.Select(i => doc.ExtractTextAsync(i, cts.Token));
string[] pages = await Task.WhenAll(tasks);
Editor
C#
using var editor = DocumentEditor.Open("form.pdf");
editor.SetFormFieldValue("name", "Jane Doe");
await editor.SaveAsync("filled.pdf");
Node.js — *Async methods
Every sync method has an async sibling — extractText → extractTextAsync, save → saveAsync, etc. Async calls run on the libuv thread pool.
Node.js
const { PdfDocument } = require("pdf-oxide");
async function extractAll(path) {
const doc = new PdfDocument(path);
try {
const pageCount = doc.getPageCount();
const pages = await Promise.all(
Array.from({ length: pageCount }, (_, i) => doc.extractTextAsync(i))
);
return pages;
} finally {
doc.close();
}
}
HTTP handler example
Node.js
import express from "express";
import { PdfDocument } from "pdf-oxide";
const app = express();
app.post("/extract", express.raw({ type: "application/pdf", limit: "50mb" }), async (req, res) => {
const doc = PdfDocument.openFromBytes(req.body);
try {
const text = await doc.extractTextAsync(0);
res.json({ text });
} finally {
doc.close();
}
});
Concurrency model
| Language | Mechanism |
|---|---|
| Python | asyncio.to_thread dispatches sync call to the default executor |
| Python (cp314t) | True thread parallelism — GIL is optional |
| C# | Task-based Asynchronous Pattern, dispatched to ThreadPool |
| Node.js | libuv worker threads (Napi::AsyncWorker) |
| Go | Not needed — goroutines call sync methods directly |
| Rust | Not provided — use tokio::task::spawn_blocking or your executor of choice |
See the concurrency guide for sharing a single PdfDocument across threads.
Related
- Concurrency — thread safety + parallel reads
- Python Getting Started
- Node.js Getting Started
- C# Getting Started