Problems with PDF theming (undefined method `unpack' for nil:NilClass)

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

Problems with PDF theming (undefined method `unpack' for nil:NilClass)

Alex
Hello,

I'm experiencing issues when I try to theme the PDF output. I'm aware that pdf styling is in alpha status but I'm afraid that I am doing something  fundamentally wrong.

You can access my test project from here:
https://github.com/alexanderklein/adoc-pdf-styling-test


I understood that it was currently necessary to start with the basic theme provided here:
https://github.com/asciidoctor/asciidoctor-pdf/blob/master/data/themes/default-theme.yml

So I copied this file to [my-project]/src/docs/resources/themes/basic-theme.yml

My build.gradle file looks like this:

buildscript {
  repositories {
    jcenter()
  }

  dependencies {
    classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
      classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.10'
  }
}

task debug {
  doLast {
    println asciidoctor.outputDir
  }
}

apply plugin: 'org.asciidoctor.convert'
asciidoctor {
  backends = ['pdf']
    attributes 'source-highlighter': 'coderay', 'pdf-fontsdir': '/Users/aklein/dev/adoc/pdf/src/resources/fonts', 'pdf-style': '/Users/aklein/dev/adoc/pdf/src/resources/themes/basic-theme.yml'
}

task wrapper(type: Wrapper) {
  gradleVersion = '2.9'
}
defaultTasks = ['asciidoctor']


(Obviously you will need to modify the absolute paths when trying to reproduce but I sticked with absolute paths since it is a recommendation in the documentation and the project is in alpha status where I consider recommendations as rules).

When my fonts directory [my-project]/src/docs/resources/fonts/ is empty, I get the following error message:
➜  pdf  ./gradlew asciidoctor
:asciidoctor
(ArgumentError) /Users/aklein/dev/adoc/pdf/src/resources/fonts/notoserif-regular-subset.ttf not found
:asciidoctor FAILED

That makes sense to me as there are not fonts in my fonts directory. So I downloaded all fonts from here:
https://github.com/asciidoctor/asciidoctor-pdf/tree/master/data/fonts

When I then try to convert the document, I get the this error message:
  pdf  ./gradlew asciidoctor
:asciidoctor
(NoMethodError) undefined method `unpack' for nil:NilClass
:asciidoctor FAILED

And here, I'm lost because of my lack of familarity with the Ruby language. However, I don't think that this is a Gradle or asciidoctorj-pdf issue because I get a very similar (or the same) error message when I try to convert the document with the Ruby Gem directly:

➜  pdf  asciidoctor-pdf src/docs/asciidoc/test.adoc -a pdf-style=/Users/aklein/dev/adoc/pdf/src/resources/themes/basic-theme.yml -a pdf-fontsdir=/Users/aklein/dev/adoc/pdf/src/resources/fonts
undefined method `unpack' for nil:NilClass

It does work well when I use other fonts (e.g Open Sans) but then Callouts are not rendered. So this does not help.

This being said, I'm already failing when I try to create a PDF document using the basic theme as long as I specifically declare it (I'm doing this because I would then like to start modifying the basic theme in order to create one that fits my needs more).

Any help would be highly appreciated.

Many thanks, Alex

Reply | Threaded
Open this post in threaded view
|

Re: Problems with PDF theming (undefined method `unpack' for nil:NilClass)

Jeremie Bresson
This post was updated on .
I was also experimenting with the new versions of Asciidoctorj using the maven examples as playground.

I have seen a similar error: "(NoMethodError) undefined method `activate' for nil:NilClass"
C:\Users\jbr\git\asciidoctor-maven-examples\asciidoctor-pdf-example>mvn
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Asciidoctor PDF Maven example 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- asciidoctor-maven-plugin:1.5.2.1:process-asciidoc (generate-pdf-doc) @ asciidoctor-pdf-example ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.959 s
[INFO] Finished at: 2015-12-10T18:56:26+01:00
[INFO] Final Memory: 73M/989M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.asciidoctor:asciidoctor-maven-plugin:1.5.2.1:process-asciidoc (generate-pdf-doc) on project asciidoctor-pdf-example: Execution generate-pdf-doc of goal org.asciidoctor:asciidoctor-maven-plugin:1.5.2.1:process-asciidoc failed: (NoMethodError) undefined method `activate' for nil:NilClass -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

I solved it by using:
<asciidoctor.maven.plugin.version>1.5.2.1</asciidoctor.maven.plugin.version>
<asciidoctorj.pdf.version>1.5.0-alpha.10.1</asciidoctorj.pdf.version>
<asciidoctorj.version>1.5.3.2</asciidoctorj.version>
<jruby.version>9.0.4.0</jruby.version>

I hope it helps you.
PS: for the maven examples, I am preparing a pull request. See this discussion.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with PDF theming (undefined method `unpack' for nil:NilClass)

mojavelinux
Administrator
In reply to this post by Alex
> You can access my test project from here: 

I can't emphasize how helpful it is to provide a sample project.

You need to specify the path to the theme file as follows:

asciidoctor {
  backends = ['pdf']
  attributes 'source-highlighter': 'coderay', 'pdf-style': file('src/resources/themes/basic-theme.yml')
}

If you use a relative path (e.g., src/resources/themes/basic-theme.yml), it will be resolved relative to the src/docs/asciidoc directory (since that is the base directory set for Asciidoctor). The file() function is the quickest way to get it to resolve an absolute path relative to the project.

You don't have to provide fonts if you use the built-in fonts (Noto Serif, etc). You only need to specify fonts if you are using different fonts (even if you are just adding a font).

I also strongly encourage you to use the following version of AsciidoctorJ PDF:

classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.10.1'

Notice the ".1" at the end. The "1.5.0-alpha.10" version was not a clean release.

Cheers,

-Dan

On Thu, Dec 10, 2015 at 9:20 AM, Alex [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hello,

I'm experiencing issues when I try to theme the PDF output. I'm aware that pdf styling is in alpha status but I'm afraid that I am doing something  fundamentally wrong.

You can access my test project from here:
https://github.com/alexanderklein/adoc-pdf-styling-test


I understood that it was currently necessary to start with the basic theme provided here:
https://github.com/asciidoctor/asciidoctor-pdf/blob/master/data/themes/default-theme.yml

So I copied this file to [my-project]/src/docs/resources/themes/basic-theme.yml

My build.gradle file looks like this:

buildscript {
  repositories {
    jcenter()
  }

  dependencies {
    classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
      classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.10'
  }
}

task debug {
  doLast {
    println asciidoctor.outputDir
  }
}

apply plugin: 'org.asciidoctor.convert'
asciidoctor {
  backends = ['pdf']
    attributes 'source-highlighter': 'coderay', 'pdf-fontsdir': '/Users/aklein/dev/adoc/pdf/src/resources/fonts', 'pdf-style': '/Users/aklein/dev/adoc/pdf/src/resources/themes/basic-theme.yml'
}

task wrapper(type: Wrapper) {
  gradleVersion = '2.9'
}
defaultTasks = ['asciidoctor']


(Obviously you will need to modify the absolute paths when trying to reproduce but I sticked with absolute paths since it is a recommendation in the documentation and the project is in alpha status where I consider recommendations as rules).

When my fonts directory [my-project]/src/docs/resources/fonts/ is empty, I get the following error message:
➜  pdf  ./gradlew asciidoctor
:asciidoctor
(ArgumentError) /Users/aklein/dev/adoc/pdf/src/resources/fonts/notoserif-regular-subset.ttf not found
:asciidoctor FAILED

That makes sense to me as there are not fonts in my fonts directory. So I downloaded all fonts from here:
https://github.com/asciidoctor/asciidoctor-pdf/tree/master/data/fonts

When I then try to convert the document, I get the this error message:
  pdf  ./gradlew asciidoctor
:asciidoctor
(NoMethodError) undefined method `unpack' for nil:NilClass
:asciidoctor FAILED

And here, I'm lost because of my lack of familarity with the Ruby language. However, I don't think that this is a Gradle or asciidoctorj-pdf issue because I get a very similar (or the same) error message when I try to convert the document with the Ruby Gem directly:

➜  pdf  asciidoctor-pdf src/docs/asciidoc/test.adoc -a pdf-style=/Users/aklein/dev/adoc/pdf/src/resources/themes/basic-theme.yml -a pdf-fontsdir=/Users/aklein/dev/adoc/pdf/src/resources/fonts
undefined method `unpack' for nil:NilClass

It does work well when I use other fonts (e.g Open Sans) but then Callouts are not rendered. So this does not help.

This being said, I'm already failing when I try to create a PDF document using the basic theme as long as I specifically declare it (I'm doing this because I would then like to start modifying the basic theme in order to create one that fits my needs more).

Any help would be highly appreciated.

Many thanks, Alex




If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Problems-with-PDF-theming-undefined-method-unpack-for-nil-NilClass-tp4054.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | http://google.com/profiles/dan.j.allen
Reply | Threaded
Open this post in threaded view
|

Re: Problems with PDF theming (undefined method `unpack' for nil:NilClass)

mojavelinux
Administrator
In reply to this post by Jeremie Bresson


I have seen the exact same error:

This appears to be a different error, though certainly worth fixing.

Do you know which part of your fix actually fixes the problem?

-Dan


--
Dan Allen | @mojavelinux | http://google.com/profiles/dan.j.allen
Reply | Threaded
Open this post in threaded view
|

Re: Problems with PDF theming (undefined method `unpack' for nil:NilClass)

Jeremie Bresson
mojavelinux wrote
This appears to be a different error, though certainly worth fixing.
Yes I was to quick. They look similar but are not the same:
* "undefined method `activate' for nil:NilClass"
* "undefined method `unpack' for nil:NilClass".

I could reproduce it with:
        <asciidoctorj.pdf.version>1.5.0-alpha.9</asciidoctorj.pdf.version>
        <asciidoctorj.version>1.5.3.2</asciidoctorj.version>

I my opinion this is not a big deal, because both dependencies should be updated to the latest version...

Sorry for the noise in this thread.
Reply | Threaded
Open this post in threaded view
|

Re: Problems with PDF theming (undefined method `unpack' for nil:NilClass)

Alex
Thank you both for the fast reply. That was amazingly quick.

Dan, I'm a bit closer to get this work. But  I'm not yet there :-(

I've updated org.asciidoctor:asciidoctorj-pdf to version 1.5.0.alpha.10.1
Also, I've changed the paths in the build file according to your recommendation:

    attributes 'source-highlighter': 'coderay',
    'pdf-fontsdir': file('src/resources/fonts'),
    'pdf-style': file('src/resources/themes/basic-theme.yml')

I can now produce a document, when I delete the pdf-fontsdir from the gradle file. But I get error messages about missing font files when I leave the pdf-fontsdir in the gradle file and just empty the physical directory on my disc:

➜  adoc-pdf-styling-test git:(master) ✗ grad
:asciidoctor
(ArgumentError) /Users/aklein/dev/adoc/adoc-pdf-styling-test/src/resources/fonts/notoserif-regular-subset.ttf not found
:asciidoctor FAILED

and when I put the fonts back in, I still get the error message from my initial message:

➜  adoc-pdf-styling-test git:(master) ✗ grad
:asciidoctor
(NoMethodError) undefined method `unpack' for nil:NilClass
:asciidoctor FAILED

My problem is, that I would like to use the M+ 1mn font for source code as it contains glyphs for the Callout icons. And other fonts for headlines and paragraphs (that's why i need to have the pdf-fontsdir in my build file).
I've also updated my sample project on Github:
https://github.com/alexanderklein/adoc-pdf-styling-test

The current status there is that I moved all fonts into a temporary sub folder, so that they cannot be found.
So the error message is that the fonts cannot be found.

If you move them from the sub folder into the fonts folder directly, you should be able to see the other error message printed:

➜  adoc-pdf-styling-test git:(master) ✗ grad
:asciidoctor
(NoMethodError) undefined method `unpack' for nil:NilClass
:asciidoctor FAILED

Many thanks again.

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

Re: Problems with PDF theming (undefined method `unpack' for nil:NilClass)

mojavelinux
Administrator
I'm a bit closer to get this work. But  I'm not yet there :-(

You are very close, actually. Just a few more things to clear up and I think you'll have it.
 
I get error messages about missing font files when I leave the pdf-fontsdir in the gradle file and just empty the physical directory on my disc:

Correct. You either need to not specify the pdf-fontsdir and use the built-in fonts, or you need to specify the pdf-fontsdir and provide all the fonts. The two options are mutually exclusive.
 
I would like to use the M+ 1mn font for source code as it contains glyphs for the Callout icons. And other fonts for headlines and paragraphs (that's why i need to have the pdf-fontsdir in my build file).
I've also updated my sample project on Github:
https://github.com/alexanderklein/adoc-pdf-styling-test

Yep, that's the typical case for customization.


 

If you move them from the sub folder into the fonts folder directly, you should be able to see the other error message printed:

➜  adoc-pdf-styling-test git:(master) ✗ grad
:asciidoctor
(NoMethodError) undefined method `unpack' for nil:NilClass
:asciidoctor FAILED

This means the font files are corrupt (or have something in them that the font library can't read). When I compare the fonts in your repository with the fonts from Asciidoctor PDF, the binary files differ. So something happened when you copied them. Make sure that diff confirms that the files are the same.

For me, not even fontforge can open the font. So I think that is your underlying problem. I can assure you that your build.gradle file is now correct.

We probably need to fail more gracefully if a font file is corrupt. Though that may be something that should be fixed in Prawn instead of Asciidoctor PDF.

Cheers,

-Dan

--
Dan Allen | @mojavelinux | http://google.com/profiles/dan.j.allen
Reply | Threaded
Open this post in threaded view
|

Re: Problems with PDF theming (undefined method `unpack' for nil:NilClass)

mojavelinux
Administrator
In reply to this post by Alex
Btw, I'd really like to see a custom theme used in the https://github.com/asciidoctor/asciidoctor-gradle-examples so that it is easier to get started (even if it is just in the comments).

-Dan

On Fri, Dec 11, 2015 at 1:59 PM, Dan Allen <[hidden email]> wrote:
I'm a bit closer to get this work. But  I'm not yet there :-(

You are very close, actually. Just a few more things to clear up and I think you'll have it.
 
I get error messages about missing font files when I leave the pdf-fontsdir in the gradle file and just empty the physical directory on my disc:

Correct. You either need to not specify the pdf-fontsdir and use the built-in fonts, or you need to specify the pdf-fontsdir and provide all the fonts. The two options are mutually exclusive.
 
I would like to use the M+ 1mn font for source code as it contains glyphs for the Callout icons. And other fonts for headlines and paragraphs (that's why i need to have the pdf-fontsdir in my build file).
I've also updated my sample project on Github:
https://github.com/alexanderklein/adoc-pdf-styling-test

Yep, that's the typical case for customization.


 

If you move them from the sub folder into the fonts folder directly, you should be able to see the other error message printed:

➜  adoc-pdf-styling-test git:(master) ✗ grad
:asciidoctor
(NoMethodError) undefined method `unpack' for nil:NilClass
:asciidoctor FAILED

This means the font files are corrupt (or have something in them that the font library can't read). When I compare the fonts in your repository with the fonts from Asciidoctor PDF, the binary files differ. So something happened when you copied them. Make sure that diff confirms that the files are the same.

For me, not even fontforge can open the font. So I think that is your underlying problem. I can assure you that your build.gradle file is now correct.

We probably need to fail more gracefully if a font file is corrupt. Though that may be something that should be fixed in Prawn instead of Asciidoctor PDF.

Cheers,

-Dan

--
Dan Allen | @mojavelinux | http://google.com/profiles/dan.j.allen



--
Dan Allen | @mojavelinux | http://google.com/profiles/dan.j.allen
Reply | Threaded
Open this post in threaded view
|

Re: Problems with PDF theming (undefined method `unpack' for nil:NilClass)

Alex
In reply to this post by mojavelinux
Oh yes!

Thank you so much Dan,

I cloned your repository and copied the fonts locally to my project and it worked immediately. Of course, I feel a bit embarrassed as broken font files are obviously not an Asciidoctor problem. So, I appreciate your help even more.

I updated my repo on GitHub and will keep it there. Hoping that it might be sort of useful as a reference on how to set up a pdf "customization" project with Asciidoctor and Gradle.

Thanks again.

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

Re: Problems with PDF theming (undefined method `unpack' for nil:NilClass)

mojavelinux
Administrator
Great news! Thanks Alex!

Keeping the repository there will definitely be helpful to anyone coming through and reading this thread.

Cheers,

-Dan

On Sun, Dec 13, 2015 at 5:58 AM, Alex [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Oh yes!

Thank you so much Dan,

I cloned your repository and copied the fonts locally to my project and it worked immediately. Of course, I feel a bit embarrassed as broken font files are obviously not an Asciidoctor problem. So, I appreciate your help even more.

I updated my repo on GitHub and will keep it there. Hoping that it might be sort of useful as a reference on how to set up a pdf "customization" project with Asciidoctor and Gradle.

Thanks again.

Best regards, Alex


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Problems-with-PDF-theming-undefined-method-unpack-for-nil-NilClass-tp4054p4086.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Dan Allen | @mojavelinux | http://google.com/profiles/dan.j.allen