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

extension api for pdf backend #7

Closed TrashCoder96 closed 6 years ago

TrashCoder96 commented 7 years ago

is it possible to use extentions (for example, PostProcessor) in my own program, that uses asciidoctorj-pdf? i tried to do this (EndToEndPostProcessor is my own class):

public class DoctorRun {

    public static void main(String[] args) {
        Asciidoctor asciidoctor = create();
        asciidoctor.javaExtensionRegistry().postprocessor(new EndToEndPostProcessor(options().backend("pdf").asMap()));
        asciidoctor.convertFile(new File("D:\\\\rc-req-mb-client\\src\\main.adoc"), options().backend("pdf").get());
    }

}

and received following output (in IntelliJ IDEA):

"C:\Program Files\Java\jdk1.8.0_91\bin\java" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:61162,suspend=y,server=n -Djruby.aot.loadClasses=true -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_91\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\rt.jar;D:\asciidoctorprocessor\target\classes;C:\Users\itimofeev\.m2\repository\org\asciidoctor\asciidoctorj\1.5.6\asciidoctorj-1.5.6.jar;C:\Users\itimofeev\.m2\repository\org\jruby\jruby-complete\1.7.26\jruby-complete-1.7.26.jar;C:\Users\itimofeev\.m2\repository\com\beust\jcommander\1.35\jcommander-1.35.jar;C:\Users\itimofeev\.m2\repository\org\asciidoctor\asciidoctorj-pdf\1.5.0-alpha.11\asciidoctorj-pdf-1.5.0-alpha.11.jar;C:\Users\itimofeev\.m2\repository\org\jsoup\jsoup\1.8.3\jsoup-1.8.3.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 15.0.3\lib\idea_rt.jar" cz.bsc.asciidoctorprocessor.DoctorRun
Connected to the target VM, address: '127.0.0.1:61162', transport: 'socket'
Disconnected from the target VM, address: '127.0.0.1:61162', transport: 'socket'
авг 24, 2017 8:16:33 PM org.asciidoctor.internal.JRubyAsciidoctor renderFile
SEVERE: (NameError) no method 'process' for arguments (org.jruby.RubyObject,org.jruby.RubyObject) on Java::CzBscAsciidoctorprocessor::EndToEndPostProcessor
  available overloads:
    (org.asciidoctor.ast.Document,java.lang.String)
    (org.asciidoctor.ast.DocumentRuby,java.lang.String)
Exception in thread "main" org.asciidoctor.internal.AsciidoctorCoreException: org.jruby.exceptions.RaiseException: (NameError) no method 'process' for arguments (org.jruby.RubyObject,org.jruby.RubyObject) on Java::CzBscAsciidoctorprocessor::EndToEndPostProcessor
  available overloads:
    (org.asciidoctor.ast.Document,java.lang.String)
    (org.asciidoctor.ast.DocumentRuby,java.lang.String)
    at org.asciidoctor.internal.JRubyAsciidoctor.renderFile(JRubyAsciidoctor.java:347)
    at org.asciidoctor.internal.JRubyAsciidoctor.renderFile(JRubyAsciidoctor.java:436)
    at org.asciidoctor.internal.JRubyAsciidoctor.convertFile(JRubyAsciidoctor.java:556)
    at cz.bsc.asciidoctorprocessor.DoctorRun.main(DoctorRun.java:18)
Caused by: org.jruby.exceptions.RaiseException: (NameError) no method 'process' for arguments (org.jruby.RubyObject,org.jruby.RubyObject) on Java::CzBscAsciidoctorprocessor::EndToEndPostProcessor
  available overloads:
    (org.asciidoctor.ast.Document,java.lang.String)
    (org.asciidoctor.ast.DocumentRuby,java.lang.String)
    at org.jruby.RubyMethod.call(org/jruby/RubyMethod.java:124)
    at RUBY.convert(C:/Users/itimofeev/.m2/repository/org/asciidoctor/asciidoctorj/1.5.6/asciidoctorj-1.5.6.jar!/gems/asciidoctor-1.5.6.1/lib/asciidoctor/document.rb:1066)
    at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1613)
    at RUBY.convert(C:/Users/itimofeev/.m2/repository/org/asciidoctor/asciidoctorj/1.5.6/asciidoctorj-1.5.6.jar!/gems/asciidoctor-1.5.6.1/lib/asciidoctor/document.rb:1065)
    at RUBY.convert(C:/Users/itimofeev/.m2/repository/org/asciidoctor/asciidoctorj/1.5.6/asciidoctorj-1.5.6.jar!/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1502)
    at RUBY.convert_file(C:/Users/itimofeev/.m2/repository/org/asciidoctor/asciidoctorj/1.5.6/asciidoctorj-1.5.6.jar!/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1575)
    at org.jruby.RubyIO.open(org/jruby/RubyIO.java:1201)
    at RUBY.convert_file(C:/Users/itimofeev/.m2/repository/org/asciidoctor/asciidoctorj/1.5.6/asciidoctorj-1.5.6.jar!/gems/asciidoctor-1.5.6.1/lib/asciidoctor.rb:1575)
    at RUBY.convertFile(<script>:75)
    at org.jruby.gen.InterfaceImpl1333197270.convertFile(org/jruby/gen/InterfaceImpl1333197270.gen:13)

Process finished with exit code 1

How to fix it? What is wrong?

robertpanzer commented 7 years ago

Hi,

Postprocessors are currently not supported for the PDF backend. The result of the PDF backend is the converter itself – a Ruby object – instead of the generated string as you have it with for example with the HTML5 backend.

All other processors should work though (from the top of my head). E.g. Preprocessors, Macros, Treeprocessors should work like with every other backend, only the Postprocessor is an exception.