github.com/pdfcpu/pdfcpu@v0.11.1/pkg/api/info.go (about) 1 /* 2 Copyright 2020 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 api 18 19 import ( 20 "io" 21 22 "github.com/pdfcpu/pdfcpu/pkg/pdfcpu" 23 "github.com/pdfcpu/pdfcpu/pkg/pdfcpu/model" 24 "github.com/pkg/errors" 25 ) 26 27 // PDFInfo returns information about rs. 28 func PDFInfo(rs io.ReadSeeker, fileName string, selectedPages []string, fonts bool, conf *model.Configuration) (*pdfcpu.PDFInfo, error) { 29 if rs == nil { 30 return nil, errors.New("pdfcpu: PDFInfo: missing rs") 31 } 32 33 if conf == nil { 34 conf = model.NewDefaultConfiguration() 35 } else { 36 conf.ValidationMode = model.ValidationRelaxed 37 } 38 conf.Cmd = model.LISTINFO 39 40 ctx, err := ReadAndValidate(rs, conf) 41 if err != nil { 42 return nil, err 43 } 44 45 if fonts { 46 if err = OptimizeContext(ctx); err != nil { 47 return nil, err 48 } 49 } 50 51 pages, err := PagesForPageSelection(ctx.PageCount, selectedPages, false, true) 52 if err != nil { 53 return nil, err 54 } 55 56 if err := pdfcpu.DetectWatermarks(ctx); err != nil { 57 return nil, err 58 } 59 60 return pdfcpu.Info(ctx, fileName, pages, fonts) 61 }