PDFのHighlight Annotationのうち、Rect
とQuadPoints
についてリバースエンジニアリングを試みます。
PDF文法そのものはこちらのサイトが分かりやすいです: 詳細PDF入門 ー 実装して学ぼう!PDFファイルの構造とその書き方読み方
PDF公式仕様書はこちら: https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf
材料
OS
Microsoft Windows 11 Home
Version 10.0.26100 Build 26100
Chrome
Version 133.0.6943.142 (Official Build) (64-bit)
Adobe Acrobat
Continuous Release | 2024.005.20421 | 64 bit
使用するPDFサンプル
Highlight Annotationを使用したミニマルサンプル(不完全データ)
%PDF-1.7
1 0 obj % entry point
<<
/Type /Catalog
/Pages 2 0 R
>>
endobj
2 0 obj
<<
/Type /Pages
/MediaBox [ 0 0 200 400 ]
/Count 1
/Kids [ 3 0 R ]
>>
endobj
3 0 obj
<<
/Type /Page
/Parent 2 0 R
/Resources <<
/Font <<
/F1 4 0 R
>>
>>
/Contents 5 0 R
/Annots [6 0 R]
>>
endobj
4 0 obj
<<
/Type /Font
/Subtype /Type1
/BaseFont /Times-Roman
>>
endobj
5 0 obj % page content
<<
/Length 44
>>
stream
BT
70 50 TD
/F1 12 Tf
(Hello, world!) Tj
ET
endstream
endobj
6 0 obj
<<
/Type /Annot
/Rect [0 0 100 100 ]
/Subtype /Highlight
/QuadPoints [69.9398 58.8418 96.5932 58.8418 69.9398 47.3526 96.5932 47.3526 ]
/M (D:20190101153417)
/Contents (aaa)
/F 4
/C [1 1 0 ]
/CA 1
/Border [0 0 1 ]
/P 3 0 R
>>
endobj
xref
trailer
<<
/Size 6
/Root 1 0 R
>>
startxref
%%EOF
これに対して、pdftkを使用して、完璧にします。(クロスリファレンス他)
pdftk
使用コマンドライン
pdftk test.pdf output test_out.pdf
Rect
Rectをいじったところ、結論としてはハイライトの変更はない。Chromeにおいて、カーソルオーバーしたときのコメント表示の位置が変動した。
一方、AcrobatのコメントはRectではなくカーソル位置に依存(大きさは不変)
Chromeでの挙動
/Rect [0 0 100 100 ]
/Rect [50 0 100 100 ]
/Rect [0 50 100 100 ]
/Rect [0 0 50 100 ]
/Rect [0 0 100 50 ]
/Rect [1 1 100 100 ]
...法則性が分からないですな。
QuadPoint
QuadPointsの順番は、仕様書と異なって、下記が実態になっている
参考: https://stackoverflow.com/questions/9855814/pdf-spec-vs-acrobat-creation-quadpoints
台形
/QuadPoints [0 58.8418 96.5932 58.8418 69.9398 47.3526 96.5932 47.3526 ]
伸ばす
/QuadPoints [0 58.8418 96.5932 58.8418 0 47.3526 96.5932 47.3526 ]
蝶つがい
/QuadPoints [69.9398 0 96.5932 58.8418 69.9398 47.3526 96.5932 47.3526 ]
うらがえs
/QuadPoints [69.9398 0 96.5932 0 69.9398 47.3526 96.5932 47.3526 ]