项目作者: alphakevin

项目描述 :
A simple RESTful server for converting documents using pandoc
高级语言: TypeScript
项目地址: git://github.com/alphakevin/pandoc-api.git
创建时间: 2019-08-13T03:16:55Z
项目社区:https://github.com/alphakevin/pandoc-api

开源协议:MIT License

下载


Pandoc API

A simple RESTful server for converting documents using pandoc

Install

pandoc is required for converting documents

  1. # apt-get install pandoc
  2. yarn add pandoc-api

Usage

Start a server in command-line:

  1. yarn start

Get command line help

  1. yarn --help
  1. pandoc-api, a simple RESTful server for converting documents
  2. please visit https://github.com/alphakevin/pandoc-api
  3. usage: pandoc-api <command> <options>
  4. commands:
  5. start [<hostname>[:<port>]] start the server, default to localhost:4000
  6. help converter get converter help
  7. options:
  8. -h, --help print this help message

Use in your application

  1. import expores from 'express';
  2. import pandoc from 'pandoc-api';
  3. const app = express();
  4. app.use('/pandoc', pandoc());
  5. // ... your own express routes
  6. app.listen(3000);

Converter

The server provides a similar interface like pandoc, you can simply remove -- or - and use /
instead of white-space between the arguments, all after /api/convert.

  1. POST /api/convert/from/<input-format>/to/<output-format> HTTP/1.1

You can upload file by either of the following method:

  • multipart/form-data upload with a file field of the file to be converted.
  • RAW upload a file in HTTP body with Content-Type and Content-Disposition header provided.

If the /output/<value> option is provided, the Content-Disposition header will contain the new filename.

The converted document will be directly output from the HTTP response body.

For more converting options, please visit https://pandoc.org/MANUAL.html

Environment Variables

Name Description
HOSTNAME For server listening hostname
PORT For server listening port

Examples

Visit http://127.0.0.1:4000/help, or get help in command-line:

  1. yarn cli help converter

Here we use cURL for examples.

Uploading with multipart/form-data

  1. $ curl -F file=@example.docx http://127.0.0.1:4000/api/convert/from/docx/to/html > result.html

Uploading RAW Binary Data

  1. $ curl -X POST \
  2. -T "example.docx" \
  3. -H "Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document" \
  4. -H "Content-Disposition: attachment; filename="example.docx"" \
  5. http://127.0.0.1:4000/api/convert/from/docx/to/html > result.html

Converting Options

  1. /e, /export/<value> set export filter options
  2. /f, /format/<value> specify the output format
  3. /F, /field/<value> replace user-defined text field with value
  4. /i, /import/<value> set import filter option string
  5. /o, /output/<value> output basename, filename or directory
  6. /password/<value> provide a password to decrypt the document

Run as Docker Container

pandoc-api can start from docker without source code or npm installed:

  1. docker run -d -p 4000:4000 --name=pandoc --restart=always alphakevin/pandoc-api

Notice

  • This is a simple http server and supposed to run as inner micro-service, so it does not include any authorization method. Please take your own risk to deploy it publicly.
  • Document formats and options are not fully tested, it just pass them to pandoc.

License

MIT