diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2023-06-29 05:01:23 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2023-07-01 22:03:19 +0200 |
commit | 6e98469ef723960ce4fcf37b27416cf2ebfca263 (patch) | |
tree | d72f10627e6088cfe727fe3d8ba01a19fc1e5c6a /pdf/pdf.go | |
parent | 55a17a69b793ef399f4c8799b37e737a0d2940b2 (diff) | |
download | pdf-simple-sign-6e98469ef723960ce4fcf37b27416cf2ebfca263.tar.gz pdf-simple-sign-6e98469ef723960ce4fcf37b27416cf2ebfca263.tar.xz pdf-simple-sign-6e98469ef723960ce4fcf37b27416cf2ebfca263.zip |
WIP: PDF 1.5 cross-reference stream support
Perhaps only for Go.
Diffstat (limited to 'pdf/pdf.go')
-rw-r--r-- | pdf/pdf.go | 40 |
1 files changed, 39 insertions, 1 deletions
@@ -671,11 +671,49 @@ func (u *Updater) parse(lex *Lexer, stack *[]Object) (Object, error) { } } +// TODO: ISO 32000-2:2020 7.5.8.2 Cross-reference stream dictionary +// - How to update this kind of file? Hybrid-reference file? +// ⋄ XRefStm could point to this old-new xref. But it's actually a /Prev. +func (u *Updater) loadXrefStream( + lex *Lexer, loadedEntries map[uint]struct{}) error { + var stack []Object + for { + object, err := u.parse(lex, &stack) + if err != nil { + return fmt.Errorf("invalid xref table: %s", err) + } else if object.Kind == End { + return errors.New("invalid xref table") + } + + // For the sake of simplicity, keep stacking until we find an object. + if object.Kind != Indirect { + stack = append(stack, object) + continue + } + + object = object.Array[0] + if object.Kind != Stream { + return errors.New("invalid xref table") + } + if typ, ok := object.Dict["Type"]; !ok || typ.String != "XRef" { + return errors.New("invalid xref stream") + } + if filter, ok := object.Dict["Filter"]; !ok || + filter.String != "FlateDecode" { + return errors.New("invalid xref stream") + } + + return errors.New("unimplemented") + } +} + +// TODO: Also return the trailer dictionary, but remove any XRef/stream fields, +// perhaps as per Table 17 + /Filter, /Length. func (u *Updater) loadXref(lex *Lexer, loadedEntries map[uint]struct{}) error { var throwawayStack []Object if keyword, _ := u.parse(lex, &throwawayStack); keyword.Kind != Keyword || keyword.String != "xref" { - return errors.New("invalid xref table") + return u.loadXrefStream(lex, loadedEntries) } for { object, _ := u.parse(lex, &throwawayStack) |