mherzl
mherzl

Reputation: 6210

How to convert asciidoc to pdf?

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?

Upvotes: 18

Views: 45762

Answers (9)

Tebogo Mahlalela
Tebogo Mahlalela

Reputation: 265

If you're using Visual Studio Code with AsciiDoc extension, Ctrl + SHFT + P (or Shift ⇧ + Cmd ⌘ + P in macOS) and type AsciiDoc: Export document as PDF.

You will need to have asciidoctor-pdf or wkhtmltopdf installed according to the command instructions.

Upvotes: 16

atul sachan
atul sachan

Reputation: 617

In case if you have AsciiDoc plugin in Intellij, here is the way you can generate -

  1. create the adoc file ex - "tktds-dhs-e2e-gcp.adoc" and write your content.. or you may already have adoc file..
  2. At top where file is opened in editor, click on PDF or HTML button to generate .pdf or .html files {need to click 1 at a time} refer below image -

enter image description here

  1. Further you can find pdf / html file in same directory, refer below image -

enter image description here

Upvotes: 1

matsev
matsev

Reputation: 33769

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

Upvotes: 21

mherzl
mherzl

Reputation: 6210

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.

Upvotes: 4

markbez
markbez

Reputation: 39

Another workflow, which I use a lot, is to create HTML from your AsciiDoc file using the AsciiDoctor processor, linking a custom CSS stylesheet with print styling rules:

asciidoctor -a stylesheet=path-to-stylesheet.css file.adoc

You can then open the HTML file in your browser and print to PDF.

For more advanced styling, such as page numbering, headers, footers, page breaks and columns, you can use PrinceXML (or other similar products). This is a commandline processor that will convert the HTML file to PDF using the styling rules in the CSS used by the HTML file. PrinceXML applies styling rules that are in the CSS3 standard but which aren't yet supported by browsers, allowing you to create finely styled layouts.

Upvotes: 0

mherzl
mherzl

Reputation: 6210

Following @Remis's answer, I used asciidoctor's pdf backend.

I could not figure out how to install asciidoctor-pdf on nixos, but managed to find the following alternative which worked:

asciidoctor -r asciidoctor-pdf -b pdf or asciidoctor-pdf

Upvotes: 0

Remis
Remis

Reputation: 651

Prerequisites: all that’s needed is Ruby (1.9.3 or above)

Install a native PDF converter for AsciiDoc - Asciidoctor PDF:

gem install asciidoctor-pdf --pre

Run:

asciidoctor-pdf mybook.adoc

You should get the file mybook.pdf in the same directory.

Upvotes: 23

Shailendra
Shailendra

Reputation: 325

The easiest way to convert AsciiDoc document to PDF is as follows -

  • Open AsciiDocLive
  • Paste your document in the editor and see the preview
  • save it as HTML
  • Open any online HTML to PDF convertor
  • Upload your newly generated HTML file
  • Convert to PDF and download it.

Done.

Upvotes: 2

Brian D
Brian D

Reputation: 963

AsciiDoc has a couple of toolchains that will render PDFs from AsciiDoc source. You can use the Ruby-based AsciiDoc -> Prawn -> PDF toolchain developed by Asciidoctor, or you can use the older AsciiDoc -> DocBook -> FOP toolchain. These are rendering/publishing procedures, whereas Pandoc mainly provides for conversion and is best for converting from one o another type of source format.

Upvotes: 3

Related Questions