[홈으로] [게시판]

[참고]

아래 내용은 KDLP.net 개편과 함께 사라진 http://docbook.kldp.net/howto/fop.html의 내용입니다. FOP 최근 버전과는 일치하지 않을 수 있으며, 현재의 닥북 모음집(DbkPackWin)를 사용하면 FOP를 직접 다룰 일이 별로 없습니다. --류광

FOP를 사용하면 FO 파일로부터 PDF 파일을 얻을 수 있습니다.

[info]

DocBook 한국♡ 프로젝트에서 제공하는 MS 윈도용 DocBook 패키지를 사용하고 있는 경우라면 이 페이지의 내용을 굳이 이해하지 않고서도 문서 변환이 가능합니다. 사용법은 패키지에 포함된 설명서를 참고하세요.

metrics 파일 얻기

우선 FOP의 최신 버전을 받아옵니다(0.18.1 이상). FOP도 자바 프로그램이지만 실행하기 편리하도록 만들어진 batch 파일과 쉘 스크립트 파일을 함께 제공합니다.

한글 PDF를 얻기 위해서는 한글 트루타입 폰트(.ttf)가 필요합니다. 폰트가 준비되었으면 다음과 같이 폰트로 부터 metrics 파일을 얻습니다.

> java -cp fop.jar;xerces.jar;xalan.jar;w3c.jar
     org.apache.fop.fonts.apps.TTFReader foobar.ttf foobar.xml

한글 트루타입 폰트로부터 만들어진 metrics 파일에는 폰트의 이름 부분에 0과 같은 군더더기가 붙는 경우가 있습니다. 파일을 직접 편집기로 열어서 해당부분의 군더더기를 지워주어야 합니다.

userconfig 설정

이제 FOP/conf/userconfig.xml 파일을 편집합니다. 다음과 같이 폰트와 해당 metrics 파일의 경로, 폰트 이름을 정확히 적어줍니다.

<fonts>
 <font metrics-file="\fop\foobar.xml" kerning="yes"
                    embed-file="\fop\foobar.ttf">
    <font-triplet name="serif" style="normal" weight="normal"/>
    <font-triplet name="serif" style="normal" weight="bold"/>
    <font-triplet name="serif" style="italic" weight="normal"/>
    <font-triplet name="serif" style="italic" weight="bold"/>
    <font-triplet name="sans-serif" style="normal" weight="normal"/>
    <font-triplet name="sans-serif" style="normal" weight="bold"/>
    <font-triplet name="sans-serif" style="italic" weight="normal"/>
    <font-triplet name="sans-serif" style="italic" weight="bold"/>
    <font-triplet name="monospace" style="normal" weight="normal"/>
    <font-triplet name="monospace" style="normal" weight="bold"/>
    <font-triplet name="monospace" style="italic" weight="normal"/>
    <font-triplet name="monospace" style="italic" weight="bold"/>
  </font>
</fonts>

이렇게 하면 모든 경우에 한가지 폰트만 사용하게 됩니다. 물론 serif나 sans-serif, 혹은 italic이나 bold에 각각 다른 폰트를 대응시키면 여러 폰트를 쓸 수 있습니다.

<fonts>
  <font metrics-file="\fop\A.xml" kerning="yes"
                                        embed-file="\fop\A.ttf">
    <font-triplet name="serif" style="normal" weight="normal"/>
    <font-triplet name="serif" style="normal" weight="bold"/>
    <font-triplet name="serif" style="italic" weight="normal"/>
    <font-triplet name="serif" style="italic" weight="bold"/>
  </font>
  <font metrics-file="\fop\B.xml" kerning="yes"
                                        embed-file="\fop\B.ttf">
    <font-triplet name="sans-serif" style="normal" weight="normal"/>
    <font-triplet name="sans-serif" style="normal" weight="bold"/>
    <font-triplet name="sans-serif" style="italic" weight="normal"/>
    <font-triplet name="sans-serif" style="italic" weight="bold"/>
  </font>
  <font metrics-file="\fop\C.xml" kerning="yes"
                                        embed-file="\fop\C.ttf">
    <font-triplet name="monospace" style="normal" weight="normal"/>
    <font-triplet name="monospace" style="normal" weight="bold"/>
    <font-triplet name="monospace" style="italic" weight="normal"/>
    <font-triplet name="monospace" style="italic" weight="bold"/>
  </font>
</fonts>

FO 파일로 부터 PDF 생성하기

이제 FOP로 FO파일을 PDF로 변환합니다. -c 옵션으로 userconfig.xml 파일을 적용시켜야 합니다.

> FOP -c /fop/conf/userconfig.xml -fo test.fo -pdf test.pdf

그런데 FOP에는 xerces와 xalan도 포함되어 있어서 다음과 같이 하면 한번에 XML 파일로부터 PDF 파일을 얻을 수 있습니다.

> FOP -c /fop/conf/userconfig.xml -xml test.xml -xsl docbook.xsl -pdf test.pdf
제일 위로
최종 수정 일시: 05월 01일(2010년) 06:18 PM 편집 | 정보 | 차이 | 비슷한페이지 | DebugInfo
유용한 페이지들: 분류 분류 | 자유로운 연습장 SandBox | 무작위 페이지들 RandomPages | 인기있는 페이지들 MostPopular