找回密码
 快速注册
搜索
查看: 74|回复: 3

包含PDF页面时保持链接

[复制链接]

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2023-5-7 00:09 |阅读模式
如果想在外部的PDF上做笔记但是没有源码,可使用PdfPagesPdfOverlay插入该PDF的页面
但是发现Bookmark[显示于阅读器的书签栏,用于快速跳转章节] 和 Link annotation [包括文档内链(Named destination)或Web URL]

使用paxnewpax
对于一个PDF运行pax时需要运行它包含的Java程序pax.jar提取 Link annotation
  1. java -jar "D:\MiKTeX\scripts\pax\pax.jar" externel.pdf
复制代码

它会生成 externel.pax [对同一个PDF只需运行一次pax.jar 因为下次编译TeX时externel.pax仍然可用]
在LaTeX导言区添加1行
  1. \usepackage{pax}
复制代码

然后运行两次 pdflatex
  1. pdflatex test
  2. pdflatex test
复制代码

它会将从原PDF提取Link annotation并插入新PDF [经测试成功了✅]

更好的解法是pdftk
它可以从原PDF中提取Bookmark并插入新PDF [经测试成功了✅]
  1. pdftk "external.pdf" dump_data >data.info
  2. pdftk "my notes.pdf" update_info data.info output "my notes with bookmarks.pdf"
复制代码

并且可以从原PDF提取Link annotation并插入新PDF [与pax等效] [经测试失败了😥]
  1. pdftk "external.pdf" dump_data_annots >annots.info
  2. pdftk "my notes.pdf" update_info annots.info output "my notes with links.pdf"
复制代码

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2023-5-7 00:57
annots.info的内容应该是Link Annotation所在的页数的和矩形区域的顶点坐标
但是这里面好像没有链接的目标位置的信息呢
  1. NumberOfPages: 47
  2. ---
  3. AnnotSubtype: Link
  4. AnnotRect: 56.693 580.761 139.587 592.885
  5. AnnotPageNumber: 1
  6. ---
  7. AnnotSubtype: Link
  8. AnnotRect: 56.693 556.303 282.74 568.426
  9. AnnotPageNumber: 1
  10. ---
  11. AnnotSubtype: Link
  12. AnnotRect: 73.057 542.753 193.25 554.877
  13. AnnotPageNumber: 1
  14. ...(后面的Link都是以上的格式)
复制代码

将annots.info插入LaTeX生成的新PDF时报错
pdftk Warning: unexpected case 1 in LoadDataFile(); continuing
pdftk Warning: unexpected case 1 in LoadDataFile(); continuing
pdftk Warning: unexpected case 1 in LoadDataFile(); continuing
pdftk Warning: unexpected case 1 in LoadDataFile(); continuing
pdftk Warning: unexpected case 1 in LoadDataFile(); continuing
pdftk Warning: unexpected case 1 in LoadDataFile(); continuing
pdftk Warning: unexpected case 1 in LoadDataFile(); continuing
...(后面很多行重复的)
看来这个annots.info不靠谱, 还是用Pax吧.
pax.jar生成的.pax的内容为
  1. \[{pax}{0.1l}\\
  2. \[{file}{\<4C656374757265206E6F74657320545432332E706466\>}{
  3.   Size={428335},
  4.   Date={D:20230504122743+01'00'},
  5. }\\
  6. \[{pagenum}{47}\\
  7. \[{page}{1}{0 0 595.28 841.89}{}\\
  8. \[{annot}{1}{Link}{56.693 580.761 139.587 592.885}{GoTo}{
  9.   C={[1 0 0]},
  10.   H={/I},
  11.   DestLabel={1},
  12.   Border={[0 0 0]},
  13. }\\
  14. \[{annot}{1}{Link}{56.693 556.303 282.74 568.426}{GoTo}{
  15.   C={[1 0 0]},
  16.   H={/I},
  17.   DestLabel={2},
  18.   Border={[0 0 0]},
  19. }\\
  20. \[{annot}{1}{Link}{73.057 542.753 193.25 554.877}{GoTo}{
  21.   C={[1 0 0]},
  22.   H={/I},
  23.   DestLabel={3},
  24.   Border={[0 0 0]},
  25. }\\
  26. \[{annot}{1}{Link}{73.057 529.204 190.278 541.328}{GoTo}{
  27.   C={[1 0 0]},
  28.   H={/I},
  29.   DestLabel={4},
  30.   Border={[0 0 0]},
  31. }\\
  32. \[{annot}{1}{Link}{73.057 515.655 275.25 527.779}{GoTo}{
  33.   C={[1 0 0]},
  34.   H={/I},
  35.   DestLabel={5},
  36.   Border={[0 0 0]},
  37. }\\
  38. \[{annot}{1}{Link}{56.693 491.197 243.767 503.32}{GoTo}{
  39.   C={[1 0 0]},
  40.   H={/I},
  41.   DestLabel={6},
  42.   Border={[0 0 0]},
  43. }\\
  44. \[{annot}{1}{Link}{73.057 477.648 211.649 489.771}{GoTo}{
  45.   C={[1 0 0]},
  46.   H={/I},
  47.   DestLabel={7},
  48.   Border={[0 0 0]},
  49. }\\
  50. ...(后面都是差不多的)
复制代码

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2023-5-7 01:01
data.info的内容是从Trailer部分提取的(包含了文档信息、创建文档的软件、页面信息、Bookmark)

InfoBegin
InfoKey: Creator
InfoValue: LaTeX with hyperref
InfoBegin
InfoKey: Producer
InfoValue: xdvipdfmx (20211117)
InfoBegin
InfoKey: CreationDate
InfoValue: D:20230504095230-00'00'
PdfID0: b324f5944f70b9da02c8ff186cf2d403
PdfID1: acca4d25e8c27510dddef7042cf25e38
NumberOfPages: 47
BookmarkBegin
BookmarkTitle: Index of Notation
BookmarkLevel: 1
BookmarkPageNumber: 2
BookmarkBegin
BookmarkTitle: Review from A1: Linear maps and continuity
BookmarkLevel: 1
BookmarkPageNumber: 3
BookmarkBegin
BookmarkTitle: Normed vector spaces
BookmarkLevel: 2
BookmarkPageNumber: 3
BookmarkBegin
BookmarkTitle: Bounded linear maps
BookmarkLevel: 2
BookmarkPageNumber: 5
BookmarkBegin
BookmarkTitle: Finite dimensional normed vector spaces
BookmarkLevel: 2
BookmarkPageNumber: 6
BookmarkBegin
BookmarkTitle: The derivative in higher dimensions
BookmarkLevel: 1
BookmarkPageNumber: 8
BookmarkBegin
BookmarkTitle: The one-dimensional case
BookmarkLevel: 2
BookmarkPageNumber: 8
BookmarkBegin
BookmarkTitle: The general case
BookmarkLevel: 2
BookmarkPageNumber: 10
BookmarkBegin
BookmarkTitle: Partial derivatives and the total derivative
BookmarkLevel: 2
BookmarkPageNumber: 13
BookmarkBegin
BookmarkTitle: The Chain Rule
BookmarkLevel: 2
BookmarkPageNumber: 15
BookmarkBegin
BookmarkTitle: The Mean Value Inequality
BookmarkLevel: 2
BookmarkPageNumber: 16
BookmarkBegin
BookmarkTitle: Continuity of partial derivatives and the existence of the total derivative
BookmarkLevel: 2
BookmarkPageNumber: 17
BookmarkBegin
BookmarkTitle: Real-valued functions on an inner product space
BookmarkLevel: 2
BookmarkPageNumber: 19
BookmarkBegin
BookmarkTitle: *Higher order derivatives
BookmarkLevel: 2
BookmarkPageNumber: 20
BookmarkBegin
BookmarkTitle: The Inverse and Implicit Function Theorems
BookmarkLevel: 1
BookmarkPageNumber: 22
BookmarkBegin
BookmarkTitle: The Inverse Function Theorem
BookmarkLevel: 2
BookmarkPageNumber: 22
BookmarkBegin
BookmarkTitle: *Proof of the Inverse Function Theorem
BookmarkLevel: 2
BookmarkPageNumber: 23
BookmarkBegin
BookmarkTitle: Applications of the Inverse Function Theorem
BookmarkLevel: 2
BookmarkPageNumber: 26
BookmarkBegin
BookmarkTitle: Systems of local coordinates and the Implicit Function Theorem.
BookmarkLevel: 2
BookmarkPageNumber: 26
BookmarkBegin
BookmarkTitle: Lagrange multipliers
BookmarkLevel: 2
BookmarkPageNumber: 31
BookmarkBegin
BookmarkTitle: Submanifolds of a normed vector space
BookmarkLevel: 1
BookmarkPageNumber: 34
BookmarkBegin
BookmarkTitle: Definition and basic properties
BookmarkLevel: 2
BookmarkPageNumber: 34
BookmarkBegin
BookmarkTitle: Tangent spaces and normal vectors
BookmarkLevel: 2
BookmarkPageNumber: 37
BookmarkBegin
BookmarkTitle: *Abstract Manifolds
BookmarkLevel: 2
BookmarkPageNumber: 39
BookmarkBegin
BookmarkTitle: Appendix
BookmarkLevel: 1
BookmarkPageNumber: 41
BookmarkBegin
BookmarkTitle: Notation:  and
BookmarkLevel: 2
BookmarkPageNumber: 41
BookmarkBegin
BookmarkTitle: *Multilinear maps and higher derivatives
BookmarkLevel: 2
BookmarkPageNumber: 42
BookmarkBegin
BookmarkTitle: *Symmetries of higher derivatives
BookmarkLevel: 2
BookmarkPageNumber: 42
BookmarkBegin
BookmarkTitle: *The immersion criterion for a submanifold
BookmarkLevel: 2
BookmarkPageNumber: 44
BookmarkBegin
BookmarkTitle: *Normed vector spaces: duals and quotients
BookmarkLevel: 2
BookmarkPageNumber: 45
PageMediaBegin
PageMediaNumber: 1
PageMediaRotation: 0
PageMediaRect: 0 0 595.28 841.89
PageMediaDimensions: 595.28 841.89
PageMediaBegin
PageMediaNumber: 2
PageMediaRotation: 0
PageMediaRect: 0 0 595.28 841.89
PageMediaDimensions: 595.28 841.89
PageMediaBegin
PageMediaNumber: 3
PageMediaRotation: 0
PageMediaRect: 0 0 595.28 841.89
PageMediaDimensions: 595.28 841.89
PageMediaBegin
PageMediaNumber: 4
PageMediaRotation: 0
PageMediaRect: 0 0 595.28 841.89
PageMediaDimensions: 595.28 841.89
...(后面的Page都是以上格式的)

用PDFTk插入data.info成功了,新PDF出现了与原来相同的书签

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

 楼主| hbghlyj 发表于 2023-5-7 02:18

编译LaTeX后自动运行pdftk

本帖最后由 hbghlyj 于 2023-5-7 03:06 编辑 如果在LaTeX内部用\write18运行pdftk, 则pdftk收到的是空的pdf, 因为LaTeX正在运行, 不能使pdftk收到LaTeX运行完的PDF.
换一种方法,在VScode的LaTex Workshop extension中新建recipe
在"latex-workshop.latex.recipes"中加入
  1.         {
  2.             "name": "pdftk",
  3.             "tools": [
  4.                 "latexmk",
  5.                 "pdftk"
  6.             ]
  7.         }
复制代码

在"latex-workshop.latex.tools"中加入
  1.         {
  2.             "name":"pdftk",
  3.             "command":"pdftk",
  4.             "args":[
  5.                 "%DOC%.pdf",
  6.                 "update_info",
  7.                 "%DOC%.info",
  8.                 "output",
  9.                 "%DOC%(Bookmark).pdf"
  10.             ]
  11.         },
复制代码

Ctrl+Shift+P进入editor commands
输入recipe选择pdftk
Screenshot 2023-05-06 191512.png

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 12:09

Powered by Discuz!

× 快速回复 返回顶部 返回列表