# Getting started

ExAnydoc converts documents locally through a Rust NIF. It does not upload the
document or require an external conversion service.

## Install

Add ExAnydoc to `mix.exs`:

```elixir
def deps do
  [
    {:ex_anydoc, "~> 0.1.0"}
  ]
end
```

Then fetch and compile the dependency:

```shell
mix deps.get
mix compile
```

Rust and Cargo must be installed wherever the dependency is compiled. The
recommended installer is [rustup](https://rustup.rs/).

## Convert a file

`ExAnydoc.to_markdown/1` accepts a filesystem path and returns
GitHub-Flavored Markdown:

```elixir
case ExAnydoc.to_markdown("priv/documents/report.docx") do
  {:ok, markdown} ->
    File.write!("report.md", markdown)

  {:error, %{code: code, message: message}} ->
    Logger.warning("document conversion failed: #{code}: #{message}")
end
```

## Convert uploaded or in-memory data

Use `ExAnydoc.to_markdown_bytes/2` when the document is already a binary:

```elixir
bytes = File.read!("slides.pptx")
{:ok, markdown} = ExAnydoc.to_markdown_bytes(bytes)
```

Most formats are detected from their contents. CSV has no reliable signature,
so it must be named explicitly:

```elixir
{:ok, markdown} =
  ExAnydoc.to_markdown_bytes("name,score\nAda,10\n", :csv)
```

For a Phoenix upload, read the temporary file or pass its path directly:

```elixir
def convert_upload(%Plug.Upload{path: path}) do
  ExAnydoc.to_markdown(path)
end
```

Continue with [Formats and conversion](formats-and-conversion.md) or learn how
to consume the [structured document model](document-model.md).
