diff options
Diffstat (limited to 'pdf')
-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) |