AsciiDoc으로 작성된 문서를 PDF로 변환

개요



AsciiDoc으로 작성된 문서를 PDF 파일로 변환하는 설정에 대한 참고 사항.

환경


  • Gradle: 5.6

  • 상세



    디렉토리 구성


    │
    ├ gradle
    │ │
    │ └ wrapper             .. asciidoctorビルド用jar
    │
    ├ src
    │ ├ themes
    │ │ │
    │ │ ├ custom-theme.yml .. pdfのstyle設定用ファイル
    │ │ │
    │ │ └ logo.png         .. ロゴ画像
    │ │
    │ └ index.adoc            
    │
    ├ build.gradle           .. asciidoctorビルド設定ファイル
    │
    ├ gradlew                .. asciidoctorビルド実行exe(unix系統用)
    │
    └ gradlew.bat            .. asciidoctorビルド実行exe(windows系統用)
    
  • src 폴더 아래의 adoc이 빌드됨
  • pdf 스타일을 설정하는 파일 준비

  • 빌드 설정



    build.gradle
    buildscript {
      ext {
        asciiDoctorGradlePluginVersion = "1.5.7"
        asciidoctorjDiagramVersion = "1.5.8"
        asciidoctorjPdfVersion = "1.5.0-alpha.15"
      }
      repositories {
        jcenter()
      }
      dependencies {
        classpath("org.asciidoctor:asciidoctor-gradle-plugin:${asciiDoctorGradlePluginVersion}")
        classpath("org.asciidoctor:asciidoctorj-diagram:${asciidoctorjDiagramVersion}")
        classpath("org.asciidoctor:asciidoctorj-pdf:${asciidoctorjPdfVersion}")
      }
    }
    
    apply plugin: 'org.asciidoctor.convert'
    apply plugin: 'org.asciidoctor.gradle.asciidoctor'
    
    asciidoctor {
      dependsOn 'clean'
      requires = ['asciidoctor-diagram'] // asciidoctor-diagram の利用設定
      backends = ['html5', 'pdf']        // htmlとpdfファイルを出力する設定
      sourceDir = file('src')            // ビルド対象のファイルを置くフォルダ
      outputDir = file('build')          // ビルド後のファイルが出力されるフォルダ
      separateOutputDirs = false
    }
    
    wrapper {
      gradleVersion = '5.6'
    }
    
    defaultTasks 'asciidoctor'
    

    PDF 스타일 설정(custom-theme.yml)


  • PDF 변환시의 폰트 등을 지정하는 설정 파일을 준비한다.
  • 자세한 것은 htps : // 기주 b. 이 m/아s도도 c와 r/아s도도 c와 rpdf/bぉb/마s테 r/도cs/테이민g구이로. 아도 c 를 참고로 한다
  • 취소 스타일링은 여기에서 가져옵니다


  • 샘플 문서(index.adoc)



    index.adoc
    :data-uri:
    :pdf-style: ./themes/custom-theme.yml
    :title-logo-image: image:./themes/logo.png[]
    :toc: left
    :sectnums:
    :chapter-label:
    :toclevels: 2
    :toc-title: 目次
    :figure-caption: 図
    
    = タイトル
    
    == TEST1
    === TEST2
    ==== TEST3
    * 設定で目次や段落を自動的に作ってくれる
    * toclevelsを2にしているため2段落(x.x)までの表題で目次が作成される
    
    ==== UML
    * UMLの出力テスト
    
    :imagesdir: /build
    [plantuml, test-uml]
    ----
    @startuml
    Alice -> Bob: Authentication Request
    Bob --> Alice: Authentication Response
    
    Alice -> Bob: Another authentication Request
    Alice <-- Bob: another authentication Response
    @enduml
    ----
    
  • 출력되는 PDF는 다음과 같이 된다


  • 요약



    사내에서만 운용하는 사양서라면 HTML이라도 문제 없지만,
    고객에게 납품하면 아무래도 그렇게 할 수 없게 된다.
    그럴 때 asciidoctorj-pdf 를 사용하면 PDF로 변환할 수 있기 때문에 편리하다고 생각한다.

    사양서 등의 문서도 버전 관리하기 쉬운 텍스트 기반의 문서로 작성할 수 있다면
    이력 관리 등 하기 쉽기 때문에 그렇게 되면 좋다고 생각한다.

    좋은 웹페이지 즐겨찾기