Closed jenskelkel closed 1 year ago
Can you please give some details on the versions of asciidoctorj and asciidoctorj-pdf that you were using?
Here my pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>com.jenskelkel.test</groupId>
<artifactId>asciidoc</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.11</java.version>
<maven.compiler.source>1.11</maven.compiler.source>
<maven.compiler.target>1.11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctorj-pdf</artifactId>
<version>1.5.0-beta.8</version>
</dependency>
</dependencies>
Yes, that won’t work. PDF is not necessarily a string, therefore it doesn’t make much sense to convert into a StringWriter. If you want to have the pdf in memory please use the option to_stream with a ByteArrayOutputStream instead: https://github.com/asciidoctor/asciidoctorj/blob/master/asciidoctorj-api/src/main/java/org/asciidoctor/OptionsBuilder.java
I see that the API is a bit misleading here, but currently passing in a StringWriter can only be used for backends producing „plain text“ like HTML, docbook etc
You can also find an example for this here: https://github.com/asciidoctor/asciidoctorj/blob/master/asciidoctorj-distribution/src/test/groovy/org/asciidoctor/diagram/WhenAPdfDocumentIsRenderedToStream.groovy
Thanks, the OptionBuilder.toStream was the puzzle that I am missing.
I understand the question is resolved. If not, feel free to address further questions to chat.asciidoctor.org
Try to creat e PDF from Java. If I use the convert Method I get null as result. The convertFile Methode trow an Exception
Exception in thread "main" org.asciidoctor.jruby.internal.AsciidoctorCoreException: org.jruby.exceptions.TypeError: (TypeError) cannot convert instance of class org.jruby.gen.RubyObject50 to class java.lang.String at org.asciidoctor.jruby.internal.JRubyAsciidoctor.convert(JRubyAsciidoctor.java:318) at org.asciidoctor.jruby.internal.JRubyAsciidoctor.convert(JRubyAsciidoctor.java:281) at org.asciidoctor.jruby.internal.JRubyAsciidoctor.convert(JRubyAsciidoctor.java:350) at App.main(App.java:24) Caused by: org.jruby.exceptions.TypeError: (TypeError) cannot convert instance of class org.jruby.gen.RubyObject50 to class java.lang.String
Here my simple Sourcecode:
public static void main(String[] args) throws IOException { Asciidoctor asciidoctor= Asciidoctor.Factory.create(); File file=new File("C:/temp/test.adoc");
Perhaps someone know the solution
Thanks.
Jens