0

我写了一个包含包含和以下结构的 asciidoctor 文档:

/mydoc.adocs
/chap1/
/chap1/chap1.adoc
/chap1/sections/
/chap1/sections/section1.adoc
/chap1/images/
/chap1/images/myimg.png
/img/
/img/...some other images here

我使用以下命令生成我的 PDF:

asciidoctor-pdf -b pdf mydoc.adoc

mydoc.adoc 看起来像这样:

:doctype: book
:encoding: utf-8
:imagesdir: img

= My life...
Thierry <thierry@mywebsite.com>

include::chap1/chap1.adoc[]

chap1.adoc 看起来像这样:

[[_Chap1]]
== Foo
include::sections/section1.adoc[]

最后 section1.adoc 看起来像这样:

=== Bla bla
image::../images/myimg.png[label]

如果我为 section1.adoc (asciidoctor-pdf -b pdf section1.adoc) 生成 PDF,它将包含图像。但是,如果我从根目录生成 mydoc.adoc (asciidoctor-pdf -b pdf mydoc.adoc) 的 PDF,则它不包含图像。

我收到以下错误:

asciidoctor: WARNING: image to embed not found or not readable: C:/myproject/images/myimg.png

我看起来好像这一代人不关心路径......

有人能帮我吗 ?

钍。

4

1 回答 1

0

不幸的是,您的请求有点老了,但我遇到了同样的问题并解决了如下问题。我正在运行 Ubuntu 20.04,但安装了 podman 并使用 CentOS7 容器在其中安装 asciidoctor-pdf。所以你必须选择任何能够运行容器的操作系统。

安装 dockerized asciidoctor-pdf(带有 .png-support)

asciidoctor-pdf 和官方 docker hub 镜像的标准安装不支持使用 .png 文件将 .adoc 转换为 .pdf。你会得到一个错误。在示例中,我尝试将 service-documentation.adoc 转换为 service-documentation.pdf:

$ podman run --rm -v $(pwd):/documents/ asciidoctor/docker-asciidoctor asciidoctor-pdf service-documentation.adoc 
Trying to pull docker.io/asciidoctor/docker-asciidoctor...
Getting image source signatures
Copying blob 85a3f8045a5f done  
Copying blob 6cf8cbf780aa done  
Copying blob c9b1b535fdd9 done  
Copying blob 07903a9ac4b8 done  
Copying blob 102cbf696e41 done  
Copying config 0c383e26e3 done  
Writing manifest to image destination
Storing signatures

asciidoctor: WARNING: could not embed image: image.png; PNG uses unsupported interlace method; install prawn-gmagick gem to add support
asciidoctor: 

准备容器

我正在使用 podman 创建所需的容器

运行 CentOS7 容器

我正在使用来自 docker.io 的 CentOS7 容器在其中安装 asciidoctor-pdf:

podman run -ti --name asciidoctor-pdf -v $(pwd):/data centos:centos7 /bin/bash

安装 epel repo 并更新系统

需要企业级 Linux 的 Etra 包,所以使用以下命令安装 yum repu:

$ yum install epel-release -y 
$ yum update -y 

安装红宝石

Asciidoctor 使用 ruby​​,安装 ruby​​:

$ yum install which git wget -y
$ curl -L get.rvm.io |bash -s stable
$ gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
$ curl -L get.rvm.io |bash -s stable
$ source /etc/profile.d/rvm.sh
$ rvm reload
$ rvm requirements run
$ rvm install 2.6
$ ruby -v

ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]

安装 asciidoctor-pdf

现在可以使用以下命令安装没有完全 .png 支持的 Asciidoctor:

$ gem install asciidoctor-pdf --pre
$ asciidoctor-pdf -v

Asciidoctor PDF 1.5.3 using Asciidoctor 2.0.10 [https://asciidoctor.org]
Runtime Environment (ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]) (lc:US-ASCII fs:US-ASCII in:US-ASCII ex:US-ASCII)

安装 Graphics Magick(用于 prawn-gmagick)

为了支持 .png 文件,我们需要 gem prawn-gmagick。对此的要求是图形魔术。使用以下命令安装它:

$ yum install GraphicsMagick-c++ GraphicsMagick-devel libpng libjpeg libpng-devel ghostscript libtiff libtiff-devel freetype freetype-devel jasper jasper-devel -y
$ mkdir ~/temp
$ cd ~/temp
$ wget ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/GraphicsMagick-LATEST.tar.gz
$ tar xvzf GraphicsMagick-LATEST.tar.gz 
$ cd GraphicsMagick-1.3.35/
$ ./configure
$ make install
$ gm version

GraphicsMagick 1.3.35 2020-02-23 Q8 http://www.GraphicsMagick.org/
Copyright (C) 2002-2020 GraphicsMagick Group.
Additional copyrights and licenses apply to this software.
See http://www.GraphicsMagick.org/www/Copyright.html for details.

Feature Support:
  Native Thread Safe         yes
  Large Files (> 32 bit)     yes
  Large Memory (> 32 bit)    yes
  BZIP                       no
  DPS                        no
  FlashPix                   no
  FreeType                   yes
  Ghostscript (Library)      no
  JBIG                       no
  JPEG-2000                  yes
  JPEG                       yes
  Little CMS                 no
  Loadable Modules           no
  Solaris mtmalloc           no
  Google perftools tcmalloc  no
  OpenMP                     yes (201107 "3.1")
  PNG                        yes
  TIFF                       yes
  TRIO                       no
  Solaris umem               no
  WebP                       no
  WMF                        no
  X11                        no
  XML                        no
  ZLIB                       yes
...
...

安装 praw-gmagick

现在我们可以继续使用以下命令安装 gem prawn-gmagick:

$ gem install prawn-gmagick

Fetching prawn-gmagick-0.0.9.gem
Building native extensions. This could take a while...
Successfully installed prawn-gmagick-0.0.9
Parsing documentation for prawn-gmagick-0.0.9
Installing ri documentation for prawn-gmagick-0.0.9
Done installing documentation for prawn-gmagick after 0 seconds
1 gem installed

设置完成,退出容器:

[root@4e5f3c876eb5 GraphicsMagick-1.3.35]# exit
exit
user@hostname-linux:~/git/service-docs$

运行 asciidoctor-pdf

现在我们可以使用我们创建的带有 .png 支持的 asciidoctor-pdf 容器,如下所示:

启动容器

$ podman start asciidoctor-pdf
$ podman exec -ti asciidoctor-pdf /bin/bash

将 .adoc 转换为 .pdf

将 .adoc 转换为 .pdf:

asciidoctor-pdf file.adoc -o /data/file.pdf

退出容器:

[root@4e5f3c876eb5 GraphicsMagick-1.3.35]# exit
exit
user@hostname-linux:~/git/service-docs$

[提示] 转换后的文件位于 cwd 中。

user@hostname-linux:~/git/service-docs$ ls -la 

total 748
...
-rw-r--r-- 1 user user 744314 Mai  2 13:40 file.pdf

[TIP] 这其实不是 asciidoctor 的问题。Asciidoctor 能够将带有 png 文件的 asciidoc 格式的文档转换为 html。将带有 png 文件的 asciidoc 文档转换为 pdf 时,您似乎需要来自 prawn-magick 的其他库。Prawn Magick 需要 Graphicks Magick。安装 Prawn Magick 后,所有依赖项都已完成,可以将 .adoc 直接转换为 .pdf。

问候

于 2020-05-02T18:13:27.343 回答