embedFont
- addBibliography
- addBookmark
- addBreak
- addCaption
- 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
- addTableAuthorities
- 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
embedFont


Embeds a TTF font in a Word document.
Description
public embedFont (string $fontSource, string $fontName, [array $options])
Parameters
fontSource
TTF font path.
fontName
Font name.
options
The possible keys and values of this array are:
Key | Type | Description |
---|---|---|
charset | string | 00 as default. |
styleEmbedding | string | Regular (default), Bold, Italic, BoldItalic. |
Exceptions
Method not available.
Code samples
x
1
// embed a font and add new text contents applying the embedded font
2
require_once 'classes/CreateDocx.php';
3
4
$docx = new CreateDocx();
5
6
// embed a TTF font
7
$docx->embedFont('Pacifico.ttf', 'Pacifico');
8
9
// add a text content using the default font
10
$docx->addText('Text using the default font.');
11
12
// add a text content using the embedded font
13
$paragraphOptions = array(
14
'font' => 'Pacifico',
15
);
16
$docx->addText('Text using the new font.', $paragraphOptions);
17
18
// generate the DOCX
19
$docx->createDocx('output');
20
28
1
// embed two fonts and add HTML applying the embedded fonts
2
require_once 'classes/CreateDocx.php';
3
4
$docx = new CreateDocx();
5
6
// embed TTF fonts
7
$docx->embedFont('Pacifico.ttf', 'Pacifico');
8
$docx->embedFont('KOMIKRAK.ttf', 'Komika Krak');
9
10
// import HTML applying the new fonts to some contents
11
$hml = '
12
<style>
13
.nf {
14
font-family: "Pacifico";
15
}
16
.nfs {
17
font-family: "Komika Krak";
18
}
19
</style>
20
<p>Text content using the default font family when importing HTML.</p>
21
<p class="nf">Text content using Pacifico font.</p>
22
<p class="nf">My text content <span class="nfs">Komika Krak</span></p>
23
';
24
25
$docx->embedHTML($hml);
26
27
$docx->createDocx('output');
28
Release notes
- phpdocx 13.0:
- updated the internal algorithm.
- phpdocx 11.0:
- prevent adding duplicated fonts.
- fixed misspelled styleEmbedding option.
- phpdocx 10.0:
- new method.