github.com/pdfcpu/pdfcpu@v0.11.1/pkg/cli/test/annotation_test.go (about) 1 /* 2 Copyright 2021 The pdfcpu Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package test 18 19 import ( 20 "path/filepath" 21 "testing" 22 23 "github.com/pdfcpu/pdfcpu/pkg/cli" 24 ) 25 26 func TestListAndRemoveAnnotations(t *testing.T) { 27 msg := "TestListAndRemoveAnnotations" 28 29 fn := "adobe_errata.pdf" 30 copyFile(t, filepath.Join(inDir, fn), filepath.Join(outDir, fn)) 31 inFile := filepath.Join(outDir, fn) 32 33 // See also api/annotations_test.go for page annotation manipulation 34 // including adding annotations. 35 36 cmd := cli.ListAnnotationsCommand(inFile, nil, conf) 37 if _, err := cli.Process(cmd); err != nil { 38 t.Fatalf("%s: %v\n", msg, err) 39 } 40 41 // Remove page annotation using obj# 34 42 cmd = cli.RemoveAnnotationsCommand(inFile, "", nil, nil, []int{34}, conf) 43 if _, err := cli.Process(cmd); err != nil { 44 t.Fatalf("%s: %v\n", msg, err) 45 } 46 47 // Remove all page annotations from page 14 48 cmd = cli.RemoveAnnotationsCommand(inFile, "", []string{"14"}, nil, nil, conf) 49 if _, err := cli.Process(cmd); err != nil { 50 t.Fatalf("%s: %v\n", msg, err) 51 } 52 53 // Remove all page annotations 54 cmd = cli.RemoveAnnotationsCommand(inFile, "", nil, nil, nil, conf) 55 if _, err := cli.Process(cmd); err != nil { 56 t.Fatalf("%s: %v\n", msg, err) 57 } 58 59 }