github.com/pdfcpu/pdfcpu@v0.11.1/pkg/cli/cmd.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 cli
    18  
    19  import (
    20  	"io"
    21  
    22  	"github.com/pdfcpu/pdfcpu/pkg/pdfcpu"
    23  	"github.com/pdfcpu/pdfcpu/pkg/pdfcpu/model"
    24  )
    25  
    26  // Command represents an execution context.
    27  type Command struct {
    28  	Mode              model.CommandMode
    29  	InFile            *string
    30  	InFileJSON        *string
    31  	InFiles           []string
    32  	InDir             *string
    33  	OutFile           *string
    34  	OutFileJSON       *string
    35  	OutDir            *string
    36  	PageSelection     []string
    37  	PWOld             *string
    38  	PWNew             *string
    39  	StringVal         string
    40  	IntVal            int
    41  	BoolVal1          bool
    42  	BoolVal2          bool
    43  	IntVals           []int
    44  	StringVals        []string
    45  	StringMap         map[string]string
    46  	Input             io.ReadSeeker
    47  	Inputs            []io.ReadSeeker
    48  	Output            io.Writer
    49  	Box               *model.Box
    50  	Import            *pdfcpu.Import
    51  	NUp               *model.NUp
    52  	Cut               *model.Cut
    53  	PageBoundaries    *model.PageBoundaries
    54  	Resize            *model.Resize
    55  	Zoom              *model.Zoom
    56  	Watermark         *model.Watermark
    57  	ViewerPreferences *model.ViewerPreferences
    58  	PageConf          *pdfcpu.PageConfiguration
    59  	Conf              *model.Configuration
    60  }
    61  
    62  var cmdMap = map[model.CommandMode]func(cmd *Command) ([]string, error){
    63  	model.VALIDATE:                Validate,
    64  	model.OPTIMIZE:                Optimize,
    65  	model.SPLIT:                   Split,
    66  	model.SPLITBYPAGENR:           SplitByPageNr,
    67  	model.MERGECREATE:             MergeCreate,
    68  	model.MERGECREATEZIP:          MergeCreateZip,
    69  	model.MERGEAPPEND:             MergeAppend,
    70  	model.EXTRACTIMAGES:           ExtractImages,
    71  	model.EXTRACTFONTS:            ExtractFonts,
    72  	model.EXTRACTPAGES:            ExtractPages,
    73  	model.EXTRACTCONTENT:          ExtractContent,
    74  	model.EXTRACTMETADATA:         ExtractMetadata,
    75  	model.TRIM:                    Trim,
    76  	model.ADDWATERMARKS:           AddWatermarks,
    77  	model.REMOVEWATERMARKS:        RemoveWatermarks,
    78  	model.LISTATTACHMENTS:         processAttachments,
    79  	model.ADDATTACHMENTS:          processAttachments,
    80  	model.ADDATTACHMENTSPORTFOLIO: processAttachments,
    81  	model.REMOVEATTACHMENTS:       processAttachments,
    82  	model.EXTRACTATTACHMENTS:      processAttachments,
    83  	model.ENCRYPT:                 processEncryption,
    84  	model.DECRYPT:                 processEncryption,
    85  	model.CHANGEUPW:               processEncryption,
    86  	model.CHANGEOPW:               processEncryption,
    87  	model.LISTPERMISSIONS:         processPermissions,
    88  	model.SETPERMISSIONS:          processPermissions,
    89  	model.IMPORTIMAGES:            ImportImages,
    90  	model.INSERTPAGESBEFORE:       processPages,
    91  	model.INSERTPAGESAFTER:        processPages,
    92  	model.REMOVEPAGES:             processPages,
    93  	model.ROTATE:                  Rotate,
    94  	model.NUP:                     NUp,
    95  	model.BOOKLET:                 Booklet,
    96  	model.LISTINFO:                ListInfo,
    97  	model.CHEATSHEETSFONTS:        CreateCheatSheetsFonts,
    98  	model.INSTALLFONTS:            InstallFonts,
    99  	model.LISTFONTS:               ListFonts,
   100  	model.LISTKEYWORDS:            processKeywords,
   101  	model.ADDKEYWORDS:             processKeywords,
   102  	model.REMOVEKEYWORDS:          processKeywords,
   103  	model.LISTPROPERTIES:          processProperties,
   104  	model.ADDPROPERTIES:           processProperties,
   105  	model.REMOVEPROPERTIES:        processProperties,
   106  	model.COLLECT:                 Collect,
   107  	model.LISTBOXES:               processPageBoundaries,
   108  	model.ADDBOXES:                processPageBoundaries,
   109  	model.REMOVEBOXES:             processPageBoundaries,
   110  	model.CROP:                    processPageBoundaries,
   111  	model.LISTANNOTATIONS:         processPageAnnotations,
   112  	model.REMOVEANNOTATIONS:       processPageAnnotations,
   113  	model.LISTIMAGES:              processImages,
   114  	model.UPDATEIMAGES:            processImages,
   115  	model.DUMP:                    Dump,
   116  	model.CREATE:                  Create,
   117  	model.LISTFORMFIELDS:          processForm,
   118  	model.REMOVEFORMFIELDS:        processForm,
   119  	model.LOCKFORMFIELDS:          processForm,
   120  	model.UNLOCKFORMFIELDS:        processForm,
   121  	model.RESETFORMFIELDS:         processForm,
   122  	model.EXPORTFORMFIELDS:        processForm,
   123  	model.FILLFORMFIELDS:          processForm,
   124  	model.MULTIFILLFORMFIELDS:     processForm,
   125  	model.RESIZE:                  Resize,
   126  	model.POSTER:                  Poster,
   127  	model.NDOWN:                   NDown,
   128  	model.CUT:                     Cut,
   129  	model.LISTBOOKMARKS:           processBookmarks,
   130  	model.EXPORTBOOKMARKS:         processBookmarks,
   131  	model.IMPORTBOOKMARKS:         processBookmarks,
   132  	model.REMOVEBOOKMARKS:         processBookmarks,
   133  	model.LISTPAGEMODE:            processPageMode,
   134  	model.SETPAGEMODE:             processPageMode,
   135  	model.RESETPAGEMODE:           processPageMode,
   136  	model.LISTPAGELAYOUT:          processPageLayout,
   137  	model.SETPAGELAYOUT:           processPageLayout,
   138  	model.RESETPAGELAYOUT:         processPageLayout,
   139  	model.LISTVIEWERPREFERENCES:   processViewerPreferences,
   140  	model.SETVIEWERPREFERENCES:    processViewerPreferences,
   141  	model.RESETVIEWERPREFERENCES:  processViewerPreferences,
   142  	model.ZOOM:                    Zoom,
   143  	model.LISTCERTIFICATES:        processCertificates,
   144  	model.INSPECTCERTIFICATES:     processCertificates,
   145  	model.IMPORTCERTIFICATES:      processCertificates,
   146  	model.VALIDATESIGNATURES:      processSignatures,
   147  }
   148  
   149  // ValidateCommand creates a new command to validate a file.
   150  func ValidateCommand(inFiles []string, conf *model.Configuration) *Command {
   151  	if conf == nil {
   152  		conf = model.NewDefaultConfiguration()
   153  	}
   154  	conf.Cmd = model.VALIDATE
   155  	return &Command{
   156  		Mode:    model.VALIDATE,
   157  		InFiles: inFiles,
   158  		Conf:    conf}
   159  }
   160  
   161  // OptimizeCommand creates a new command to optimize a file.
   162  func OptimizeCommand(inFile, outFile string, conf *model.Configuration) *Command {
   163  	if conf == nil {
   164  		conf = model.NewDefaultConfiguration()
   165  	}
   166  	conf.Cmd = model.OPTIMIZE
   167  	return &Command{
   168  		Mode:    model.OPTIMIZE,
   169  		InFile:  &inFile,
   170  		OutFile: &outFile,
   171  		Conf:    conf}
   172  }
   173  
   174  // SplitCommand creates a new command to split a file according to span or along bookmarks..
   175  func SplitCommand(inFile, dirNameOut string, span int, conf *model.Configuration) *Command {
   176  	if conf == nil {
   177  		conf = model.NewDefaultConfiguration()
   178  	}
   179  	conf.Cmd = model.SPLIT
   180  	return &Command{
   181  		Mode:   model.SPLIT,
   182  		InFile: &inFile,
   183  		OutDir: &dirNameOut,
   184  		IntVal: span,
   185  		Conf:   conf}
   186  }
   187  
   188  // SplitByPageNrCommand creates a new command to split a file into files along given pages.
   189  func SplitByPageNrCommand(inFile, dirNameOut string, pageNrs []int, conf *model.Configuration) *Command {
   190  	if conf == nil {
   191  		conf = model.NewDefaultConfiguration()
   192  	}
   193  	conf.Cmd = model.SPLITBYPAGENR
   194  	return &Command{
   195  		Mode:    model.SPLITBYPAGENR,
   196  		InFile:  &inFile,
   197  		OutDir:  &dirNameOut,
   198  		IntVals: pageNrs,
   199  		Conf:    conf}
   200  }
   201  
   202  // MergeCreateCommand creates a new command to merge files.
   203  // Outfile will be created. An existing outFile will be overwritten.
   204  func MergeCreateCommand(inFiles []string, outFile string, dividerPage bool, conf *model.Configuration) *Command {
   205  	if conf == nil {
   206  		conf = model.NewDefaultConfiguration()
   207  	}
   208  	conf.Cmd = model.MERGECREATE
   209  	return &Command{
   210  		Mode:     model.MERGECREATE,
   211  		InFiles:  inFiles,
   212  		OutFile:  &outFile,
   213  		BoolVal1: dividerPage,
   214  		Conf:     conf}
   215  }
   216  
   217  // MergeCreateZipCommand creates a new command to zip merge 2 files.
   218  // Outfile will be created. An existing outFile will be overwritten.
   219  func MergeCreateZipCommand(inFiles []string, outFile string, conf *model.Configuration) *Command {
   220  	if conf == nil {
   221  		conf = model.NewDefaultConfiguration()
   222  	}
   223  	conf.Cmd = model.MERGECREATEZIP
   224  	return &Command{
   225  		Mode:    model.MERGECREATEZIP,
   226  		InFiles: inFiles,
   227  		OutFile: &outFile,
   228  		Conf:    conf}
   229  }
   230  
   231  // MergeAppendCommand creates a new command to merge files.
   232  // Any existing outFile PDF content will be preserved and serves as the beginning of the merge result.
   233  func MergeAppendCommand(inFiles []string, outFile string, dividerPage bool, conf *model.Configuration) *Command {
   234  	if conf == nil {
   235  		conf = model.NewDefaultConfiguration()
   236  	}
   237  	conf.Cmd = model.MERGEAPPEND
   238  	return &Command{
   239  		Mode:     model.MERGEAPPEND,
   240  		InFiles:  inFiles,
   241  		OutFile:  &outFile,
   242  		BoolVal1: dividerPage,
   243  		Conf:     conf}
   244  }
   245  
   246  // ExtractImagesCommand creates a new command to extract embedded images.
   247  // (experimental)
   248  func ExtractImagesCommand(inFile string, outDir string, pageSelection []string, conf *model.Configuration) *Command {
   249  	if conf == nil {
   250  		conf = model.NewDefaultConfiguration()
   251  	}
   252  	conf.Cmd = model.EXTRACTIMAGES
   253  	return &Command{
   254  		Mode:          model.EXTRACTIMAGES,
   255  		InFile:        &inFile,
   256  		OutDir:        &outDir,
   257  		PageSelection: pageSelection,
   258  		Conf:          conf}
   259  }
   260  
   261  // ExtractFontsCommand creates a new command to extract embedded fonts.
   262  // (experimental)
   263  func ExtractFontsCommand(inFile string, outDir string, pageSelection []string, conf *model.Configuration) *Command {
   264  	if conf == nil {
   265  		conf = model.NewDefaultConfiguration()
   266  	}
   267  	conf.Cmd = model.EXTRACTFONTS
   268  	return &Command{
   269  		Mode:          model.EXTRACTFONTS,
   270  		InFile:        &inFile,
   271  		OutDir:        &outDir,
   272  		PageSelection: pageSelection,
   273  		Conf:          conf}
   274  }
   275  
   276  // ExtractPagesCommand creates a new command to extract specific pages of a file.
   277  func ExtractPagesCommand(inFile string, outDir string, pageSelection []string, conf *model.Configuration) *Command {
   278  	if conf == nil {
   279  		conf = model.NewDefaultConfiguration()
   280  	}
   281  	conf.Cmd = model.EXTRACTPAGES
   282  	return &Command{
   283  		Mode:          model.EXTRACTPAGES,
   284  		InFile:        &inFile,
   285  		OutDir:        &outDir,
   286  		PageSelection: pageSelection,
   287  		Conf:          conf}
   288  }
   289  
   290  // ExtractContentCommand creates a new command to extract page content streams.
   291  func ExtractContentCommand(inFile string, outDir string, pageSelection []string, conf *model.Configuration) *Command {
   292  	if conf == nil {
   293  		conf = model.NewDefaultConfiguration()
   294  	}
   295  	conf.Cmd = model.EXTRACTCONTENT
   296  	return &Command{
   297  		Mode:          model.EXTRACTCONTENT,
   298  		InFile:        &inFile,
   299  		OutDir:        &outDir,
   300  		PageSelection: pageSelection,
   301  		Conf:          conf}
   302  }
   303  
   304  // ExtractMetadataCommand creates a new command to extract metadata streams.
   305  func ExtractMetadataCommand(inFile string, outDir string, conf *model.Configuration) *Command {
   306  	if conf == nil {
   307  		conf = model.NewDefaultConfiguration()
   308  	}
   309  	conf.Cmd = model.EXTRACTMETADATA
   310  	return &Command{
   311  		Mode:   model.EXTRACTMETADATA,
   312  		InFile: &inFile,
   313  		OutDir: &outDir,
   314  		Conf:   conf}
   315  }
   316  
   317  // TrimCommand creates a new command to trim the pages of a file.
   318  func TrimCommand(inFile, outFile string, pageSelection []string, conf *model.Configuration) *Command {
   319  	if conf == nil {
   320  		conf = model.NewDefaultConfiguration()
   321  	}
   322  	conf.Cmd = model.TRIM
   323  	return &Command{
   324  		Mode:          model.TRIM,
   325  		InFile:        &inFile,
   326  		OutFile:       &outFile,
   327  		PageSelection: pageSelection,
   328  		Conf:          conf}
   329  }
   330  
   331  // ListAttachmentsCommand create a new command to list attachments.
   332  func ListAttachmentsCommand(inFile string, conf *model.Configuration) *Command {
   333  	if conf == nil {
   334  		conf = model.NewDefaultConfiguration()
   335  	}
   336  	conf.Cmd = model.LISTATTACHMENTS
   337  	return &Command{
   338  		Mode:   model.LISTATTACHMENTS,
   339  		InFile: &inFile,
   340  		Conf:   conf}
   341  }
   342  
   343  // AddAttachmentsCommand creates a new command to add attachments.
   344  func AddAttachmentsCommand(inFile, outFile string, fileNames []string, conf *model.Configuration) *Command {
   345  	if conf == nil {
   346  		conf = model.NewDefaultConfiguration()
   347  	}
   348  	conf.Cmd = model.ADDATTACHMENTS
   349  	return &Command{
   350  		Mode:    model.ADDATTACHMENTS,
   351  		InFile:  &inFile,
   352  		OutFile: &outFile,
   353  		InFiles: fileNames,
   354  		Conf:    conf}
   355  }
   356  
   357  // AddAttachmentsPortfolioCommand creates a new command to add attachments to a portfolio.
   358  func AddAttachmentsPortfolioCommand(inFile, outFile string, fileNames []string, conf *model.Configuration) *Command {
   359  	if conf == nil {
   360  		conf = model.NewDefaultConfiguration()
   361  	}
   362  	conf.Cmd = model.ADDATTACHMENTSPORTFOLIO
   363  	return &Command{
   364  		Mode:    model.ADDATTACHMENTSPORTFOLIO,
   365  		InFile:  &inFile,
   366  		OutFile: &outFile,
   367  		InFiles: fileNames,
   368  		Conf:    conf}
   369  }
   370  
   371  // RemoveAttachmentsCommand creates a new command to remove attachments.
   372  func RemoveAttachmentsCommand(inFile, outFile string, fileNames []string, conf *model.Configuration) *Command {
   373  	if conf == nil {
   374  		conf = model.NewDefaultConfiguration()
   375  	}
   376  	conf.Cmd = model.REMOVEATTACHMENTS
   377  	return &Command{
   378  		Mode:    model.REMOVEATTACHMENTS,
   379  		InFile:  &inFile,
   380  		OutFile: &outFile,
   381  		InFiles: fileNames,
   382  		Conf:    conf}
   383  }
   384  
   385  // ExtractAttachmentsCommand creates a new command to extract attachments.
   386  func ExtractAttachmentsCommand(inFile string, outDir string, fileNames []string, conf *model.Configuration) *Command {
   387  	if conf == nil {
   388  		conf = model.NewDefaultConfiguration()
   389  	}
   390  	conf.Cmd = model.EXTRACTATTACHMENTS
   391  	return &Command{
   392  		Mode:    model.EXTRACTATTACHMENTS,
   393  		InFile:  &inFile,
   394  		OutDir:  &outDir,
   395  		InFiles: fileNames,
   396  		Conf:    conf}
   397  }
   398  
   399  // EncryptCommand creates a new command to encrypt a file.
   400  func EncryptCommand(inFile, outFile string, conf *model.Configuration) *Command {
   401  	if conf == nil {
   402  		conf = model.NewDefaultConfiguration()
   403  	}
   404  	conf.Cmd = model.ENCRYPT
   405  	return &Command{
   406  		Mode:    model.ENCRYPT,
   407  		InFile:  &inFile,
   408  		OutFile: &outFile,
   409  		Conf:    conf}
   410  }
   411  
   412  // DecryptCommand creates a new command to decrypt a file.
   413  func DecryptCommand(inFile, outFile string, conf *model.Configuration) *Command {
   414  	if conf == nil {
   415  		conf = model.NewDefaultConfiguration()
   416  	}
   417  	conf.Cmd = model.DECRYPT
   418  	return &Command{
   419  		Mode:    model.DECRYPT,
   420  		InFile:  &inFile,
   421  		OutFile: &outFile,
   422  		Conf:    conf}
   423  }
   424  
   425  // ChangeUserPWCommand creates a new command to change the user password.
   426  func ChangeUserPWCommand(inFile, outFile string, pwOld, pwNew *string, conf *model.Configuration) *Command {
   427  	if conf == nil {
   428  		conf = model.NewDefaultConfiguration()
   429  	}
   430  	conf.Cmd = model.CHANGEUPW
   431  	return &Command{
   432  		Mode:    model.CHANGEUPW,
   433  		InFile:  &inFile,
   434  		OutFile: &outFile,
   435  		PWOld:   pwOld,
   436  		PWNew:   pwNew,
   437  		Conf:    conf}
   438  }
   439  
   440  // ChangeOwnerPWCommand creates a new command to change the owner password.
   441  func ChangeOwnerPWCommand(inFile, outFile string, pwOld, pwNew *string, conf *model.Configuration) *Command {
   442  	if conf == nil {
   443  		conf = model.NewDefaultConfiguration()
   444  	}
   445  	conf.Cmd = model.CHANGEOPW
   446  	return &Command{
   447  		Mode:    model.CHANGEOPW,
   448  		InFile:  &inFile,
   449  		OutFile: &outFile,
   450  		PWOld:   pwOld,
   451  		PWNew:   pwNew,
   452  		Conf:    conf}
   453  }
   454  
   455  // ListPermissionsCommand create a new command to list permissions.
   456  func ListPermissionsCommand(inFiles []string, conf *model.Configuration) *Command {
   457  	if conf == nil {
   458  		conf = model.NewDefaultConfiguration()
   459  	}
   460  	conf.Cmd = model.LISTPERMISSIONS
   461  	return &Command{
   462  		Mode:    model.LISTPERMISSIONS,
   463  		InFiles: inFiles,
   464  		Conf:    conf}
   465  }
   466  
   467  // SetPermissionsCommand creates a new command to add permissions.
   468  func SetPermissionsCommand(inFile, outFile string, conf *model.Configuration) *Command {
   469  	if conf == nil {
   470  		conf = model.NewDefaultConfiguration()
   471  	}
   472  	conf.Cmd = model.SETPERMISSIONS
   473  	return &Command{
   474  		Mode:    model.SETPERMISSIONS,
   475  		InFile:  &inFile,
   476  		OutFile: &outFile,
   477  		Conf:    conf}
   478  }
   479  
   480  // AddWatermarksCommand creates a new command to add Watermarks to a file.
   481  func AddWatermarksCommand(inFile, outFile string, pageSelection []string, wm *model.Watermark, conf *model.Configuration) *Command {
   482  	if conf == nil {
   483  		conf = model.NewDefaultConfiguration()
   484  	}
   485  	conf.Cmd = model.ADDWATERMARKS
   486  	return &Command{
   487  		Mode:          model.ADDWATERMARKS,
   488  		InFile:        &inFile,
   489  		OutFile:       &outFile,
   490  		PageSelection: pageSelection,
   491  		Watermark:     wm,
   492  		Conf:          conf}
   493  }
   494  
   495  // RemoveWatermarksCommand creates a new command to remove Watermarks from a file.
   496  func RemoveWatermarksCommand(inFile, outFile string, pageSelection []string, conf *model.Configuration) *Command {
   497  	if conf == nil {
   498  		conf = model.NewDefaultConfiguration()
   499  	}
   500  	conf.Cmd = model.REMOVEWATERMARKS
   501  	return &Command{
   502  		Mode:          model.REMOVEWATERMARKS,
   503  		InFile:        &inFile,
   504  		OutFile:       &outFile,
   505  		PageSelection: pageSelection,
   506  		Conf:          conf}
   507  }
   508  
   509  // ImportImagesCommand creates a new command to import images.
   510  func ImportImagesCommand(imageFiles []string, outFile string, imp *pdfcpu.Import, conf *model.Configuration) *Command {
   511  	if conf == nil {
   512  		conf = model.NewDefaultConfiguration()
   513  	}
   514  	conf.Cmd = model.IMPORTIMAGES
   515  	return &Command{
   516  		Mode:    model.IMPORTIMAGES,
   517  		InFiles: imageFiles,
   518  		OutFile: &outFile,
   519  		Import:  imp,
   520  		Conf:    conf}
   521  }
   522  
   523  // InsertPagesCommand creates a new command to insert a blank page before or after selected pages.
   524  func InsertPagesCommand(inFile, outFile string, pageSelection []string, conf *model.Configuration, mode string, pageConf *pdfcpu.PageConfiguration) *Command {
   525  	if conf == nil {
   526  		conf = model.NewDefaultConfiguration()
   527  	}
   528  	cmdMode := model.INSERTPAGESBEFORE
   529  	if mode == "after" {
   530  		cmdMode = model.INSERTPAGESAFTER
   531  	}
   532  	conf.Cmd = cmdMode
   533  	return &Command{
   534  		Mode:          cmdMode,
   535  		InFile:        &inFile,
   536  		OutFile:       &outFile,
   537  		PageSelection: pageSelection,
   538  		PageConf:      pageConf,
   539  		Conf:          conf}
   540  }
   541  
   542  // RemovePagesCommand creates a new command to remove selected pages.
   543  func RemovePagesCommand(inFile, outFile string, pageSelection []string, conf *model.Configuration) *Command {
   544  	if conf == nil {
   545  		conf = model.NewDefaultConfiguration()
   546  	}
   547  	conf.Cmd = model.REMOVEPAGES
   548  	return &Command{
   549  		Mode:          model.REMOVEPAGES,
   550  		InFile:        &inFile,
   551  		OutFile:       &outFile,
   552  		PageSelection: pageSelection,
   553  		Conf:          conf}
   554  }
   555  
   556  // RotateCommand creates a new command to rotate pages.
   557  func RotateCommand(inFile, outFile string, rotation int, pageSelection []string, conf *model.Configuration) *Command {
   558  	if conf == nil {
   559  		conf = model.NewDefaultConfiguration()
   560  	}
   561  	conf.Cmd = model.ROTATE
   562  	return &Command{
   563  		Mode:          model.ROTATE,
   564  		InFile:        &inFile,
   565  		OutFile:       &outFile,
   566  		PageSelection: pageSelection,
   567  		IntVal:        rotation,
   568  		Conf:          conf}
   569  }
   570  
   571  // NUpCommand creates a new command to render PDFs or image files in n-up fashion.
   572  func NUpCommand(inFiles []string, outFile string, pageSelection []string, nUp *model.NUp, conf *model.Configuration) *Command {
   573  	if conf == nil {
   574  		conf = model.NewDefaultConfiguration()
   575  	}
   576  	conf.Cmd = model.NUP
   577  	return &Command{
   578  		Mode:          model.NUP,
   579  		InFiles:       inFiles,
   580  		OutFile:       &outFile,
   581  		PageSelection: pageSelection,
   582  		NUp:           nUp,
   583  		Conf:          conf}
   584  }
   585  
   586  // BookletCommand creates a new command to render PDFs or image files in booklet fashion.
   587  func BookletCommand(inFiles []string, outFile string, pageSelection []string, nup *model.NUp, conf *model.Configuration) *Command {
   588  	if conf == nil {
   589  		conf = model.NewDefaultConfiguration()
   590  	}
   591  	conf.Cmd = model.BOOKLET
   592  	return &Command{
   593  		Mode:          model.BOOKLET,
   594  		InFiles:       inFiles,
   595  		OutFile:       &outFile,
   596  		PageSelection: pageSelection,
   597  		NUp:           nup,
   598  		Conf:          conf}
   599  }
   600  
   601  // InfoCommand creates a new command to output information about inFile.
   602  func InfoCommand(inFiles []string, pageSelection []string, fonts, json bool, conf *model.Configuration) *Command {
   603  	if conf == nil {
   604  		conf = model.NewDefaultConfiguration()
   605  	}
   606  	conf.Cmd = model.LISTINFO
   607  	return &Command{
   608  		Mode:          model.LISTINFO,
   609  		InFiles:       inFiles,
   610  		PageSelection: pageSelection,
   611  		BoolVal1:      fonts,
   612  		BoolVal2:      json,
   613  		Conf:          conf}
   614  }
   615  
   616  // ListFontsCommand returns a list of supported fonts.
   617  func ListFontsCommand(conf *model.Configuration) *Command {
   618  	if conf == nil {
   619  		conf = model.NewDefaultConfiguration()
   620  	}
   621  	conf.Cmd = model.LISTFONTS
   622  	return &Command{
   623  		Mode: model.LISTFONTS,
   624  		Conf: conf}
   625  }
   626  
   627  // InstallFontsCommand installs true type fonts for embedding.
   628  func InstallFontsCommand(fontFiles []string, conf *model.Configuration) *Command {
   629  	if conf == nil {
   630  		conf = model.NewDefaultConfiguration()
   631  	}
   632  	conf.Cmd = model.INSTALLFONTS
   633  	return &Command{
   634  		Mode:    model.INSTALLFONTS,
   635  		InFiles: fontFiles,
   636  		Conf:    conf}
   637  }
   638  
   639  // CreateCheatSheetsFontsCommand creates single page PDF cheat sheets in current dir.
   640  func CreateCheatSheetsFontsCommand(fontFiles []string, conf *model.Configuration) *Command {
   641  	if conf == nil {
   642  		conf = model.NewDefaultConfiguration()
   643  	}
   644  	conf.Cmd = model.CHEATSHEETSFONTS
   645  	return &Command{
   646  		Mode:    model.CHEATSHEETSFONTS,
   647  		InFiles: fontFiles,
   648  		Conf:    conf}
   649  }
   650  
   651  // ListKeywordsCommand create a new command to list keywords.
   652  func ListKeywordsCommand(inFile string, conf *model.Configuration) *Command {
   653  	if conf == nil {
   654  		conf = model.NewDefaultConfiguration()
   655  	}
   656  	conf.Cmd = model.LISTKEYWORDS
   657  	return &Command{
   658  		Mode:   model.LISTKEYWORDS,
   659  		InFile: &inFile,
   660  		Conf:   conf}
   661  }
   662  
   663  // AddKeywordsCommand creates a new command to add keywords.
   664  func AddKeywordsCommand(inFile, outFile string, keywords []string, conf *model.Configuration) *Command {
   665  	if conf == nil {
   666  		conf = model.NewDefaultConfiguration()
   667  	}
   668  	conf.Cmd = model.ADDKEYWORDS
   669  	return &Command{
   670  		Mode:       model.ADDKEYWORDS,
   671  		InFile:     &inFile,
   672  		OutFile:    &outFile,
   673  		StringVals: keywords,
   674  		Conf:       conf}
   675  }
   676  
   677  // RemoveKeywordsCommand creates a new command to remove keywords.
   678  func RemoveKeywordsCommand(inFile, outFile string, keywords []string, conf *model.Configuration) *Command {
   679  	if conf == nil {
   680  		conf = model.NewDefaultConfiguration()
   681  	}
   682  	conf.Cmd = model.REMOVEKEYWORDS
   683  	return &Command{
   684  		Mode:       model.REMOVEKEYWORDS,
   685  		InFile:     &inFile,
   686  		OutFile:    &outFile,
   687  		StringVals: keywords,
   688  		Conf:       conf}
   689  }
   690  
   691  // ListPropertiesCommand creates a new command to list document properties.
   692  func ListPropertiesCommand(inFile string, conf *model.Configuration) *Command {
   693  	if conf == nil {
   694  		conf = model.NewDefaultConfiguration()
   695  	}
   696  	conf.Cmd = model.LISTPROPERTIES
   697  	return &Command{
   698  		Mode:   model.LISTPROPERTIES,
   699  		InFile: &inFile,
   700  		Conf:   conf}
   701  }
   702  
   703  // AddPropertiesCommand creates a new command to add document properties.
   704  func AddPropertiesCommand(inFile, outFile string, properties map[string]string, conf *model.Configuration) *Command {
   705  	if conf == nil {
   706  		conf = model.NewDefaultConfiguration()
   707  	}
   708  	conf.Cmd = model.ADDPROPERTIES
   709  	return &Command{
   710  		Mode:      model.ADDPROPERTIES,
   711  		InFile:    &inFile,
   712  		OutFile:   &outFile,
   713  		StringMap: properties,
   714  		Conf:      conf}
   715  }
   716  
   717  // RemovePropertiesCommand creates a new command to remove document properties.
   718  func RemovePropertiesCommand(inFile, outFile string, propKeys []string, conf *model.Configuration) *Command {
   719  	if conf == nil {
   720  		conf = model.NewDefaultConfiguration()
   721  	}
   722  	conf.Cmd = model.REMOVEPROPERTIES
   723  	return &Command{
   724  		Mode:       model.REMOVEPROPERTIES,
   725  		InFile:     &inFile,
   726  		OutFile:    &outFile,
   727  		StringVals: propKeys,
   728  		Conf:       conf}
   729  }
   730  
   731  // CollectCommand creates a new command to create a custom PDF page sequence.
   732  func CollectCommand(inFile, outFile string, pageSelection []string, conf *model.Configuration) *Command {
   733  	if conf == nil {
   734  		conf = model.NewDefaultConfiguration()
   735  	}
   736  	conf.Cmd = model.COLLECT
   737  	return &Command{
   738  		Mode:          model.COLLECT,
   739  		InFile:        &inFile,
   740  		OutFile:       &outFile,
   741  		PageSelection: pageSelection,
   742  		Conf:          conf}
   743  }
   744  
   745  // ListBoxesCommand creates a new command to list page boundaries for selected pages.
   746  func ListBoxesCommand(inFile string, pageSelection []string, pb *model.PageBoundaries, conf *model.Configuration) *Command {
   747  	if conf == nil {
   748  		conf = model.NewDefaultConfiguration()
   749  	}
   750  	conf.Cmd = model.LISTBOXES
   751  	return &Command{
   752  		Mode:           model.LISTBOXES,
   753  		InFile:         &inFile,
   754  		PageSelection:  pageSelection,
   755  		PageBoundaries: pb,
   756  		Conf:           conf}
   757  }
   758  
   759  // AddBoxesCommand creates a new command to add page boundaries for selected pages.
   760  func AddBoxesCommand(inFile, outFile string, pageSelection []string, pb *model.PageBoundaries, conf *model.Configuration) *Command {
   761  	if conf == nil {
   762  		conf = model.NewDefaultConfiguration()
   763  	}
   764  	conf.Cmd = model.ADDBOXES
   765  	return &Command{
   766  		Mode:           model.ADDBOXES,
   767  		InFile:         &inFile,
   768  		OutFile:        &outFile,
   769  		PageSelection:  pageSelection,
   770  		PageBoundaries: pb,
   771  		Conf:           conf}
   772  }
   773  
   774  // RemoveBoxesCommand creates a new command to remove page boundaries for selected pages.
   775  func RemoveBoxesCommand(inFile, outFile string, pageSelection []string, pb *model.PageBoundaries, conf *model.Configuration) *Command {
   776  	if conf == nil {
   777  		conf = model.NewDefaultConfiguration()
   778  	}
   779  	conf.Cmd = model.REMOVEBOXES
   780  	return &Command{
   781  		Mode:           model.REMOVEBOXES,
   782  		InFile:         &inFile,
   783  		OutFile:        &outFile,
   784  		PageSelection:  pageSelection,
   785  		PageBoundaries: pb,
   786  		Conf:           conf}
   787  }
   788  
   789  // CropCommand creates a new command to apply a cropBox to selected pages.
   790  func CropCommand(inFile, outFile string, pageSelection []string, box *model.Box, conf *model.Configuration) *Command {
   791  	if conf == nil {
   792  		conf = model.NewDefaultConfiguration()
   793  	}
   794  	conf.Cmd = model.CROP
   795  	return &Command{
   796  		Mode:          model.CROP,
   797  		InFile:        &inFile,
   798  		OutFile:       &outFile,
   799  		PageSelection: pageSelection,
   800  		Box:           box,
   801  		Conf:          conf}
   802  }
   803  
   804  // ListAnnotationsCommand creates a new command to list annotations for selected pages.
   805  func ListAnnotationsCommand(inFile string, pageSelection []string, conf *model.Configuration) *Command {
   806  	if conf == nil {
   807  		conf = model.NewDefaultConfiguration()
   808  	}
   809  	conf.Cmd = model.LISTANNOTATIONS
   810  	return &Command{
   811  		Mode:          model.LISTANNOTATIONS,
   812  		InFile:        &inFile,
   813  		PageSelection: pageSelection,
   814  		Conf:          conf}
   815  }
   816  
   817  // RemoveAnnotationsCommand creates a new command to remove annotations for selected pages.
   818  func RemoveAnnotationsCommand(inFile, outFile string, pageSelection []string, idsAndTypes []string, objNrs []int, conf *model.Configuration) *Command {
   819  	if conf == nil {
   820  		conf = model.NewDefaultConfiguration()
   821  	}
   822  	conf.Cmd = model.REMOVEANNOTATIONS
   823  	return &Command{
   824  		Mode:          model.REMOVEANNOTATIONS,
   825  		InFile:        &inFile,
   826  		OutFile:       &outFile,
   827  		PageSelection: pageSelection,
   828  		StringVals:    idsAndTypes,
   829  		IntVals:       objNrs,
   830  		Conf:          conf}
   831  }
   832  
   833  // ListImagesCommand creates a new command to list annotations for selected pages.
   834  func ListImagesCommand(inFiles []string, pageSelection []string, conf *model.Configuration) *Command {
   835  	if conf == nil {
   836  		conf = model.NewDefaultConfiguration()
   837  	}
   838  	conf.Cmd = model.LISTIMAGES
   839  	return &Command{
   840  		Mode:          model.LISTIMAGES,
   841  		InFiles:       inFiles,
   842  		PageSelection: pageSelection,
   843  		Conf:          conf}
   844  }
   845  
   846  // UpdateImagesCommand creates a new command to update images.
   847  func UpdateImagesCommand(inFile, imageFile, outFile string, objNrOrPageNr int, id string, conf *model.Configuration) *Command {
   848  	if conf == nil {
   849  		conf = model.NewDefaultConfiguration()
   850  	}
   851  	conf.Cmd = model.UPDATEIMAGES
   852  
   853  	return &Command{
   854  		Mode:      model.UPDATEIMAGES,
   855  		InFiles:   []string{inFile, imageFile},
   856  		OutFile:   &outFile,
   857  		IntVal:    objNrOrPageNr,
   858  		StringVal: id,
   859  		Conf:      conf}
   860  }
   861  
   862  // DumpCommand creates a new command to dump objects on stdout.
   863  func DumpCommand(inFilePDF string, vals []int, conf *model.Configuration) *Command {
   864  	if conf == nil {
   865  		conf = model.NewDefaultConfiguration()
   866  	}
   867  	conf.Cmd = model.DUMP
   868  	return &Command{
   869  		Mode:    model.DUMP,
   870  		InFile:  &inFilePDF,
   871  		IntVals: vals,
   872  		Conf:    conf}
   873  }
   874  
   875  // CreateCommand creates a new command to create a PDF file.
   876  func CreateCommand(inFilePDF, inFileJSON, outFilePDF string, conf *model.Configuration) *Command {
   877  	if conf == nil {
   878  		conf = model.NewDefaultConfiguration()
   879  	}
   880  	conf.Cmd = model.CREATE
   881  	return &Command{
   882  		Mode:       model.CREATE,
   883  		InFile:     &inFilePDF,
   884  		InFileJSON: &inFileJSON,
   885  		OutFile:    &outFilePDF,
   886  		Conf:       conf}
   887  }
   888  
   889  // ListFormFieldsCommand creates a new command to list the field ids from a PDF form.
   890  func ListFormFieldsCommand(inFiles []string, conf *model.Configuration) *Command {
   891  	if conf == nil {
   892  		conf = model.NewDefaultConfiguration()
   893  	}
   894  	conf.Cmd = model.LISTFORMFIELDS
   895  	return &Command{
   896  		Mode:    model.LISTFORMFIELDS,
   897  		InFiles: inFiles,
   898  		Conf:    conf}
   899  }
   900  
   901  // RemoveFormFieldsCommand creates a new command to remove fields from a PDF form.
   902  func RemoveFormFieldsCommand(inFile, outFile string, fieldIDs []string, conf *model.Configuration) *Command {
   903  	if conf == nil {
   904  		conf = model.NewDefaultConfiguration()
   905  	}
   906  	conf.Cmd = model.REMOVEFORMFIELDS
   907  	return &Command{
   908  		Mode:       model.REMOVEFORMFIELDS,
   909  		InFile:     &inFile,
   910  		OutFile:    &outFile,
   911  		StringVals: fieldIDs,
   912  		Conf:       conf}
   913  }
   914  
   915  // LockFormCommand creates a new command to lock PDF form fields.
   916  func LockFormCommand(inFile, outFile string, fieldIDs []string, conf *model.Configuration) *Command {
   917  	if conf == nil {
   918  		conf = model.NewDefaultConfiguration()
   919  	}
   920  	conf.Cmd = model.LOCKFORMFIELDS
   921  	return &Command{
   922  		Mode:       model.LOCKFORMFIELDS,
   923  		InFile:     &inFile,
   924  		OutFile:    &outFile,
   925  		StringVals: fieldIDs,
   926  		Conf:       conf}
   927  }
   928  
   929  // UnlockFormCommand creates a new command to unlock PDF form fields.
   930  func UnlockFormCommand(inFile, outFile string, fieldIDs []string, conf *model.Configuration) *Command {
   931  	if conf == nil {
   932  		conf = model.NewDefaultConfiguration()
   933  	}
   934  	conf.Cmd = model.UNLOCKFORMFIELDS
   935  	return &Command{
   936  		Mode:       model.UNLOCKFORMFIELDS,
   937  		InFile:     &inFile,
   938  		OutFile:    &outFile,
   939  		StringVals: fieldIDs,
   940  		Conf:       conf}
   941  }
   942  
   943  // ResetFormCommand creates a new command to lock PDF form fields.
   944  func ResetFormCommand(inFile, outFile string, fieldIDs []string, conf *model.Configuration) *Command {
   945  	if conf == nil {
   946  		conf = model.NewDefaultConfiguration()
   947  	}
   948  	conf.Cmd = model.RESETFORMFIELDS
   949  	return &Command{
   950  		Mode:       model.RESETFORMFIELDS,
   951  		InFile:     &inFile,
   952  		OutFile:    &outFile,
   953  		StringVals: fieldIDs,
   954  		Conf:       conf}
   955  }
   956  
   957  // ExportFormCommand creates a new command to export a PDF form.
   958  func ExportFormCommand(inFilePDF, outFileJSON string, conf *model.Configuration) *Command {
   959  	if conf == nil {
   960  		conf = model.NewDefaultConfiguration()
   961  	}
   962  	conf.Cmd = model.EXPORTFORMFIELDS
   963  	return &Command{
   964  		Mode:        model.EXPORTFORMFIELDS,
   965  		InFile:      &inFilePDF,
   966  		OutFileJSON: &outFileJSON,
   967  		Conf:        conf}
   968  }
   969  
   970  // FillFormCommand creates a new command to fill a PDF form with data.
   971  func FillFormCommand(inFilePDF, inFileJSON, outFilePDF string, conf *model.Configuration) *Command {
   972  	if conf == nil {
   973  		conf = model.NewDefaultConfiguration()
   974  	}
   975  	conf.Cmd = model.FILLFORMFIELDS
   976  	return &Command{
   977  		Mode:       model.FILLFORMFIELDS,
   978  		InFile:     &inFilePDF,
   979  		InFileJSON: &inFileJSON,
   980  		OutFile:    &outFilePDF,
   981  		Conf:       conf}
   982  }
   983  
   984  // MultiFillFormCommand creates a new command to fill multiple PDF forms with JSON or CSV data.
   985  func MultiFillFormCommand(inFilePDF, inFileData, outDir, outFilePDF string, merge bool, conf *model.Configuration) *Command {
   986  	if conf == nil {
   987  		conf = model.NewDefaultConfiguration()
   988  	}
   989  	conf.Cmd = model.MULTIFILLFORMFIELDS
   990  	return &Command{
   991  		Mode:       model.MULTIFILLFORMFIELDS,
   992  		InFile:     &inFilePDF,
   993  		InFileJSON: &inFileData, // TODO Fix name clash.
   994  		OutDir:     &outDir,
   995  		OutFile:    &outFilePDF,
   996  		BoolVal1:   merge,
   997  		Conf:       conf}
   998  }
   999  
  1000  // ResizeCommand creates a new command to scale selected pages.
  1001  func ResizeCommand(inFile, outFile string, pageSelection []string, resize *model.Resize, conf *model.Configuration) *Command {
  1002  	if conf == nil {
  1003  		conf = model.NewDefaultConfiguration()
  1004  	}
  1005  	conf.Cmd = model.RESIZE
  1006  	return &Command{
  1007  		Mode:          model.RESIZE,
  1008  		InFile:        &inFile,
  1009  		OutFile:       &outFile,
  1010  		PageSelection: pageSelection,
  1011  		Resize:        resize,
  1012  		Conf:          conf}
  1013  }
  1014  
  1015  // PosterCommand creates a new command to cut and slice pages horizontally or vertically.
  1016  func PosterCommand(inFile, outDir, outFile string, pageSelection []string, cut *model.Cut, conf *model.Configuration) *Command {
  1017  	if conf == nil {
  1018  		conf = model.NewDefaultConfiguration()
  1019  	}
  1020  	conf.Cmd = model.POSTER
  1021  	return &Command{
  1022  		Mode:          model.POSTER,
  1023  		InFile:        &inFile,
  1024  		OutDir:        &outDir,
  1025  		OutFile:       &outFile,
  1026  		PageSelection: pageSelection,
  1027  		Cut:           cut,
  1028  		Conf:          conf}
  1029  }
  1030  
  1031  // NDownCommand creates a new command to cut and slice pages horizontally or vertically.
  1032  func NDownCommand(inFile, outDir, outFile string, pageSelection []string, n int, cut *model.Cut, conf *model.Configuration) *Command {
  1033  	if conf == nil {
  1034  		conf = model.NewDefaultConfiguration()
  1035  	}
  1036  	conf.Cmd = model.NDOWN
  1037  	return &Command{
  1038  		Mode:          model.NDOWN,
  1039  		InFile:        &inFile,
  1040  		OutDir:        &outDir,
  1041  		OutFile:       &outFile,
  1042  		PageSelection: pageSelection,
  1043  		IntVal:        n,
  1044  		Cut:           cut,
  1045  		Conf:          conf}
  1046  }
  1047  
  1048  // CutCommand creates a new command to cut and slice pages horizontally or vertically.
  1049  func CutCommand(inFile, outDir, outFile string, pageSelection []string, cut *model.Cut, conf *model.Configuration) *Command {
  1050  	if conf == nil {
  1051  		conf = model.NewDefaultConfiguration()
  1052  	}
  1053  	conf.Cmd = model.CUT
  1054  	return &Command{
  1055  		Mode:          model.CUT,
  1056  		InFile:        &inFile,
  1057  		OutDir:        &outDir,
  1058  		OutFile:       &outFile,
  1059  		PageSelection: pageSelection,
  1060  		Cut:           cut,
  1061  		Conf:          conf}
  1062  }
  1063  
  1064  // ListBookmarksCommand creates a new command to list bookmarks of inFile.
  1065  func ListBookmarksCommand(inFile string, conf *model.Configuration) *Command {
  1066  	if conf == nil {
  1067  		conf = model.NewDefaultConfiguration()
  1068  	}
  1069  	conf.Cmd = model.LISTBOOKMARKS
  1070  	return &Command{
  1071  		Mode:   model.LISTBOOKMARKS,
  1072  		InFile: &inFile,
  1073  		Conf:   conf}
  1074  }
  1075  
  1076  // ExportBookmarksCommand creates a new command to export bookmarks of inFile.
  1077  func ExportBookmarksCommand(inFile, outFileJSON string, conf *model.Configuration) *Command {
  1078  	if conf == nil {
  1079  		conf = model.NewDefaultConfiguration()
  1080  	}
  1081  	conf.Cmd = model.EXPORTBOOKMARKS
  1082  	return &Command{
  1083  		Mode:        model.EXPORTBOOKMARKS,
  1084  		InFile:      &inFile,
  1085  		OutFileJSON: &outFileJSON,
  1086  		Conf:        conf}
  1087  }
  1088  
  1089  // ImportBookmarksCommand creates a new command to import bookmarks to inFile.
  1090  func ImportBookmarksCommand(inFile, inFileJSON, outFile string, replace bool, conf *model.Configuration) *Command {
  1091  	if conf == nil {
  1092  		conf = model.NewDefaultConfiguration()
  1093  	}
  1094  	conf.Cmd = model.IMPORTBOOKMARKS
  1095  	return &Command{
  1096  		Mode:       model.IMPORTBOOKMARKS,
  1097  		BoolVal1:   replace,
  1098  		InFile:     &inFile,
  1099  		InFileJSON: &inFileJSON,
  1100  		OutFile:    &outFile,
  1101  		Conf:       conf}
  1102  }
  1103  
  1104  // RemoveBookmarksCommand creates a new command to remove all bookmarks from inFile.
  1105  func RemoveBookmarksCommand(inFile, outFile string, conf *model.Configuration) *Command {
  1106  	if conf == nil {
  1107  		conf = model.NewDefaultConfiguration()
  1108  	}
  1109  	conf.Cmd = model.REMOVEBOOKMARKS
  1110  	return &Command{
  1111  		Mode:    model.REMOVEBOOKMARKS,
  1112  		InFile:  &inFile,
  1113  		OutFile: &outFile,
  1114  		Conf:    conf}
  1115  }
  1116  
  1117  // ListPageLayoutCommand creates a new command to list the document page layout.
  1118  func ListPageLayoutCommand(inFile string, conf *model.Configuration) *Command {
  1119  	if conf == nil {
  1120  		conf = model.NewDefaultConfiguration()
  1121  	}
  1122  	conf.Cmd = model.LISTPAGELAYOUT
  1123  	return &Command{
  1124  		Mode:   model.LISTPAGELAYOUT,
  1125  		InFile: &inFile,
  1126  		Conf:   conf}
  1127  }
  1128  
  1129  // SetPageLayoutCommand creates a new command to set the document page layout.
  1130  func SetPageLayoutCommand(inFile, outFile, value string, conf *model.Configuration) *Command {
  1131  	if conf == nil {
  1132  		conf = model.NewDefaultConfiguration()
  1133  	}
  1134  	conf.Cmd = model.SETPAGELAYOUT
  1135  	return &Command{
  1136  		Mode:      model.SETPAGELAYOUT,
  1137  		InFile:    &inFile,
  1138  		OutFile:   &outFile,
  1139  		StringVal: value,
  1140  		Conf:      conf}
  1141  }
  1142  
  1143  // ResetPageLayoutCommand creates a new command to reset the document page layout.
  1144  func ResetPageLayoutCommand(inFile, outFile string, conf *model.Configuration) *Command {
  1145  	if conf == nil {
  1146  		conf = model.NewDefaultConfiguration()
  1147  	}
  1148  	conf.Cmd = model.RESETPAGELAYOUT
  1149  	return &Command{
  1150  		Mode:    model.RESETPAGELAYOUT,
  1151  		InFile:  &inFile,
  1152  		OutFile: &outFile,
  1153  		Conf:    conf}
  1154  }
  1155  
  1156  // ListPageModeCommand creates a new command to list the document page mode.
  1157  func ListPageModeCommand(inFile string, conf *model.Configuration) *Command {
  1158  	if conf == nil {
  1159  		conf = model.NewDefaultConfiguration()
  1160  	}
  1161  	conf.Cmd = model.LISTPAGEMODE
  1162  	return &Command{
  1163  		Mode:   model.LISTPAGEMODE,
  1164  		InFile: &inFile,
  1165  		Conf:   conf}
  1166  }
  1167  
  1168  // SetPageModeCommand creates a new command to set the document page mode.
  1169  func SetPageModeCommand(inFile, outFile, value string, conf *model.Configuration) *Command {
  1170  	if conf == nil {
  1171  		conf = model.NewDefaultConfiguration()
  1172  	}
  1173  	conf.Cmd = model.SETPAGEMODE
  1174  	return &Command{
  1175  		Mode:      model.SETPAGEMODE,
  1176  		InFile:    &inFile,
  1177  		OutFile:   &outFile,
  1178  		StringVal: value,
  1179  		Conf:      conf}
  1180  }
  1181  
  1182  // ResetPageModeCommand creates a new command to reset the document page mode.
  1183  func ResetPageModeCommand(inFile, outFile string, conf *model.Configuration) *Command {
  1184  	if conf == nil {
  1185  		conf = model.NewDefaultConfiguration()
  1186  	}
  1187  	conf.Cmd = model.RESETPAGEMODE
  1188  	return &Command{
  1189  		Mode:    model.RESETPAGEMODE,
  1190  		InFile:  &inFile,
  1191  		OutFile: &outFile,
  1192  		Conf:    conf}
  1193  }
  1194  
  1195  // ListViewerPreferencesCommand creates a new command to list the viewer preferences.
  1196  func ListViewerPreferencesCommand(inFile string, all, json bool, conf *model.Configuration) *Command {
  1197  
  1198  	if conf == nil {
  1199  		conf = model.NewDefaultConfiguration()
  1200  	}
  1201  	conf.Cmd = model.LISTVIEWERPREFERENCES
  1202  	return &Command{
  1203  		Mode:     model.LISTVIEWERPREFERENCES,
  1204  		InFile:   &inFile,
  1205  		BoolVal1: all,
  1206  		BoolVal2: json,
  1207  		Conf:     conf}
  1208  }
  1209  
  1210  // SetViewerPreferencesCommand creates a new command to set the viewer preferences.
  1211  func SetViewerPreferencesCommand(inFilePDF, inFileJSON, outFilePDF, stringJSON string, conf *model.Configuration) *Command {
  1212  
  1213  	if conf == nil {
  1214  		conf = model.NewDefaultConfiguration()
  1215  	}
  1216  	conf.Cmd = model.SETVIEWERPREFERENCES
  1217  	return &Command{
  1218  		Mode:       model.SETVIEWERPREFERENCES,
  1219  		InFile:     &inFilePDF,
  1220  		InFileJSON: &inFileJSON,
  1221  		OutFile:    &outFilePDF,
  1222  		StringVal:  stringJSON,
  1223  		Conf:       conf}
  1224  }
  1225  
  1226  // ResetViewerPreferencesCommand creates a new command to reset the viewer preferences.
  1227  func ResetViewerPreferencesCommand(inFile, outFile string, conf *model.Configuration) *Command {
  1228  	if conf == nil {
  1229  		conf = model.NewDefaultConfiguration()
  1230  	}
  1231  	conf.Cmd = model.RESETVIEWERPREFERENCES
  1232  	return &Command{
  1233  		Mode:    model.RESETVIEWERPREFERENCES,
  1234  		InFile:  &inFile,
  1235  		OutFile: &outFile,
  1236  		Conf:    conf}
  1237  }
  1238  
  1239  // ZoomCommand creates a new command to zoom in/out of selected pages.
  1240  func ZoomCommand(inFile, outFile string, pageSelection []string, zoom *model.Zoom, conf *model.Configuration) *Command {
  1241  	if conf == nil {
  1242  		conf = model.NewDefaultConfiguration()
  1243  	}
  1244  	conf.Cmd = model.ZOOM
  1245  	return &Command{
  1246  		Mode:          model.ZOOM,
  1247  		InFile:        &inFile,
  1248  		OutFile:       &outFile,
  1249  		PageSelection: pageSelection,
  1250  		Zoom:          zoom,
  1251  		Conf:          conf}
  1252  }
  1253  
  1254  // ListCertificatesCommand creates a new command to list installed certificates.
  1255  func ListCertificatesCommand(json bool, conf *model.Configuration) *Command {
  1256  	if conf == nil {
  1257  		conf = model.NewDefaultConfiguration()
  1258  	}
  1259  	conf.Cmd = model.LISTCERTIFICATES
  1260  	return &Command{
  1261  		Mode:     model.LISTCERTIFICATES,
  1262  		BoolVal1: json,
  1263  		Conf:     conf}
  1264  }
  1265  
  1266  // InspectCertificatesCommand creates a new command to inspect certificates.
  1267  func InspectCertificatesCommand(inFiles []string, conf *model.Configuration) *Command {
  1268  	if conf == nil {
  1269  		conf = model.NewDefaultConfiguration()
  1270  	}
  1271  	conf.Cmd = model.INSPECTCERTIFICATES
  1272  	return &Command{
  1273  		Mode:    model.INSPECTCERTIFICATES,
  1274  		InFiles: inFiles,
  1275  		Conf:    conf}
  1276  }
  1277  
  1278  // ImportCertificatesCommand creates a new command to import certificates.
  1279  func ImportCertificatesCommand(inFiles []string, conf *model.Configuration) *Command {
  1280  	if conf == nil {
  1281  		conf = model.NewDefaultConfiguration()
  1282  	}
  1283  	conf.Cmd = model.IMPORTCERTIFICATES
  1284  	return &Command{
  1285  		Mode:    model.IMPORTCERTIFICATES,
  1286  		InFiles: inFiles,
  1287  		Conf:    conf}
  1288  }
  1289  
  1290  // ValidateSignaturesCommand creates a new command to validate encountered digital signatures.
  1291  func ValidateSignaturesCommand(inFile string, all, full bool, conf *model.Configuration) *Command {
  1292  	if conf == nil {
  1293  		conf = model.NewDefaultConfiguration()
  1294  	}
  1295  	conf.Cmd = model.VALIDATESIGNATURES
  1296  	return &Command{
  1297  		Mode:     model.VALIDATESIGNATURES,
  1298  		InFile:   &inFile,
  1299  		BoolVal1: all,
  1300  		BoolVal2: full,
  1301  		Conf:     conf}
  1302  }