오픈소스

adoc pdf로 변환하는 방법 (rvm&ruby 설치하기)- adoc to pdf with rvm&ruby

토끼C 2023. 6. 30. 20:00
반응형

adoc pdf로 변환하는 방법 (rvm&ruby 설치하기)- adoc to pdf with rvm&ruby

안녕하세요, 오늘은 adoc 파일을 pdf로 변환하는 방법에 대해 소개하고자 합니다.

adoc 확장자는 AsciiDoc언어로 작성된 파일을 의미하고, Asciidoc은 경량 마크다운 언어입니다!

오늘은 Asciidoctor라는 프로세서를 활용하여 adoc 파일을 pdf로 변환해보겠습니다.

 

목차
1. rvm & ruby 설치
2. asciidoctor 설치
3. coderay 설치
4. asciidoctor-pdf 설치
5. asciidoctor-pdf-cjk-kai_gen_gothic 설치
6. pdf로 변환하기

 

 

1. rvm & ruby 설치

ruby를 설치하는 방법은 약 3가지 정도가 있는데, apt install로 할 경우 2.3.1버전으로 다운 가능하다. apt list ruby 명령어를 실행하면 설치 가능한 패키지가 조회되는데, 글을 작성하는 시점 기준으로는 2.3.1밖에 없었다. 2.3.1버전으로 진행하니, 버전 관련 에러가 발생하여 rvm 으로 설치하는 방식으로 진행하였다.

 

버전 관련 에러는 coderay 설치 에러 해결하기에서 확인이 가능하다.

 

ERROR: Error installing pygments.rb: pygments.rb requires Ruby version >= 2.5.0. [coderay 설치 에러 해결하기]

2023.06.30 - [오픈소스] - adoc pdf로 변환하는 방법 (rvm&ruby 설치하기)- adoc to pdf with rvm&ruby adoc pdf로 변환하는 방법 (rvm&ruby 설치하기)- adoc to pdf with rvm&ruby adoc pdf로 변환하는 방법 (rvm&ruby 설치하기)- ado

tokkicine.tistory.com

 

 

ruby 설치를 위해 rvm을 먼저 설치한다.

 

curl -sSL https://get.rvm.io | bash -s stable --ruby

또는

apt-get install software-properties-common

apt-add-repository -y ppa:rael-gc/rvm

apt-get update
sudo apt-get install rvm

명령어를 사용하여 rvm을 설치한다.

 

root@LYJ:/# curl -k -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: Signature made 2021년 01월 15일 (금)  using RSA key ID 39499BDB
gpg: Can't check signature: public key not found
GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.12.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:

    gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

or if it fails:

    command curl -sSL https://rvm.io/mpapis.asc | gpg --import -
    command curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -

In case of further problems with validation please refer to https://rvm.io/rvm/security

 

이런 에러가 나오면 로그에 찍힌 대로

gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

를 실행해서 key를 만들면된다. (gpg가 없으면 apt-get install gpg2로 설치해준다.)

 

 

root@LYJ:/# gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: requesting key D39DC0E3 from hkp server keyserver.ubuntu.com
gpg: requesting key 39499BDB from hkp server keyserver.ubuntu.com
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key D39DC0E3: public key "Michal Papis (RVM signing) <mpapis@gmail.com>" imported
gpg: key 39499BDB: public key "Piotr Kuczynski <piotr.kuczynski@gmail.com>" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 2
gpg:               imported: 2  (RSA: 2)

 

 

curl -k -sSL https://get.rvm.io | bash -s stable

root@LYJ:/# curl -k -sSL https://get.rvm.io | bash -s stable 
Downloading https://github.com/rvm/rvm/archive/1.29.12.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.12/1.29.12.tar.gz.asc
gpg: Signature made 2021년 01월 15일 (금)  using RSA key ID 39499BDB
gpg: Good signature from "Piotr Kuczynski <piotr.kuczynski@gmail.com>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7D2B AF1C F37B 13E2 069D  6956 105B D0E7 3949 9BDB
GPG verified '/usr/local/rvm/archives/rvm-1.29.12.tgz'
Creating group 'rvm'
Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:

  * First you need to add all users that will be using rvm to 'rvm' group,
    and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.

  * To start using RVM you need to run `source /etc/profile.d/rvm.sh`
    in all your open shell windows, in rare cases you need to reopen all shell windows.
  * Please do NOT forget to add your users to the rvm group.
     The installer no longer auto-adds root or users to the rvm group. Admins must do this.
     Also, please note that group memberships are ONLY evaluated at login time.
     This means that users must log out then back in before group membership takes effect!
Thanks for installing RVM 🙏
Please consider donating to our open collective to help us maintain RVM.

👉  Donate: https://opencollective.com/rvm/donate

Ruby enVironment Manager 1.29.12 (latest) (c) 2009-2020 Michal Papis, Piotr Kuczynski, Wayne E. Seguin

Searching for binary rubies, this might take some time.
Found remote file https://rubies.travis-ci.org/ubuntu/16.04/x86_64/ruby-3.0.0.tar.bz2
Checking requirements for ubuntu.
Installing requirements for ubuntu.
Updating systemThere has been an error while updating your system using `apt-get`.
It seems that there are some 404 Not Found errors for repositories listed in:

    /etc/apt/sources.list
    /etc/apt/sources.list.d/*.list

Make sure that all repositories are available from your system and verify your setup by running manually:

    sudo apt-get update

Make sure that it works correctly before proceeding with RVM.

If you are working from the GUI instead of the terminal, you might want to verify and fix broken
repositories using "Software & Updates" application.

 

 

rvm 설치가 완료되었으면, 로그에 나온것처럼

source /etc/profile.d/rvm.sh 를 실행한다.

rvm reload 로 rvm을 다시 로드한다.

 

rvm version으로 설치된 버전을 확인할 수 있다.

root@LYJ:/# rvm version
rvm 1.29.12 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

 

 

rvm list known |grep ruby 로 설치 가능한 ruby 버전대 확인이 가능하다.

root@LYJ:/# rvm list known |grep ruby
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.10]
[ruby-]2.5[.8]
[ruby-]2.6[.6]
[ruby-]2.7[.2]
[ruby-]3[.0.0]

 

 

버전이 낮으면 adsciidoctor를 사용할 때 문제가 발생하므로

제일 높은 버전인 3.0.0 버전을 설치한다.

 

rvm install ruby-3.0.0

root@LYJ:/# rvm install ruby-3.0.0
Searching for binary rubies, this might take some time.
Found remote file https://rubies.travis-ci.org/ubuntu/16.04/x86_64/ruby-3.0.0.tar.bz2
Checking requirements for ubuntu.
Installing requirements for ubuntu.
Updating system..
Installing required packages: gawk, autoconf, automake, bison, libgdbm-dev, libsqlite3-dev, libyaml-dev, sqlite3, libreadline6-dev, libssl-dev...........
Requirements installation successful.
ruby-3.0.0 - #configure
ruby-3.0.0 - #download
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
100 22.6M  100 22.6M    0     0  2998k      0  0:00:07  0:00:07 --:--:-- 5305k
No checksum for downloaded archive, recording checksum in user configuration.
ruby-3.0.0 - #validate archive
ruby-3.0.0 - #extract
ruby-3.0.0 - #validate binary
ruby-3.0.0 - #setup
ruby-3.0.0 - #gemset created /usr/local/rvm/gems/ruby-3.0.0@global
ruby-3.0.0 - #importing gemset /usr/local/rvm/gemsets/global.gems..................................
ruby-3.0.0 - #generating global wrappers........
ruby-3.0.0 - #gemset created /usr/local/rvm/gems/ruby-3.0.0
ruby-3.0.0 - #importing gemsetfile /usr/local/rvm/gemsets/default.gems evaluated to empty gem list
ruby-3.0.0 - #generating default wrappers........

 

root@LYJ:/# rvm --default use ruby-3.0.0
Using /usr/local/rvm/gems/ruby-3.0.0

디폴트로 사용할 루비 버전을 3.0.0으로 지정한다

 

root@LYJ:/# ruby --version
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

루비가 3.0.0으로 설치된 것을 확인할 수 있다.

 

 

2. asciidoctor 설치

gem install asciidoctor

root@LYJ:~# gem install asciidoctor
Fetching: asciidoctor-2.0.20.gem (100%)
Successfully installed asciidoctor-2.0.20
Parsing documentation for asciidoctor-2.0.20
Installing ri documentation for asciidoctor-2.0.20
Done installing documentation for asciidoctor after 2 seconds
1 gem installed

 

3. coderay 설치

gem install coderay pygments.rb

root@LYJ:/# gem install coderay pygments.rb
Fetching coderay-1.1.3.gem
Successfully installed coderay-1.1.3
invalid options: -SNw2
(invalid options are ignored)
Parsing documentation for coderay-1.1.3
Installing ri documentation for coderay-1.1.3
Done installing documentation for coderay after 0 seconds
Fetching pygments.rb-2.4.0.gem
Successfully installed pygments.rb-2.4.0
Parsing documentation for pygments.rb-2.4.0
Installing ri documentation for pygments.rb-2.4.0
Done installing documentation for pygments.rb after 0 seconds
2 gems installed

 

4. asciidoctor-pdf 설치

gem install --pre asciidoctor-pdf

root@LYJ:/# gem install --pre asciidoctor-pdf
Fetching prawn-2.4.0.gem
Fetching pdf-core-0.9.0.gem
.
.
.
Done installing documentation for polyglot, treetop, ttfunk, pdf-core, prawn, ruby-rc4, hashery, Ascii85, afm, pdf-reader, prawn-templates, prawn-table, public_suffix, addressable, css_parser, prawn-svg, prawn-icon, matrix, concurrent-ruby, asciidoctor-pdf after 8 seconds
20 gems installed

 

5. asciidoctor-pdf-cjk-kai_gen_gothic 설치

gem install asciidoctor-pdf-cjk-kai_gen_gothic

root@LYJ:/# gem install asciidoctor-pdf-cjk-kai_gen_gothic
Fetching thread_safe-0.3.6.gem
Fetching safe_yaml-1.0.5.gem
.
.
.
Parsing documentation for asciidoctor-pdf-cjk-kai_gen_gothic-0.1.1
Installing ri documentation for asciidoctor-pdf-cjk-kai_gen_gothic-0.1.1
Done installing documentation for treetop, thread_safe, safe_yaml, ttfunk, pdf-core, prawn, Ascii85, pdf-reader, prawn-templates, prawn-svg, prawn-icon, asciidoctor-pdf, asciidoctor-pdf-cjk, asciidoctor-pdf-cjk-kai_gen_gothic after 2 seconds
14 gems installed

 

 

asciidoctor-pdf-cjk-kai_gen_gothic-install

root@LYJ:/# asciidoctor-pdf-cjk-kai_gen_gothic-install
[1/20] Downloading KaiGenGothicCN-Bold-Italic.ttf
/usr/local/rvm/gems/ruby-3.0.0/gems/asciidoctor-pdf-cjk-kai_gen_gothic-0.1.1/exe/asciidoctor-pdf-cjk-kai_gen_gothic-install:34:in `initialize': No such file or directory @ rb_sysopen - https://github.com/chloerei/asciidoctor-pdf-cjk-kai_gen_gothic/releases/download/v0.1.0-fonts/KaiGenGothicCN-Bold-Italic.ttf (Errno::ENOENT)
        from /usr/local/rvm/gems/ruby-3.0.0/gems/asciidoctor-pdf-cjk-kai_gen_gothic-0.1.1/exe/asciidoctor-pdf-cjk-kai_gen_gothic-install:34:in `open'
        from /usr/local/rvm/gems/ruby-3.0.0/gems/asciidoctor-pdf-cjk-kai_gen_gothic-0.1.1/exe/asciidoctor-pdf-cjk-kai_gen_gothic-install:34:in `block (3 levels) in <top (required)>'
        from /usr/local/rvm/gems/ruby-3.0.0/gems/asciidoctor-pdf-cjk-kai_gen_gothic-0.1.1/exe/asciidoctor-pdf-cjk-kai_gen_gothic-install:33:in `open'
        from /usr/local/rvm/gems/ruby-3.0.0/gems/asciidoctor-pdf-cjk-kai_gen_gothic-0.1.1/exe/asciidoctor-pdf-cjk-kai_gen_gothic-install:33:in `block (2 levels) in <top (required)>'
        from /usr/local/rvm/gems/ruby-3.0.0/gems/asciidoctor-pdf-cjk-kai_gen_gothic-0.1.1/exe/asciidoctor-pdf-cjk-kai_gen_gothic-install:31:in `each'
        from /usr/local/rvm/gems/ruby-3.0.0/gems/asciidoctor-pdf-cjk-kai_gen_gothic-0.1.1/exe/asciidoctor-pdf-cjk-kai_gen_gothic-install:31:in `each_with_index'
        from /usr/local/rvm/gems/ruby-3.0.0/gems/asciidoctor-pdf-cjk-kai_gen_gothic-0.1.1/exe/asciidoctor-pdf-cjk-kai_gen_gothic-install:31:in `block in <top (required)>'
        from /usr/local/rvm/gems/ruby-3.0.0/gems/asciidoctor-pdf-cjk-kai_gen_gothic-0.1.1/exe/asciidoctor-pdf-cjk-kai_gen_gothic-install:30:in `chdir'
        from /usr/local/rvm/gems/ruby-3.0.0/gems/asciidoctor-pdf-cjk-kai_gen_gothic-0.1.1/exe/asciidoctor-pdf-cjk-kai_gen_gothic-install:30:in `<top (required)>'
        from /usr/local/rvm/gems/ruby-3.0.0/bin/asciidoctor-pdf-cjk-kai_gen_gothic-install:23:in `load'
        from /usr/local/rvm/gems/ruby-3.0.0/bin/asciidoctor-pdf-cjk-kai_gen_gothic-install:23:in `<main>'
root@LYJ:/# vi /usr/local/rvm/gems/ruby-3.0.0/gems/asciidoctor-pdf-cjk-kai_gen_gothic-0.1.1/exe/asciidoctor-pdf-cjk-kai_gen_gothic-install
root@LYJ:/# asciidoctor-pdf-cjk-kai_gen_gothic-install
[1/20] Downloading KaiGenGothicCN-Bold-Italic.ttf
[2/20] Downloading KaiGenGothicCN-Bold.ttf
[3/20] Downloading KaiGenGothicCN-Regular-Italic.ttf
[4/20] Downloading KaiGenGothicCN-Regular.ttf
[5/20] Downloading KaiGenGothicJP-Bold-Italic.ttf
[6/20] Downloading KaiGenGothicJP-Bold.ttf
[7/20] Downloading KaiGenGothicJP-Regular-Italic.ttf
[8/20] Downloading KaiGenGothicJP-Regular.ttf
[9/20] Downloading KaiGenGothicKR-Bold-Italic.ttf
[10/20] Downloading KaiGenGothicKR-Bold.ttf
[11/20] Downloading KaiGenGothicKR-Regular-Italic.ttf
[12/20] Downloading KaiGenGothicKR-Regular.ttf
[13/20] Downloading KaiGenGothicTW-Bold-Italic.ttf
[14/20] Downloading KaiGenGothicTW-Bold.ttf
[15/20] Downloading KaiGenGothicTW-Regular-Italic.ttf
[16/20] Downloading KaiGenGothicTW-Regular.ttf
[17/20] Downloading RobotoMono-Bold.ttf
[18/20] Downloading RobotoMono-BoldItalic.ttf
[19/20] Downloading RobotoMono-Italic.ttf
[20/20] Downloading RobotoMono-Regular.ttf

실행 중 No such file or directory 에러가 발생할 경우 다음을 참고하면 된다.No such file or directory

 

asciidoctor-pdf-cjk-kai_gen_gothic-install:34:in `initialize': No such file or directory @ rb_sysopen 해결하기

asciidoctor-pdf-cjk-kai_gen_gothic-install을 실행했더니 다음과 같은 에러가 발생했다. root@LYJ:/# asciidoctor-pdf-cjk-kai_gen_gothic-install [1/20] Downloading KaiGenGothicCN-Bold-Italic.ttf /usr/local/rvm/gems/ruby-3.0.0/gems/asciidoctor-

tokkicine.tistory.com

 

6. pdf로 변환하기

root@LYJ:/# asciidoctor -r asciidoctor-pdf-cjk-kai_gen_gothic -b pdf -a pdf-style=KaiGenGothicKR test.adoc

root@LYJ:/# ll
합계 120
drwxr-xr-x   1 root root 4096  6월 30 01:53 ./
drwxr-xr-x   1 root root 4096  6월 30 01:53 ../
drwxr-xr-x   1 root root 4096  6월 29 08:49 bin/
drwxr-xr-x   2 root root 4096  4월 12  2016 boot/
drwxr-xr-x   5 root root  360  6월 29 07:42 dev/
drwxr-xr-x   1 root root 4096  6월 30 00:52 etc/
drwxr-xr-x   2 root root 4096  4월 12  2016 home/
drwxr-xr-x   1 root root 4096  6월 29 08:56 lib/
drwxr-xr-x   1 root root 4096  6월 29 08:47 lib64/
drwxr-xr-x   2 root root 4096  7월 10  2017 media/
drwxr-xr-x   2 root root 4096  7월 10  2017 mnt/
drwxr-xr-x   2 root root 4096  7월 10  2017 opt/
dr-xr-xr-x 582 root root    0  6월 29 07:42 proc/
drwx------   1 root root 4096  6월 30 01:51 root/
drwxr-xr-x   1 root root 4096  6월 29 08:47 run/
drwxr-xr-x   1 root root 4096  6월 29 08:49 sbin/
drwxr-xr-x   2 root root 4096  7월 10  2017 srv/
dr-xr-xr-x  13 root root    0  6월  2 01:24 sys/
**-rw-r--r--   1 root root    3  6월 30 01:51 test.adoc
-rw-r--r--   1 root root 9029  6월 30 01:53 test.pdf**
drwxrwxrwt   1 root root 4096  6월 30 01:08 tmp/
drwxr-xr-x   1 root root 4096  7월 20  2017 usr/
drwxr-xr-x   1 root root 4096  6월  2 01:23 var/

 

이렇게 adoc 확장자 파일을 pdf로 변환할 수 있다.

반응형

'오픈소스' 카테고리의 다른 글

Kafka 설치 및 사용 방법  (0) 2023.06.28