diff --git a/pkg/pdfcpu/validate/annotation.go b/pkg/pdfcpu/validate/annotation.go index 534a10d4..f5cd756d 100644 --- a/pkg/pdfcpu/validate/annotation.go +++ b/pkg/pdfcpu/validate/annotation.go @@ -250,35 +250,32 @@ func validateAnnotationDictText(xRefTable *model.XRefTable, d types.Dict, dictNa } // State, optional, text string, since V1.5 - // NOTE: acceptable state values depend on the StateModel. for now, accept the union of all valid values for State. - // once the StateModel is loaded and validated, we will check the State again to make sure it corresponds to - // the model. - validate := func(s string) bool { - return types.MemberOf(s, []string{"None", "Marked", "Unmarked", "Completed", "Accepted", "Rejected", "Cancelled"}) + state, err := validateStringEntry(xRefTable, d, dictName, "State", OPTIONAL, model.V15, nil) + if err != nil { + return err } - state, err := validateStringEntry(xRefTable, d, dictName, "State", OPTIONAL, model.V15, validate) + + // StateModel, text string, since V1.5 + validate := func(s string) bool { return types.MemberOf(s, []string{"Marked", "Review"}) } + stateModel, err := validateStringEntry(xRefTable, d, dictName, "StateModel", state != nil, model.V15, validate) if err != nil { return err } - if state != nil { - // StateModel, text string, since V1.5 - validate = func(s string) bool { return types.MemberOf(s, []string{"Marked", "Review"}) } - stateModel, err := validateStringEntry(xRefTable, d, dictName, "StateModel", REQUIRED, model.V15, validate) - if err != nil { - return err + if state == nil { + if stateModel != nil { + return errors.Errorf("pdfcpu: validateAnnotationDictText: dict=%s missing state for statemodel=%s", dictName, *stateModel) } + return nil + } - // Ensure that the state/model combo is valid. - var validStates []string - if *stateModel == "Marked" { - validStates = []string{"Marked", "Unmarked"} - } else { - validStates = []string{"Accepted", "Rejected", "Cancelled", "Completed", "None"} - } - if !types.MemberOf(*state, validStates) { - return errors.Errorf("pdfcpu: validateAnnotationDictText: dict=%s invalid state=%s for state model=%s", dictName, *state, *stateModel) - } + // Ensure that the state/model combo is valid. + validStates := []string{"Accepted", "Rejected", "Cancelled", "Completed", "None"} // stateModel "Review" + if *stateModel == "Marked" { + validStates = []string{"Marked", "Unmarked"} + } + if !types.MemberOf(*state, validStates) { + return errors.Errorf("pdfcpu: validateAnnotationDictText: dict=%s invalid state=%s for state model=%s", dictName, *state, *stateModel) } return nil