How to convert asciidoc to pdf?
Asked Answered
D

9

17

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?

Diseased answered 22/5, 2018 at 22:54 Comment(3)
pandoc indicates here "For PDF output, you’ll also need to install LaTeX", so perhaps asciidoc is the wrong tool and you need to use a pandoc LaTeX tool of some sort or something?Lorenzetti
See my graphical user interface-based approach, this is the easiest and most convenient solutionKorrie
Does this answer your question? Generate single PDF from multiple Asciidoc filesKorrie
D
3

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.

Diseased answered 10/6, 2019 at 19:27 Comment(1)
I'm using asciidoc/dosbook for many years and I agree regarding asciidoc. But when using asciidoctor it is quite different: The recommended way is to use the gradle-plugin.Pronominal
E
21

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.

Extradition answered 6/8, 2018 at 14:28 Comment(2)
I used snap on Ubuntu to install ruby. Error: Command 'asciidoctor-pdf' not found, but can be installed with: apt install ruby-asciidoctor-pdf. So I removed snap ruby and used sudo apt. Works.Fincher
If you have nix installed, just use nix-shell -p asciidoctor-with-extensions to enter a sub-shell that has asciidoctor-pdf ready to use.Volcanic
C
19

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

Cornelie answered 10/3, 2020 at 13:33 Comment(1)
On windows, $(pwd) doesn't work in the command line so I used docker run --rm -v "%cd%:/documents/" asciidoctor/docker-asciidoctor asciidoctor-pdf mybook.adoc insteadAmalekite
B
16

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.

Bod answered 24/2, 2020 at 7:14 Comment(1)
I have my document organised into several files. For me VS Code fails to load images - for some reason it looks for them in a completely different location.Goosy
H
3

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.

Hartsock answered 5/6, 2018 at 22:19 Comment(0)
D
3

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.

Diseased answered 10/6, 2019 at 19:27 Comment(1)
I'm using asciidoc/dosbook for many years and I agree regarding asciidoc. But when using asciidoctor it is quite different: The recommended way is to use the gradle-plugin.Pronominal
E
2

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.

Extricate answered 19/7, 2018 at 11:55 Comment(0)
R
1

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

Rosenberry answered 5/10, 2021 at 9:36 Comment(0)
D
0

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
Diseased answered 25/9, 2018 at 4:13 Comment(0)
F
0

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.

Fulgurite answered 14/2, 2019 at 8:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.