phpdocx CLI command

phpdocx CLI command

Information

phpdocx Premium licenses include a phpdocx-cli script to speed up developments and assist you in the work with phpdocx by generating sample code skeletons, checking server settings, returning information and other useful tasks.

How to use

To run phpdocx-cli.php and view all available options, execute:

x
 
1
php phpdocx-cli.php
2

If no option or valid parameter are set, the help information is displayed.

For example, the following command generates a skeleton (phpdocx-sample-skeleton.php as default) to create a new DOCX adding text, image, list, header, footer and html methods:

2
 
1
php phpdocx-cli.php -a generate -m "text, image, list, header, footer, html"
2
Available options

The available options are the following:.

11
 
1
-a, --action <action>                   Action. Allowed values:
2
                                                · "check": check and view PHP settings.
3
                                                · "generate": create a skeleton.
4
    --color                             Change output colors. Allowed values: auto, none.
5
-m, --methods <method1, method2...>     Methods to be included in the output separated by commas.
6
-h, --help                              View help information.
7
-l, --license                           View phpdocx license information.
8
-o, --output                            Output file for skeletons. Default as "phpdocx-sample-skeleton.php".
9
-t, --template <template>               DOCX template.
10
    --view-methods                      Display available methods to be used when generating skeletons.
11
Skeleton methods

Supported methods in documents generated from scratch:

  • backgroundColor
  • backgroundImage
  • bibliography
  • bookmark
  • break
  • caption
  • chart
  • citation
  • comment
  • cross-reference
  • date
  • embedFont
  • endnote
  • externalFile
  • footnote
  • footer
  • formElement
  • header
  • heading
  • html
  • image
  • link
  • list
  • mathEquation
  • mergeField
  • ole
  • onlineVideo
  • pageNumber
  • properties
  • section
  • shape
  • simpleField
  • source
  • structuredDocumentTag
  • styleCharacter
  • styleList
  • styleParagraph
  • styleTable
  • svg
  • tab
  • table
  • tableAuthorities
  • tableContents
  • tableFigures
  • text
  • textBox
  • wordML

Supported methods in documents generated with a template:

  • clearBlocks
  • cloneBlock
  • deleteBlock
  • getTemplateVariables
  • modifyInputFields
  • modifyMergeFields
  • removeVariable
  • replaceBlock
  • replaceImage
  • replaceList
  • replaceTable
  • replaceText
  • setTemplateSymbol
  • tickCheckboxes

Template methods are only added to the skeleton when a DOCX template is set using "-t" parameter:

2
 
1
php phpdocx-cli.php -a generate -m "replaceImage, replaceList, replaceText" -t template.docx
2

These template methods are not added to the skeleton when creating a new DOCX without a template.

Other supported methods:

  • encrypt
  • merge
  • sign
  • stream
  • tracking
  • transform
  • watermark

To display all available methods use --view-methods:

2
 
1
php phpdocx-cli.php --view-methods
2
Examples

Generate a phpdocx skeleton using header, html, list and text methods:

2
 
1
php phpdocx-cli.php -a generate -m "header, html, list, text"
2

Generate a phpdocx skeleton using a template and replaceImage, replaceList and replaceText methods:

2
 
1
php phpdocx-cli.php -a generate -m "replaceImage, replaceList, replaceText" -t template.docx
2

Generate a phpdocx skeleton and save the sample as custom-skeleton.php:

2
 
1
php phpdocx-cli.php -a generate -m "text" -o custom-skeleton.php
2

Check server settings:

2
 
1
php phpdocx-cli.php -a check
2

View phpdocx license information:

2
 
1
php phpdocx-cli.php -l
2
­
­