asciidoctor / asciidoctor-pdf

:page_with_curl: Asciidoctor PDF: A native PDF converter for AsciiDoc based on Asciidoctor and Prawn, written entirely in Ruby.
https://docs.asciidoctor.org/pdf-converter/latest/
MIT License
1.13k stars 499 forks source link

Invoking asciidoctor-pdf in Ruby #866

Closed briandominick closed 5 years ago

briandominick commented 6 years ago

I've got a gem that calls Asciidoctor.convert_file and always sets require: "pdf", so when backend: pdf it churns out a nice doc. This has worked pretty great, but after struggling to suppress the cover page on a PDF document I'm rendering, I was unable to make it work, even using the technique described in Issue #95. So I tested by directly building with asciidoctor-pdf on the CLI, and it works like a charm.

So should I be trying to get Asciidoctor.convert_file to behave like the asciidoctor-pdf command? Maybe I'm missing a setting? Is there a way to call the Asciidoctor PDF from my Ruby script? Or do I have to switch to an explicit command-line invocation?

mojavelinux commented 5 years ago

You should be able to use Asciidoctor PDF via the Asciidoctor.convert_file with the following script:

require 'asciidoctor-pdf'

Asciidoctor.convert_file 'input.adoc', backend: 'pdf', safe: :safe

The only requirements are that:

Is that not working for you?

briandominick commented 5 years ago

Sorry Dan I should have come by and closed this issue. I did first implemen a CLI invocation of asciidoctor-pdf. Whatever testing I was doing was getting me stuck, and it matched the experience of someone else I was talking to at the time, that somehow invoking the asciidoctor-pdf gem was inadequate. I knew that couldn't be true (and that you can't get to ever issue post here), so I tried again recently and now I'm properly calling asciidoctor-pdf as a gem. https://github.com/DocOps/liquidoc-gem/pull/54

I'm sorry I didn't come back here and update this post. I forgot I posted it!

mojavelinux commented 5 years ago

No problem @briandominick. I'm very happy to hear you got it working!

I'm curious about one thing, though. What does require: "pdf" do? I don't see a pdf.rb file in the repository, and "pdf" is not the name of a gem. It looks like you are already requiring asciidoctor-pdf at the top of the file, so I don't think you need that line unless I'm missing something.

briandominick commented 5 years ago

Ah, if only I had you reviewing all of my PRs @mojavelinux! Or anyone, for that matter, but definitely you would be great, welcome anytime ;-) That looks vestigial from some attempt at something.

mojavelinux commented 5 years ago

;)

If you need input, always feel free to @ me.