A simple RESTful server for converting documents using pandoc
pandoc is required for converting documents
# apt-get install pandoc
yarn add pandoc-api
Start a server in command-line:
yarn start
Get command line help
yarn --help
pandoc-api, a simple RESTful server for converting documents
please visit https://github.com/alphakevin/pandoc-api
usage: pandoc-api <command> <options>
commands:
start [<hostname>[:<port>]] start the server, default to localhost:4000
help converter get converter help
options:
-h, --help print this help message
Use in your application
import expores from 'express';
import pandoc from 'pandoc-api';
const app = express();
app.use('/pandoc', pandoc());
// ... your own express routes
app.listen(3000);
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
.
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 afile
field of the file to be converted.- RAW upload a file in HTTP body with
Content-Type
andContent-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
Name | Description |
---|---|
HOSTNAME |
For server listening hostname |
PORT |
For server listening port |
Visit http://127.0.0.1:4000/help
, or get help in command-line:
yarn cli help converter
Here we use cURL for examples.
$ curl -F file=@example.docx http://127.0.0.1:4000/api/convert/from/docx/to/html > result.html
$ curl -X POST \
-T "example.docx" \
-H "Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document" \
-H "Content-Disposition: attachment; filename="example.docx"" \
http://127.0.0.1:4000/api/convert/from/docx/to/html > result.html
/e, /export/<value> set export filter options
/f, /format/<value> specify the output format
/F, /field/<value> replace user-defined text field with value
/i, /import/<value> set import filter option string
/o, /output/<value> output basename, filename or directory
/password/<value> provide a password to decrypt the document
pandoc-api
can start from docker without source code or npm installed:
docker run -d -p 4000:4000 --name=pandoc --restart=always alphakevin/pandoc-api
- 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.
MIT