无法包含

时间:2016-06-07 12:19:13

标签: image asciidoc asciidoctor

我写了一个包含以下结构的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

我看起来好像这一代人没有照顾这些路径......

有人可以帮助我吗?

的Th。

1 个答案:

答案 0 :(得分: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存储库并更新系统

需要用于企业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
...
...

安装prawn-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

现在,我们可以使用创建的asciidoctor-pdf容器,其中描述了.png支持 如下:

启动容器

$ 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

[提示] 这并不是真正的asciidoctor问题。 Asciidoctor能够将asciidoc格式的文档(包括png文件)转换为html。将带有png文件的asciidoc文档转换为pdf时,似乎您需要prawn-magick的其他库。大虾魔术师需要Graphicks Magick。安装了Prawn Magick之后,将满足所有依赖关系,以将.adoc直接转换为.pdf。

礼物

相关问题