NewConnect Claude, Gemini, ChatGPT, and other AI agents to API Ninjas via our MCP server →

Word to PDF API

The Word to PDF API converts Microsoft Word documents to PDF. Send a .docx or .doc file, as an upload or a link, and get back a PDF with the document's text, fonts, headings, tables, images, lists, headers and footers, footnotes and page numbers, on the same page size and margins.

Common Office fonts that a document uses but does not embed, such as Calibri, Cambria, Arial and Times New Roman, are replaced with fonts that have the same character widths, so text keeps close to its original line and page breaks. Macros in a document never run.

Use it to turn contracts, invoices, reports and letters generated as Word files into PDFs for sharing, printing, archiving or e-signature.

Each page of the PDF uses one of your plan's monthly document pages, not API calls: Free 50, Developer 10,000, Business 100,000, Professional 500,000. The X-Pages-Used and X-Pages-Remaining response headers show the pages each request used and how many are left. See pricing.

Working with images? The Image to PDF API combines images into a PDF, the PDF to Image API turns PDF pages into images, and the Image to Text API reads the text in an image.

Available endpoint:

At a Glance

Input.docx or .doc: upload, raw body, or url (up to about 4 MB)
OutputA PDF, as base64 in JSON or as a PDF file
Pages per documentUp to 100
Plan usage1 document page per page of the PDF
Free planDocuments up to 3 pages and 2 MB

Related APIs

https://api.api-ninjas.com/v1/wordtopdf

Converts a Word document (.docx or .doc) to PDF. Returns the PDF as base64 in JSON, or as a raw PDF file. Accepts GET or POST: use POST to upload a document, or GET with url.

Parameters

Send the document as a file upload (multipart form data), as a url link, or as the raw request body with its Content-Type.

  • file  optional

    The Word document (.docx or .doc), as a multipart form upload, up to about 4 MB.

  • url  optional

    A public http:// or https:// link to a .docx or .doc file, up to about 4 MB, instead of an upload. Works with GET or POST.

Headers

  • X-Api-Key  required

    API Key associated with your account.

  • Accept  optional

    application/pdf returns the raw PDF file instead of JSON.

  • Content-Type  optional

    application/vnd.openxmlformats-officedocument.wordprocessingml.document (.docx) or application/msword (.doc), when the request body is the document itself. Multipart uploads set their own content type.

Response

The /v1/wordtopdf endpoint returns a JSON object with the following fields, or an error if the request is unsuccessful (see errors).

  • page_count

    Number of pages in the PDF.

  • size

    Size of the PDF in bytes.

  • pdf

    The PDF file, base64-encoded.

With Accept: application/pdf, the response body is the PDF file itself (Content-Type: application/pdf). Responses have X-Pages-Used (document pages the request used) and X-Pages-Remaining (document pages left this month) headers.

Limits

  • Documents up to 100 pages and about 4 MB, uploaded or from url.
  • The PDF can be up to about 4 MB.
  • One document per request. Password-protected documents are not supported.
  • Free plan: documents up to 3 pages and 2 MB, sent as file uploads.

Document pages

This API uses your plan's monthly document pages, not API calls. Each page of the PDF uses one: a 10-page document uses 10.

Live Demo

Live demo · no API key required
Form data and query parameters

The demo converts this sample document. Sign up or log in to convert your own Word documents.

Get a free API key to get started — no credit card required.

Headers
X-Api-KeyLog in or sign up to get your API key
POST
https://api.api-ninjas.com/v1/wordtopdf
Sample response

Press Send to convert the document and preview the PDF here.

{
"page_count": 1,
"size": 44357,
"pdf": "JVBERi0xLjcKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMg..."
}

Code Examples

# Convert a Word document and save the PDF curl -X POST "https://api.api-ninjas.com/v1/wordtopdf" \ -H "X-Api-Key: YOUR_API_KEY" \ -H "Accept: application/pdf" \ -F "file=@report.docx" \ --output report.pdf

Errors

An invalid request returns HTTP 400 with a JSON body holding a readable error message. If too many documents are being converted at once, the API returns HTTP 503: retry after a few seconds. Authentication and quota errors use the standard format described in error codes.

CauseExample error
No document in the requestSend the Word document as file (a multipart form upload) or as url (a link to the document).
A file that is not a Word documentUnsupported file type. Send a Word document (.docx or .doc).
A damaged or password-protected documentThe document could not be converted. Check that it is a valid Word document and is not password-protected.
More than 100 pagesThis document has 140 pages. The most per request is 100 pages.
A document over about 4 MBThe file is larger than 4 MB. Send a smaller document.
A PDF over about 4 MBThe PDF would be larger than 4 MB. Try a document with fewer or smaller images.
More than one documentSend one document per request.
No document pages left this monthYou have used all 50 document pages included in your Free plan this month. They renew on December 1, 2026. Upgrade at https://api-ninjas.com/pricing for more.
Free plan: more than 3 pagesThis document has 5 pages. The Free plan converts documents of up to 3 pages. Upgrade at https://api-ninjas.com/pricing for documents up to 100 pages.

Frequently Asked Questions

  • Yes, but you must have a premium subscription. Commercial use of the Word to PDF API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.
  • Sign up for a free account to instantly get your API key, then pass it in the X-Api-Key header on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.
  • Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.
  • The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.
  • POST the document to /v1/wordtopdf as a multipart upload named file, e.g. curl -X POST "https://api.api-ninjas.com/v1/wordtopdf" -H "X-Api-Key: YOUR_API_KEY" -H "Accept: application/pdf" -F "file=@report.docx" --output report.pdf. Without the Accept header the response is JSON with the PDF base64-encoded in pdf. A document that is already online can be passed as url instead.
  • .docx files (Word 2007 and later) and .doc files (Word 97 to 2003). The file type is read from the file itself, so the file name does not matter. Password-protected documents are not supported, and macros in a document never run.
  • Text, headings, fonts, tables, images, lists, headers and footers, footnotes and page numbers are converted, on the document's own page size and margins. Fonts embedded in the document are used as they are. Common Office fonts that are not embedded, such as Calibri, Cambria, Arial, Times New Roman and Courier New, are replaced with fonts that have the same character widths, so text keeps close to its original line and page breaks.
  • No API calls. Each page of the PDF uses one of your plan's monthly document pages, so a 10-page document uses 10. The X-Pages-Used and X-Pages-Remaining response headers show the pages each request used and how many are left.
  • Yes: the Free plan includes 50 document pages a month, for documents up to 3 pages and 2 MB sent as file uploads. Paid plans convert documents up to 100 pages and about 4 MB, from uploads or url, with 10,000 to 500,000 document pages a month. See pricing.