To upload a PDF to an API and get JSON back, send the file as a multipart form upload with your API key, then read either the JSON result in the response or a job ID to check later. Before you upload, check size, page count and passwords; after, validate the JSON's form type and tax year.
The curl command and the JSON in this post are examples aimed at a placeholder host, https://api.example.com. Because Schema Tax has not published API documentation, treat the path, parameters and response keys as a sketch of the general pattern and not as a real endpoint.
Multipart or base64: how should you upload a PDF to an API?
Multipart is usually the better way to upload a PDF to an API. It sends the file's bytes as they are, streams well from disk, and every HTTP tool supports it. Base64 inside a JSON body is simpler to log and route, but it makes the payload about a third larger and is usually held in memory whole.
Multipart form uploads
A multipart upload, defined by RFC 7578 on multipart/form-data, splits the request body into named parts. Each part carries a Content-Disposition header with a name, and file parts should carry a filename as well. The RFC deprecates Content-Transfer-Encoding in contexts like HTTP that support binary data, which in practice means the PDF's bytes travel unchanged.
The curl manual shows the tooling side: -F makes curl post data as multipart/form-data, an @ before a filename attaches that file, and ;type= sets the part's media type. Here is the illustrative request, aimed at the placeholder host.
# Illustrative only: placeholder host, example path and field names.
curl -sS https://api.example.com/v1/extract \
-H "Authorization: Bearer $EXTRACTION_API_KEY" \
-F "file=@w2-fictional-2025.pdf;type=application/pdf" \
-F "tax_year_hint=2025" \
--max-time 120
The --max-time flag stops curl from waiting forever on a slow response. The extra tax_year_hint field shows that a form can carry plain text parts next to the file. Whether a real API accepts such a hint is up to that API.
Base64 in a JSON body
Base64 turns binary into text so it can sit inside a JSON string. RFC 4648 on Base64 encoding says the encoding represents each 24-bit group of input as 4 output characters. Three bytes become four characters, so a 9 MB scan becomes about 12 MB of text before the JSON around it.
The size is only part of the cost. To build the JSON body, most code reads the whole file, encodes it, and holds the encoded string while it serializes the request. On the server, the same thing happens in reverse. With several uploads in flight, memory use climbs quickly.
Base64 still has uses. Some gateways and message queues only accept JSON. Some clients, such as a browser extension or a low-code tool, find a single JSON body easier to build than a multipart form. If an API offers both, use multipart for files you read from disk and keep base64 for small images captured in memory.
When does a PDF upload return JSON right away?
A PDF upload returns JSON right away when the file is small enough for the server to read inside one HTTP request. A one-page W-2 often fits. A multi-page scan, a batch, or a busy queue usually gets an accepted response with a job ID instead, and the JSON arrives later by polling or webhook.
The synchronous case is the easy one to code. You send the file, wait, and the response body holds the extracted forms. An example body for one fictional W-2 might look like this:
{
"document_id": "doc_example_042",
"status": "complete",
"pages": 1,
"forms": [
{
"form_type": "W-2",
"tax_year": 2025,
"fields": {
"employee_ssn": {"value": "XXX-XX-1234", "flagged": false},
"box_1_wages": {"value": "48210.55", "flagged": false}
}
}
]
}
The asynchronous case returns sooner and says less. A common signal is the HTTP status 202. The MDN reference for 202 Accepted says it means the request has been accepted for processing but processing has not been completed, and that processing is not guaranteed to succeed. The body then carries a job ID and a status such as pending, and the result comes from a second request or a callback.
Write your client for both cases from the start, even if your first test files all come back at once. A client that assumes a full result will break the first time a user uploads a forty-page statement. The guide to async document processing and webhook patterns covers polling intervals, webhook signatures and duplicate deliveries.
Sending many files raises the same question at a larger scale. Uploading a folder of client forms one request at a time works, but batching changes the rate limits, the job tracking and the error handling. The guide to batch uploading tax forms via an API picks up there.
PDF upload limits: file size, page count and password-protected PDFs
PDF upload limits are the reasons a well-formed request still fails: a file over the size cap, a document with more pages than the endpoint accepts, or a password-protected PDF the server cannot open. Each has a cheap check you can run before the upload instead of after.
File size
Every API sets a maximum request size, and some set a lower one for synchronous calls. A request over the cap typically comes back as 413. The MDN reference for 413 Content Too Large says the status means the request was larger than the limits the server defines. Retrying the same file will fail the same way.
Large tax PDFs are usually large because of how they were scanned, not because of how many pages they hold. A color scan at a high resolution can be many times the size of a grayscale scan at a moderate one, with no gain for reading printed boxes. The guide to scanner settings for tax documents has a settings table that keeps files small and readable.
Page count
Some endpoints cap pages per request, and per page billing makes page count a cost question as well. A forty-page PDF that holds one client's whole year might be better split into one file per form. The guide to splitting a PDF with multiple tax forms covers doing that by hand or automatically. Check the count before upload so the request you send is the one you meant to pay for.
Password-protected PDFs
Brokerage and payroll portals sometimes deliver statements as password-protected PDFs. A server that cannot open the file cannot render its pages, so the upload fails or returns an error about the file. Remove the password in a PDF viewer you trust, save a new copy, and upload that. Never send the password to an extraction API alongside the file.
Damaged or mislabeled files
A file named .pdf is not always a PDF. Email clients and download tools sometimes save an HTML error page or a zero-byte file under a PDF name. The Library of Congress format description for PDF 1.7 lists the PDF signature as the ASCII characters %PDF, followed in the header by a version number such as %PDF-1.7. Checking the first four bytes takes one line of code and saves a confusing error message later.
Phone photos and scans sent to a PDF to JSON API
Phone photos and scans sent to a PDF to JSON API are images first. The service has to find the form in the picture, straighten it, and read it, so image type, rotation and how pages are grouped decide the result as much as the camera does. Send each form as clear, upright pages in one document.
Image types
Check which image types the API lists as accepted before you build an upload screen. Common formats such as JPEG and PNG are the safe default. If your users' phones save photos in a format the API does not list, convert on the device or in your backend before upload, and keep the original in case you need to redo it.
Rotation and tilt
A photo can arrive sideways or upside down, and a hand-held shot is rarely square to the page. Small tilts make box borders and baselines slant, which hurts any reader that expects straight lines. Schema Tax straightens crooked scans before reading them, but your own pre-upload step can still help by rotating obviously sideways photos to upright. The guide to deskewing a scanned document before OCR explains what a few degrees of tilt does to box reading.
Combining photos into one document
A two-page form photographed as two images should travel as one document, not two unrelated uploads. If the API accepts several files in one request, send them together and in order. If it accepts only one file, combine the photos into a single PDF with one page per photo. Either way, the service sees the pages as one form, and you get one result instead of two halves.
The capture itself is the cheapest place to fix quality. Good light, a dark background and the whole page in frame do more than any post-processing. The guide to scanning tax documents with your phone has a checklist to run before upload. For how OCR handles these images once they arrive, the tax form OCR category collects the background posts.
Checking the JSON from a PDF upload before you store it
Checking the JSON from a PDF upload before you store it means three things: validate its shape against a schema, confirm each form's type and tax year are the ones you expected, and treat flagged fields as unconfirmed. A response that passes all three is safe to write; one that fails is a question for a person.
Schema validation
The JSON Schema overview defines JSON Schema as a declarative language for defining structure and constraints for JSON data. A schema for the response says which keys must exist, which values are strings, and which strings must look like amounts. Run it on every response. A failure means the contract changed or the response is incomplete, and either way the data should not reach your database. The guide to the fields inside a tax form extraction API response explains what each part of a typical response means.
Form type and tax year
A valid response can still be the wrong document. If a user uploads last year's W-2 by mistake, the JSON is well formed and the tax year says 2024 when you asked for 2025. If they upload a 1099-INT where you expected a W-2, the form type gives it away. Compare both against what your screen asked for, and show the user a clear message when they differ.
Flags and checks
Flagged fields are values the service could not read with confidence. Keep the flag with the value and route the form to review. Recompute simple totals yourself as a second line of defense, and keep amounts as decimal strings rather than floats while you do. In Schema Tax, a value carries its box number, its field name and the checks it passed, which is the information this step needs; the five-step flow from identify to export shows where review fits.
A pre-upload checklist
Run these checks on each file before you send it. Every item is cheap, and each one prevents a failed request or a wasted page.
- The file starts with
%PDF, or is an image type the API accepts. - The file is under the API's size limit for the call you are making.
- The page count is what you expect for the forms inside.
- The PDF has no password.
- Photos are upright and grouped into one document per form.
- Blank pages from duplex scans are removed.
- The same file has not already been uploaded; compare a stored hash.
- You know what tax year and form type you expect back, so you can check the JSON.
- The file holds fictional data if this is a test, never a real taxpayer's form.