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:
def deps do
[
{:ex_anydoc, "~> 0.1.0"}
]
endThen fetch and compile the dependency:
mix deps.get
mix compile
Rust and Cargo must be installed wherever the dependency is compiled. The recommended installer is rustup.
Convert a file
ExAnydoc.to_markdown/1 accepts a filesystem path and returns
GitHub-Flavored Markdown:
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}")
endConvert uploaded or in-memory data
Use ExAnydoc.to_markdown_bytes/2 when the document is already a binary:
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:
{: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:
def convert_upload(%Plug.Upload{path: path}) do
ExAnydoc.to_markdown(path)
endContinue with Formats and conversion or learn how to consume the structured document model.