asciidoctor / asciidoctorj-pdf

AsciidoctorJ PDF bundles the Asciidoctor PDF RubyGem (asciidoctor-pdf) so it can be loaded into the JVM using JRuby.
Apache License 2.0
36 stars 17 forks source link

AsciidoctorJ does not detect asciidoctorj-pdf correctly #17

Closed jonathanday930 closed 5 years ago

jonathanday930 commented 6 years ago

Here is my gradle.build script:

group 'doc'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.jruby', name: 'jruby-complete', version: '9.1.16.0'
    compile group: 'org.asciidoctor', name: 'asciidoctorj', version: '1.5.6'
    compile group: 'org.asciidoctor', name: 'asciidoctorj-pdf', version: '1.5.0-alpha.16'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Whenever I run convertDirectory, and have the backend set to html, it works. However, when I set backend to pdf, I get this:

Jul 30, 2018 11:37:11 AM org.asciidoctor.internal.JRubyAsciidoctor renderFile
SEVERE: (NotImplementedError) asciidoctor: FAILED: missing converter for backend 'pdf'. Processing aborted.
Exception in thread "main" org.asciidoctor.internal.AsciidoctorCoreException: org.jruby.exceptions.RaiseException: (NotImplementedError) asciidoctor: FAILED: missing converter for backend 'pdf'. Processing aborted.
    at org.asciidoctor.internal.JRubyAsciidoctor.renderFile(JRubyAsciidoctor.java:347)
    at org.asciidoctor.internal.JRubyAsciidoctor.renderAllFiles(JRubyAsciidoctor.java:405)
    at org.asciidoctor.internal.JRubyAsciidoctor.renderDirectory(JRubyAsciidoctor.java:396)
    at org.asciidoctor.internal.JRubyAsciidoctor.convertDirectory(JRubyAsciidoctor.java:566)
    at Main.main(Main.java:72)
Caused by: org.jruby.exceptions.RaiseException: (NotImplementedError) asciidoctor: FAILED: missing converter for backend 'pdf'. Processing aborted.
    at RUBY.update_backend_attributes(uri:classloader:/gems/asciidoctor-1.5.6.1/lib/asciidoctor/document.rb:953)
    at RUBY.initialize(uri:classloader:/gems/asciidoctor-1.5.6.1/lib/asciidoctor/document.rb:414)
    at RUBY.load(uri:classloader:/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1341)
    at RUBY.convert(uri:classloader:/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1457)
    at RUBY.block in convert_file(uri:classloader:/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1575)
    at org.jruby.RubyIO.open(org/jruby/RubyIO.java:1171)
    at RUBY.convert_file(uri:classloader:/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1575)
    at RUBY.convertFile(<script>:75)

Anyone have any ideas on what this could be? It looks like asciidoctorJ isnt finding asciidoctorJ-pdf, but I dont know why.

robertpanzer commented 6 years ago

Hi Jonathan,

Do you have a sample project to clone?

jonathanday930 commented 6 years ago

No, but I got it to work!

I used to convert files with this code:

public static void main(String[] args) {
       Asciidoctor asciidoct= Asciidoctor.Factory.create();
Map<String, Object> attributes =new HashMap<>();
        attributes.put("backend", "pdf");
        attributes.put("toc", "left");

       Map<String, Object> options = options().safe(SafeMode.SAFE).asMap();
        options.put("attributes", attributes);
        options.put("in_place", true);
String[] res = asciidoct.convertDirectory(
                new AsciiDocDirectoryWalker("C:\\Users\\Intern1\\documentation\\asciidoctor"),
               options);
        System.out.println("done");
}

but now I can convert PDFs by using this code:

public static void main(String[] args) {
       Asciidoctor asciidoct= Asciidoctor.Factory.create();
        Options options = new Options();
        options.setBackend("html");
        options.setSafe(SafeMode.SAFE);

       String[] res = asciidoct.convertDirectory(
                new AsciiDocDirectoryWalker("C:\\Users\\Intern1\\documentation\\asciidoctor"),
               options);
        System.out.println("done");

    }

}

It looks like there is an error with options somewhere when I configured the options manually. Using the first implementation, I was able to generate HTML but not pdfs. In the second, I can generate both.

robertpanzer commented 6 years ago

It looks a bit strange that in the upper example you're setting the attribute backend to pdf while it must be the option like you did in the second example. Can you please try using the option?

robertpanzer commented 5 years ago

Looks like this is solved and can be closed.