질문 : Any idea how is it possible to preserve the TOC information during DJVU to PDF conversion?
답변 : I'll outline the basic process. You'll need the open source command line utilities pdftk and djvused (part of DjVuLibre). These are available from your package manager (GNU/Linux) or their websites (Windows, OS X).
- step 1: convert the file text
First, use any tool to convert the DJVU file to a PDF (without bookmarks).
Suppose the files are called filename.djvu and filename.pdf.
- step 2: extract DJVU outline
Next, output the DJVU outline data to a file, like this:
djvused "filename.djvu" -e 'print-outline' > bmarks.outThis is a file listing the DJVU documents bookmarks in a serialized tree format. In fact it's just a SEXPR, and can be easily parsed. The format is as follows:
file ::= (bookmarks <bookmark>*) bookmark ::= (name page <bookmark>*) name ::= "<character>*" page ::= "#<digit>+"For example:
(bookmarks ("bmark1" "#1") ("bmark2" "#5" ("bmark2subbmark1" "#6") ("bmark2subbmark2" "#7")) ("bmark3" "#9" ...)) - step 3: convert DJVU outline to PDF metadata format
Now, we need to convert these bookmarks into the format required by PDF metadata. This file has format:
file ::= <entry>* entry ::= BookmarkBegin BookmarkTitle: <title> BookmarkLevel: <number> BookmarkPageNumber: <number> title ::= <character>*So our example would become:
BookmarkBegin BookmarkTitle: bmark1 BookmarkLevel: 1 BookmarkPageNumber: 1 BookmarkBegin BookmarkTitle: bmark2 BookmarkLevel: 1 BookmarkPageNumber: 5 BookmarkBegin BookmarkTitle: bmark2subbmark1 BookmarkLevel: 2 BookmarkPageNumber: 6 BookmarkBegin BookmarkTitle: bmark2subbmark2 BookmarkLevel: 2 BookmarkPageNumber: 7 BookmarkBegin BookmarkTitle: bmark3 BookmarkLevel: 1 BookmarkPageNumber: 9Basically, you just need to write a script to walk the SEXPR tree, keeping track of the level, and output the name, page number and level of each entry it comes to, in the correct format.
- step 4: extract PDF metadata and splice in converted bookmarks
Once you've got the converted list, output the PDF metadata from your converted PDF file:
pdftk "filename.pdf" dump_data > pdfmetadata.outNow, open the file and find the line that begins: NumberOfPages:
insert the converted bookmarks after this line. Save the new file as pdfmetadata.in
- step 5: create PDF with bookmarks
Now we can create a new PDF file incorporating this metadata:
pdftk "filename.pdf" update_info "pdfmetadata.in" output out.pdfThe file out.pdf should be a copy of your PDF with the bookmarks imported from the DJVU file.
형들 이게 대체 먼말이야 ㅠㅠ 어케 하는지 좀 알려주세여
아니; 뭘 알고싶은건데 ㅅㅂ;
Based on the very clear outline above given by user @pyrocrasty (thank you!), I have implemented a DJVU to PDF converter which preserves both OCR'd text and the bookmark structure. You may find it here:
https://github.com/kcroker/dpsprep
Acknowledgements
for the OCR data go to @zetah on the Ubuntu forums!
아니 내가 djvu 를 pdf로 바꿀라는데
중간에 ::= 이런건 파일포맷이고 컴파일러 수업 들었으면 알거아님
그거 바꾸는 프로그램 쓰면 다 사진파일로 바껴서 pdf로 저장되고 북마크했던거도 다 사라져서 그거 그대로 유지해서 pdf로 바꾸고 시픈데 하는법을 찾아보니 먼 소린지 모르겠어
나 프로그래밍 하나도 몰라 ㅠㅠ '
직접 못짜면 걍 온라인 djvu to pdf 사이트 다 뒤져보는 수밖에 없음.
내용은 djvu 파일 포맷이랑 pdf 메타데이터 포맷 나타낸거임. 글고 프로그래밍 안다고 해도 lex, yacc같은걸로 짜야될건데
다 해밨는데 안되서 ㅠ djvu 왜 만든거냐
프로그래밍 머르면 혼자서 절대 못하는 각이야?
ㅇㅇ 포기하셈
툴 찾는게 빠름
djvused "filename.djvu" -e 'print-outline' > bmarks.out 이거 하면 되잖아
pdf 북마크 쓰는 사람이 있긴 있구나..
저걸 어떤 프로그램에서 쳐야해?? 내 컴터 윈도우즈10인데.... ㅠㅠ
컴터에서 책 보면서 썼는데 눈아파서 pdf로 바꿔서 패드엣 ㅓ볼라고 하는데. ㅠ ㅠ 방법을모르게써