Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert asciidoc to pdf?

Tags:

asciidoc

I attempted to convert my mybook.adoc to mybook.pdf using pandoc, and got the following error.

$ pandoc -s mybook.adoc -t asciidoc -o mybook.pdf
pandoc: cannot produce pdf output with asciidoc writer

Is there another tool that I should use instead of or in concert with pandoc? How can I convert asciidoc to pdf?

like image 237
mherzl Avatar asked May 22 '18 22:05

mherzl


People also ask

What is AsciiDoc format?

AsciiDoc is a text document format that was explicitly designed with the needs of publishing in mind, both print and web. It supports all the structural elements necessary for writing notes, documentation, articles, books, ebooks, slideshows, web pages, technical manuals and blogs.

How do you convert data to PDF?

Click the Select a file button above or drag and drop a file into the drop zone. Select the document you want to convert to PDF. Watch Adobe Acrobat do its PDF conversion magic. Download your new PDF or sign in to share it.

How do I automate a PDF conversion?

Open the PDF Converter Settings panel from Start > Programs > AssistMyTeam PDF Converter for Windows. Alternatively, invoke it from the context menu of Windows Explorer. From the Settings panel, go to Auto PDF tab and check 'Enable Automation' option.


2 Answers

If you have Docker installed, you can use the AsciiDoctor Docker Image. Then you can use the image interactively or in batch mode as explained below:

Prerequisites

  1. Install Docker
  2. Install the Docker image:

    $ docker pull asciidoctor/docker-asciidoctor
    

Create the pdf by executing the following command:

$ cd [directory to where my book.adoc is located]
$ docker run --rm -v $(pwd):/documents/ asciidoctor/docker-asciidoctor asciidoctor-pdf mybook.adoc

Explanation

  • docker run starts a Docker container
  • --rm cleanup - removes the Docker container after the command has been executed
  • -v mount a volume to the image
  • $(pwd) get the path to the current directory, e.g. the value of [directory to where my book.adoc is located] above
  • documents the name of the mounted volume in the running container
  • asciidoctor/docker-asciidoctor the name of the Docker image that is used to create the Docker container
  • asciidoctor-pdf the command that actually triggers the pdf generation
  • mybook.adoc the name of the AsciiDoc source file to generate the pdf from

See also the docker run documentation

like image 147
matsev Avatar answered Sep 28 '22 03:09

matsev


I now realize the ideal route from asciidoc to pdf is to first convert the asciidoc to docbook. This employs the intended sphere of asciidoc and a docbook->pdf converter using each in its separate area of concern.

Furthermore, instead of pandoc I have found that when mathematical formulas are included, it was easier to use dblatex for docbook->pdf conversion. Thus my conversion pipeline is the following:

asciidoc -> asciidoctor -> docbook -> dblatex -> pdf

A sample make file:

make: my.adoc
  asciidoc -b docbook my.adoc
  dblatex my.xml

This discussion page suggests that asciidoc is primarily designed to compile to docbook.

like image 28
mherzl Avatar answered Sep 28 '22 03:09

mherzl