optimizeTemplate
- 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
- 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
optimizeTemplate
![](/img/preview/methods_check.png)
![](/img/preview/methods_X.png)
Process a DOCX to get the best performance when using the document as a template.
Description
public optimizeTemplate (string $source, string $target, array $variables = array(), string $templateSymbolStart = '$', string $templateSymbolEnd = null, bool $parseMode = false)
Parameters
source
DOCX document to be optimized.
dest
Destination path of the optimized template.
variables
Array of variables to be optimized.
templateSymbolStart
The symbol used for identifying placeholder variables within templates.
templateSymbolEnd
The symbol used for identifying placeholder variables within templates.
parseMode
If true uses the parse mode to repair and get variables. Default as false.
Exceptions
Error while trying to open the (base) template as a zip file.
Code samples
Example #1:
Release notes
- phpdocx 14.5:
- generate a new CreateDocxFromTemplate::$regExprVariableSymbols value automatically.
- phpdocx 14.0:
- return DOCXStructure.
- phpdocx 11.0:
- DOCXStructure and in-memory DOCX documents.
- return DOCXStructure.