docs/guides/convert a file

Guides

Convert a file

Turn a file into another format, such as a Word document into a PDF, a deck into pictures or a workbook into CSV. See what the file can become, then convert it.

See what it can become

cv targets lists the formats a file can become, each with what the conversion keeps and drops. It reads the format from the file's content on your machine and uploads nothing.

Only these conversions exist. Any other target fails with unsupported_conversion, and its try: line lists the ones that do.

Terminal
$ export CV_API_KEY=cv_sk_…

cv login saves a key, or export one as CV_API_KEY. Every cv command reads it.

Terminal
$ cv targets report.pdf
stdoutpdf ->6 lines
pdf ->  docx     The text is rebuilt as an editable document with headings, paragraphs and lists, without the page layout. …  pdf      Only the changes you ask for are made. …  pdf      join: The PDFs joined in the order given. …  md       Headings, paragraphs, lists, links and tables whose cells line up in rows and columns are recovered from the text layout. …  …

Convert it

Name the output, and its extension picks the format. Or pass --to and leave the output out, and the result goes to stdout. An output file that already exists is replaced only with --force.

In the API, upload the file, start a job with the format in to, and download each output from its url. The link needs no key and works for an hour. See Files and Jobs.

A file already in the format you ask for comes back as it was, at no cost. That output is your own upload, so it has no url: keep the file you sent. See Outputs without a link.

A format goes by its id or an alias, so jpg is jpeg and markdown is md. See Formats.

Terminal
$ cv convert report.docx report.pdf
stderr48213 bytes -> report.pdf

Many files from one

A conversion that makes one file for each page, slide or sheet, such as a PDF to PNG, needs a directory as the output. --pages picks the pages, such as 1-3,7.

An output file or stdout asks for exactly one file, so cv fails and its try: line shows the directory form. In the API, each output has its index, and archive holds them all in one zip. A job lists its first 100 outputs; see Several outputs for the rest.

Terminal
$ cv convert slides.pdf pages/ --to png --pages 1-3
stderr3 files -> pages/

Set options

--opt key=value sets an option of the conversion, such as the quality of a picture. Repeat it for several. In the API, options go in the job's options.

Each conversion takes only some options. cv targets <file> --json lists them with their ranges and defaults, and one the conversion does not take fails with invalid_options. See Options.

Terminal
$ cv convert photo.png web.webp --opt quality=80 --opt strip=true
stderr48120 bytes -> web.webp

Several files

Several inputs with a directory as the output are converted one by one. With one output file they are joined into one, in the order given.

In the API, output.shape set to one joins the inputs. Files converted one by one cost a conversion each, and PDFs joined into a PDF cost one. See Join several files and What a job costs.

Terminal
$ cv convert a.pdf b.pdf merged.pdf
stderr412870 bytes -> merged.pdf

Text from a scan

A scan holds pictures of text. A conversion that takes ocr reads the text with --opt ocr=on, such as a scanned PDF to an editable Word document. Add language when the text is not English. Without either, ocr is auto, which reads only the text layer the file already has.

cv targets scan.pdf --json shows which conversions take ocr. To read a scan as text, see Scanned pages.

Terminal
$ cv convert scan.pdf scan.docx --opt ocr=on --opt language=en,ko

Large files and long jobs

cv waits for the job up to --wait seconds, 300 by default. When the wait runs out the job keeps running, and the same command again waits for it instead of starting and paying for a new one.

In the API, a file over 32 MiB goes up in parts, and a job that takes longer than the wait answers 202. See Upload a large file and Waiting and retries.

A file locked with a password fails with input_encrypted. See Files with a password.