> ## Documentation Index
> Fetch the complete documentation index at: https://docs.doconda.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Review and fix a Word file before sending it

> How to review a Word document (.docx) from code, fix its formatting problems and know whether it is ready to send.

You'll write a script that takes a Word file, reviews it, downloads the fixed version and tells you whether it can be
sent or whether something is left to look at. The review uses no AI and never changes your text or your amounts: it
only fixes what is safe (tables wider than the page, headings alone at the bottom of a page, split signatures, gaps in
numbering…) and reports the rest.

## What you need

* A Doconda API key in `DOCONDA_API_KEY`. Create it in the dashboard, under **API keys**.
* Python 3.9+ or Node 20+.
* A Word file to review, for example `contract.docx`. `.doc` works too: it comes back as `.docx`.

## 1. Install the SDK

<CodeGroup>
  ```bash Python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  pip install doconda
  ```

  ```bash TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  npm install @doconda/sdk
  ```
</CodeGroup>

## 2. Upload the file and ask for the review

`create` with `operation: "review"` waits until the review is done and returns the document.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  from doconda import Doconda

  doconda = Doconda()
  file = doconda.files.upload("contract.docx")
  reviewed = doconda.documents.create(operation="review", file=file["id"])

  print(reviewed["status"])
  ```

  ```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  import { readFile, writeFile } from "node:fs/promises"
  import { Doconda } from "@doconda/sdk"

  const doconda = new Doconda()
  const file = await doconda.files.upload(await readFile("contract.docx"), "contract.docx")
  const reviewed = await doconda.documents.create({ operation: "review", file: file.id })

  console.log(reviewed.status)
  ```
</CodeGroup>

`status` tells you how it turned out:

| `status` | What it means |
| - | - |
| `ready` | No problems (or all of them fixed). |
| `ready_with_warnings` | Minor warnings are left. |
| `needs_review` | Something is left that can't be fixed without changing your content. |

## 3. Read the report

The report has two lists: `ledger`, with every fix that was tried (applied or rejected, and why), and `issues`, with
what is left to look at and where it is.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  report = doconda.documents.report(reviewed["id"])

  for fix in report["ledger"]:
      print(fix["outcome"], fix["fix"])
  for issue in report["issues"]:
      print(issue["severity"], issue["code"], issue["message"], issue["location"].get("pages"))
  ```

  ```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  const report = await doconda.documents.report(reviewed.id)

  for (const fix of report.ledger) console.log(fix.outcome, fix.fix)
  for (const issue of report.issues) console.log(issue.severity, issue.code, issue.message, issue.location.pages)
  ```
</CodeGroup>

An issue in the report looks like this:

```json theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
{
  "code": "crossref.broken",
  "severity": "error",
  "message": "…",
  "fixable": false,
  "location": { "pages": [4] }
}
```

## 4. Decide and download the fixed Word file

If the status is `ready` or `ready_with_warnings`, you save the fixed version. Otherwise, check the report.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  if reviewed["status"] in ("ready", "ready_with_warnings"):
      open("contract-reviewed.docx", "wb").write(doconda.documents.download(reviewed["id"], "docx"))
      print("Ready to send: contract-reviewed.docx")
  else:
      print(f"Don't send it yet ({reviewed['status']}): check the report.")
  ```

  ```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  if (reviewed.status === "ready" || reviewed.status === "ready_with_warnings") {
    await writeFile("contract-reviewed.docx", await doconda.documents.download(reviewed.id, "docx"))
    console.log("Ready to send: contract-reviewed.docx")
  } else {
    console.log(`Don't send it yet (${reviewed.status}): check the report.`)
  }
  ```
</CodeGroup>

## Result

* `contract-reviewed.docx`: the same document, with the safe fixes applied. It is still editable.
* The PDF version, if you need it: `download(id, "pdf")`.
* The report: what was fixed, what was discarded and what is left to look at, with the page of each issue.

If `status` is `needs_review`, the report says what is missing and where. For example, an amount in words that doesn't
match the figure (`money.words_mismatch`) is flagged, not corrected: you decide.

## Next steps

* [Review](/en/guides/review): every problem that is detected in Word, PowerPoint, Excel and PDF files.
* [Python SDK](/en/sdk/python) and [TypeScript SDK](/en/sdk/introduction): every method.
* [Complete examples on GitHub](https://github.com/B-C-Software/doconda-examples).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.