PDF's from asciidoctor-pdf ruby gem ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

PDF's from asciidoctor-pdf ruby gem ?

jnorthr
Do we ever see a time when we will be able to gen PDF's using a ruby gem named something like asciidoctor-pdf ?

looking at the asciidoctorJ notes from https://github.com/asciidoctor/asciidoctorj  there is no jar, etc download for it only shows as:

org.asciidoctor  asciidoctorj-pdf  1.5.0-alpha.6

so no joy there yet
Reply | Threaded
Open this post in threaded view
|

Re: PDF's from asciidoctor-pdf ruby gem ?

mojavelinux
Administrator
Jim,

I'm not sure I understand your question. Asciidoctor PDF has been available for some time to serve this purpose and we've even realized AsciidoctorJ PDF so you can use it from Java without much hassle.

You can see an example of it in use in the Maven plugin examples. All you need to do is add org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.6 to the classpath and set the backend to "pdf" to use it.

https://github.com/asciidoctor/asciidoctor-maven-examples/blob/master/asciidoctor-pdf-example/pom.xml#L34

Cheers,

-Dan

On Mon, Jan 26, 2015 at 3:20 PM, jnorthr [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Do we ever see a time when we will be able to gen PDF's using a ruby gem named something like asciidoctor-pdf ?

looking at the asciidoctorJ notes from https://github.com/asciidoctor/asciidoctorj  there is no jar, etc download for it only shows as:

org.asciidoctor  asciidoctorj-pdf  1.5.0-alpha.6

so no joy there yet


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/PDF-s-from-asciidoctor-pdf-ruby-gem-tp2715.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Ted
Reply | Threaded
Open this post in threaded view
|

Re: PDF's from asciidoctor-pdf ruby gem ?

Ted
In reply to this post by jnorthr
This is currently working very well. It uses Ruby:

How to Convert AsciiDoc to PDF with Asciidoctor



- Ted @TedAtCIS
Reply | Threaded
Open this post in threaded view
|

Re: PDF's from asciidoctor-pdf ruby gem ?

davidgamba
How do you use asciidoctor-pdf using the ruby API?

With the asciidoctor command I can run:

asciidoctor -b pdf -r asciidoctor-pdf file.adoc

With the API I am trying to set:

    adoc_options[:attributes]["backend"] = 'pdf'
    adoc_options[:requires] = ['asciidoctor-pdf']
    doc = Asciidoctor.load_file options[:file], adoc_options

But I get the following error:

/home/david/.rvm/gems/ruby-2.2.0/gems/asciidoctor-1.5.2/lib/asciidoctor/document.rb:1016:in `convert': asciidoctor: FAILED: missing converter for backend 'pdf'. Processing aborted. (RuntimeError)

I get the same error when trying to set "requires" pointing to my local copy of asciidoctor-pdf.

Any ideas? The asciidoctor-pdf gem is installed and properly used when calling the script from the command line.

Thanks,
Reply | Threaded
Open this post in threaded view
|

Re: PDF's from asciidoctor-pdf ruby gem ?

Robert.Panzer
Just tried with
asciidoctor 1.5.2
asciidoctor-pdf 1.5.0.alpha.6
on JRuby 1.7.13 on Win7 and the following script worked fine for me:

require 'asciidoctor'
require 'asciidoctor-pdf'
Asciidoctor.convert_file 'test.ad', :backend => 'pdf'

Could you check if that works for you as well?

Best regards,
Robert
Reply | Threaded
Open this post in threaded view
|

Re: PDF's from asciidoctor-pdf ruby gem ?

mojavelinux
Administrator
As Robert pointed out, you need to require the library explicitly when using the API. The required option is only processed by the cli (asciidoctor command), not in the API itself. You get an error because asciidoctor-pdf was never required.


Cheers,

-Dan

On Tue, Mar 31, 2015 at 9:05 AM, Robert.Panzer [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Just tried with
asciidoctor 1.5.2
asciidoctor-pdf 1.5.0.alpha.6
on JRuby 1.7.13 on Win7 and the following script worked fine for me:

require 'asciidoctor'
require 'asciidoctor-pdf'
Asciidoctor.convert_file 'test.ad', :backend => 'pdf'

Could you check if that works for you as well?

Best regards,
Robert


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/PDF-s-from-asciidoctor-pdf-ruby-gem-tp2715p2883.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

Re: PDF's from asciidoctor-pdf ruby gem ?

davidgamba
Thanks guys,

I am almost there:

    require 'asciidoctor'
    require 'asciidoctor-pdf'
    adoc_options[:attributes]["backend"] = 'pdf'
    doc = Asciidoctor.load_file options[:file], adoc_options
    Check_document.check_broken_references(doc)
    File.open("test.html", "w+") do |file|
        file.puts doc.render
    end

I need the doc object for some processing, like checking broken references, so using convert_file doesn't work for me.

The code above works for html but when the backend is pdf I get a file with:

less test.html
#<Asciidoctor::Pdf::Converter:0x0000000190dbd8>

How do I render from the doc object into the pdf file? I also tried this without luck.

    doc.render(:to_file => "test2.pdf")

Thanks,

--David

On Tue, Mar 31, 2015 at 7:16 AM, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> wrote:
As Robert pointed out, you need to require the library explicitly when using the API. The required option is only processed by the cli (asciidoctor command), not in the API itself. You get an error because asciidoctor-pdf was never required.


Cheers,

-Dan

On Tue, Mar 31, 2015 at 9:05 AM, Robert.Panzer [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Just tried with
asciidoctor 1.5.2
asciidoctor-pdf 1.5.0.alpha.6
on JRuby 1.7.13 on Win7 and the following script worked fine for me:

require 'asciidoctor'
require 'asciidoctor-pdf'
Asciidoctor.convert_file 'test.ad', :backend => 'pdf'

Could you check if that works for you as well?

Best regards,
Robert


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/PDF-s-from-asciidoctor-pdf-ruby-gem-tp2715p2883.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/PDF-s-from-asciidoctor-pdf-ruby-gem-tp2715p2888.html
To unsubscribe from PDF's from asciidoctor-pdf ruby gem ?, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: PDF's from asciidoctor-pdf ruby gem ?

mojavelinux
Administrator

On Tue, Mar 31, 2015 at 7:13 PM, davidgamba [via Asciidoctor :: Discussion] <[hidden email]> wrote:
File.open("test.html", "w+") do |file|
        file.puts doc.render
    end

You need to use render_file, then it should sort out the extension properly.

doc.render_file target

You can see where this is done in Asciidoctor PDF internals.


That file holds the key info you probably need :)

Reply | Threaded
Open this post in threaded view
|

Re: PDF's from asciidoctor-pdf ruby gem ?

mojavelinux
Administrator
In reply to this post by davidgamba
Note that render_file is a Prawn API, not an Asciidoctor API. The converter is both a Prawn Document and an Asciidoctor Converter object.

-Dan

On Tue, Mar 31, 2015 at 8:22 PM, Dan Allen <[hidden email]> wrote:

On Tue, Mar 31, 2015 at 7:13 PM, davidgamba [via Asciidoctor :: Discussion] <[hidden email]> wrote:
File.open("test.html", "w+") do |file|
        file.puts doc.render
    end

You need to use render_file, then it should sort out the extension properly.

doc.render_file target

You can see where this is done in Asciidoctor PDF internals.


That file holds the key info you probably need :)




--
Reply | Threaded
Open this post in threaded view
|

Re: PDF's from asciidoctor-pdf ruby gem ?

davidgamba
Thanks, I got it by running by using:

  if options[:pdf]
    puts doc.convert.render_file output_file
  else
    File.open(output_file, "w+") do |file|
      file.puts doc.render
    end
  end

As you can see, I had to use doc.convert to be able to access the pdf_doc methods.

Thanks for your help!

--David

On Tue, Mar 31, 2015 at 12:23 PM, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Note that render_file is a Prawn API, not an Asciidoctor API. The converter is both a Prawn Document and an Asciidoctor Converter object.

-Dan

On Tue, Mar 31, 2015 at 8:22 PM, Dan Allen <[hidden email]> wrote:

On Tue, Mar 31, 2015 at 7:13 PM, davidgamba [via Asciidoctor :: Discussion] <[hidden email]> wrote:
File.open("test.html", "w+") do |file|
        file.puts doc.render
    end

You need to use render_file, then it should sort out the extension properly.

doc.render_file target

You can see where this is done in Asciidoctor PDF internals.


That file holds the key info you probably need :)




--



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/PDF-s-from-asciidoctor-pdf-ruby-gem-tp2715p2898.html
To unsubscribe from PDF's from asciidoctor-pdf ruby gem ?, click here.
NAML