Sooner or later a product that handles documents receives a .docx. A contract template edited in Word, a price list exported from Excel, a sales deck someone wants attached to a proposal. Browsers cannot render these, so none of the HTML tools from the first two lessons help. Converting them yourself means installing LibreOffice on a server, keeping its fonts current and stopping a hung conversion from eating a worker.
Office to PDF (officetopdf) runs that conversion for you, with LibreOffice. It accepts Word (doc, docx), Excel (xls, xlsx), PowerPoint (ppt, pptx), OpenDocument (odt, ods, odp), RTF, plain text and CSV, up to 10 MB per document. Each call converts one document and costs 30 credits.
Two ways to send the document
The one input parameter is document, and it takes either form:
- A public URL to the file, as a JSON body:
{"document": "https://..."}. The definition also acceptsurlas an alias for the same parameter. - The file itself, as a
multipart/form-dataupload with the field namedocument.
Start with the URL form, because it is the one you can try from this page:
curl -X POST "https://api.apiverve.com/v1/officetopdf" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"document":"https://raw.githubusercontent.com/apache/poi/trunk/test-data/document/SampleDoc.docx"}'inputFormat is detected from the file's contents; pageCount tells you how many pages the PDF has.
That sample Word document converts to a two-page PDF. The response gives you more to work with than the HTML renderers did:
| Field | What it is |
|---|---|
pageCount | Pages in the resulting PDF |
inputFormat | The format the document was converted as, detected from its contents |
inputName | The input file name, such as SampleDoc.docx |
size | Size of the PDF in bytes |
pageRanges | The pages converted, or null for the whole document |
landscape | Whether landscape orientation was applied |
downloadURL, expires, pdfName | The signed link (valid for 2 days), its expiry in milliseconds, and the file name |
The same call with an Excel workbook (SampleSS.xlsx from the same test-data repository) returned inputFormat: "xlsx" and two pages, and a PowerPoint deck (SampleShow.pptx) returned inputFormat: "pptx" and two pages, one per slide.
Which input form to use
The URL form is convenient when the file already sits somewhere public, but "public" is the catch. The service fetches the URL from the internet without your credentials, so a link to a private bucket or an intranet share fails. Making a contract publicly readable so a converter can fetch it is the wrong trade.
There is a middle path when files live in your object storage: generate a short-lived signed URL (a few minutes is plenty) and send that. The file stays private, the link is useless shortly afterwards, and your server never has to hold the bytes.
The upload form is right when the bytes are already in your process, typically because a user just uploaded them to you. Two limits apply: 10 MB per document, and uploads on the Free plan are limited to 400 KB. A typical text-heavy DOCX fits under 400 KB; a deck with photos usually does not. If your own upload form accepts larger files than your plan forwards, you will see that as a 400 naming the size ceiling, so check sizes before calling and give the user a clear message instead.
Your app stores customer contracts in a private storage bucket. What is the best way to convert one with Office to PDF?
Answer the check above to continue.
Using pageCount as a quality gate
Every conversion tells you how many pages came out. That is cheap, deterministic and surprisingly useful:
- A contract template that has always been 4 pages coming back as 5 means someone edited the template and pushed the signature block onto a new page.
- A 30-page report that comes back as 2 pages means the wrong file, or an empty export, reached the converter.
- A spreadsheet that explodes into dozens of pages has a print-area problem.
Store the expected page count per template and alert on deviations. It catches most layout regressions without anyone opening a PDF.
Next
You can now produce PDFs from HTML, web pages, Markdown and office files. Real workflows rarely stop at one file: they bundle, number and read them. That is the last lesson, /academy/generate-pdfs/04-merge-number-and-extract-pdfs. The full reference for this API is on its marketplace page.