processTemplate
- addBibliography
- addBookmark
- addBreak
- addChart
- addCitation
- addComment
- addCrossReference
- addDateAndHour
- addEndnote
- addExternalFile
- addFootnote
- addFormElement
- addHeading
- addImage
- addLink
- addList
- addMathEquation
- addMergeField
- addOLE
- addOnlineVideo
- addPageNumber
- addShape
- addSimpleField
- addSource
- addStructuredDocumentTag
- addSVG
- addTab
- addTable
- addTableContents
- addTableFigures
- addText
- addTextBox
- addWordFragment
- addWordML
- embedHTML
- addBackgroundImage
- addFooter
- addFooterSection
- addHeader
- addHeaderSection
- addLineNumbering
- addMacroFromDoc
- addPageBorders
- addProperties
- addSection
- createDocx
- createDocxAndDownload
- createCharacterStyle
- createListStyle
- createParagraphStyle
- createTableStyle
- docxSettings
- embedFont
- importChartStyle
- importHeadersAndFooters
- importListStyle
- importStyles
- importStylesWordDefault
- modifyPageLayout
- parseStyles
- removeFooters
- removeHeaders
- setBackgroundColor
- setDecimalSymbol
- setDefaultFont
- setDocumentDefaultStyles
- setEncodeUTF8
- setLanguage
- setMarkAsFinal
- setRTL
- clearBlocks
- cloneBlock
- deleteBlock
- getTemplateVariables
- getTemplateVariablesType
- modifyInputFields
- modifyMergeFields
- processTemplate
- removeTemplateVariable
- removeTemplateVariableImage
- replaceBlock
- replaceListVariable
- replacePlaceholderImage
- replaceTableVariable
- replaceVariableByExternalFile
- replaceVariableByHtml
- replaceVariableByText
- replaceVariableByWordFragment
- replaceVariableByWordML
- setTemplateSymbol
- setTemplateBlockSymbol
- tickCheckboxes
processTemplate
Preprocesses a given Word template in order to speed up further manipulations over it.
This method allows the preprocessing of a Word template in order to improve performance in the process of replacing placeholder variables by their corresponding values.
Due to various reasons the Word interface may split internally the placeholder variables making direct substitution impossible. Even if you may see the placeholder variable correctly displayed in the Word interface the associated XML node may contain the associated text included in a very cumbersome way (with XML tags splitting the variable name in different chunks).
Although phpdocx deals by itself with that extra complications the process may require multiple manipulations, which for documents with a very large number of placeholders variables, may considerably slow down the output.
By preprocessing the Word template you make sure that all variables are already properly cleaned so the substitution may be carried out at a very fast pace.
It is convenient to run this method independently and keep the resulting document in a separate repository of processed templates.
If the placeholders use delimiter symbols that exist in other contents of the document, it is advisable to indicate the name of the variables that are going to be processed instead of automatically detect them.
variables
You may try to generate automatically this array with the getVariables method although it is highly recommended to have a look at the resulting array to make sure that it includes all the relevant variables in the expected format.
options
The keys and values of this array are:
Key | Type | Description |
---|---|---|
document | array | Array of variable names within the main document. |
headers | array | Array of variable names within the headers of the document. |
footers | array | Array of variable names within the footers of the document. |
footnotes | array | Array of variable names within the footnotes of the document. |
endnotes | array | Array of variable names within the endnotes of the document. |
comments | array | Array of variable names within the comments of the document. |
- phpdocx 10.0:
- supported singular nouns to set targets.