How to use Font Awesome with MPDF? - zend-framework

I am using Zend Framework and creating PDF with mpdf.
I am trying to use fontawesome for denoting some of the articles but the fonts of font awesome are not rendering properly
below is the code .
$stylesheet = file_get_contents("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css");
$stylesheet .= file_get_contents("https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css");
$this->mpdf->WriteHTML($stylesheet,1);
$this->mpdf->WriteHTML($html,2);
$this->mpdf->allow_charset_conversion = true;
$this->mpdf->charset_in = 'windows-1252';
$this->mpdf->Output();
The code I am using in the html
<span class="company-name"> name of the company</span>
Thanks in advance.

EDIT: Nowadays, this is an obsolete method, and should only be used on legacy systems.
I recommend the answer below, from #Arie, to modify the mPDF font in its recent versions and/or if it was installed by Composer, passing the parameters when instantiating the class.
The easy way:
Copy fontawesome-webfont.ttf file into /mPDF/ttfonts/ directory.
Edit /mPDF/config_fonts.php, search the array started by $this->fontdata and add to it:
"fontawesome" => array(
'R' => "fontawesome-webfont.ttf",
),
Change your document CSS properly, with your new font family. Eg.:
$stylesheet = '.company-name { font-family: fontawesome; }';
When you instantiate the class, let the first parameter in blank:
Eg.:
$mpdf = new mPDF();
or
$mpdf = new mPDF('', 'A4');
I am tested with mPDF 6.0 and it worked.
Also, the mPDF manual explain how to do it with more options:
Fonts in mPDF 6.x

A more recent solution for Font Awesome 5.x and mPDF 7.x, when you don't want to edit the source files/dirs from mPDF: https://mpdf.github.io/fonts-languages/fonts-in-mpdf-7-x.html
My use case, this offers usage of mPDF supplied fonts, fontawesome and another custom font (ibmplex in this case). Note that when supplying a font name such as 'ibmplex' and 'fontawesome', they are lowercase. To avoid confusion why a font doesn't work, I'd advice using lower case and no spaces for the names.
$defaultConfig = (new Mpdf\Config\ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];
$defaultFontConfig = (new Mpdf\Config\FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new \Mpdf\Mpdf([
'fontDir' => array_merge($fontDirs, [
__DIR__ . '/../../resources/fonts',
]),
'fontdata' => $fontData + [
'ibmplex' => [
'R' => 'IBMPlexSans-Regular.ttf',
'B' => 'IBMPlexSans-Bold.ttf',
'I' => 'IBMPlexSans-Italic.ttf',
],
'fontawesome' => [
'R' => 'fa-solid-900.ttf'
],
],
'default_font' => 'ibmplex',
'format' => 'A4'
]);
Then you can use
<span style="font-family: fontawesome;"></span>
As per https://fontawesome.com/cheatsheet -- note that f3ed is the actual icon in this case.

Actually, if you have installed mPdf with composer, add the following lines into file located in vendor\mpdf\mpdf\src\Config\FontVariables.php
"fontawesome" => [
'R' => "fontawesome-webfont.ttf",
],
inside the 'fontdata' section

Related

TCA Icon overlay in typo3 backend

I’m working on an extension where I synchronise some data to another database and I wanted to show this in the backend using a TCA icon overlay. Sadly I could not find out how to do this. I thought about using ‘ctrl’=>‘typeicon_classes’ (using the state field of my table to choose an icon), this works for the default (non synchronised element) but I cannot figure out how to set an overlay. Any idea on how to do this?
My TCA configuration looks like this:
'ctrl' => [
...
'typeicon_column' => 'state',
'typeicon_classes' => [
'new' => 'mimetypes-x-content-login',
'synced' => 'mimetypes-x-content-login-overlay-approved',
]
],
The "synced" part does not work as expected. What I would expect is to either add the overlay at the end of the icon or by adding it with a whitespace but both did not work.
Any help is appreciated.
PS: I really just need this in the TYPO3 backend, the obvious solution for frontend is to use fluid or PHP but I don't think this suits the TYPO3 Backend list.
You need to register your icon files.
Given your icon files are named content_login.svg and content_login_overlay_approved.svg located in directory /Resources/Public/Icons/ you can register these in ext_localconf.php as following:
if (TYPO3_MODE === 'BE') {
$icons = [
'mimetypes-x-content-login' => 'content_login.svg',
'mimetypes-x-content-login-overlay-approved' => 'content_login_overlay_approved.svg',
];
$iconRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class);
foreach ($icons as $identifier => $path) {
$iconRegistry->registerIcon(
$identifier,
\TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider::class,
['source' => 'EXT:YOUREXTENSIONNANME/Resources/Public/Icons/' . $path]
);
}
}
Adapt yourextensionname

How to use TYPO3 Link wizard in extension

In an extension, I would like to be able to modify an existing link. The corresponding field in the database is one which may contain several links (e.g. tt_content.bodytext).
I want to reuse as much already existing functionality as possible. So I would like to use the already existing link wizard.
What I did find was the existing route rteckeditor_wizard_browse_links which uses rte_ckeditor/Classes/Controller/BrowseLinksController.php.
I use this in my view helper:
$parameters = [
'table' => $table,
'fieldName' => $field,
'pid' => $pid,
'uid' => $uid,
'recordType' => $recordType;
];
$urlParameters = [
'contentsLanguage' => 'en',
// 'route'
// 'token*
'P' => $parameters,
'curUrl' => [
'url' => $url
// todo: add anchor text etc. ...
],
'editorId' => 'cke_1'
];
$route = 'rteckeditor_wizard_browse_links';
return (string)$uriBuilder->buildUriFromRoute($route, $urlParameters);
This does opens the link wizard correctly. But it is intertwined with the ckeditor.
When I press "Set link" nothing happens and I get the following JavaScript error (visible if Console is open in Browser):
RteLinkBrowser.js?bust=8d6016d70f0f490d5e7d24262f0ec96230f399d9:77 Uncaught TypeError: Cannot read property 'document' of null
at Object.LinkBrowser.finalizeFunction (RteLinkBrowser.js?bust=8d6016d70f0f490d5e7d24262f0ec96230f399d9:77)
at HTMLFormElement.UrlLinkHandler.link (UrlLinkHandler.js?bust=8d6016d70f0f490d5e7d24262f0ec96230f399d9:40)
at HTMLFormElement.dispatch (jquery.min-16985e7a97b69d2a9c29e484ac3b581a.js:2)
at HTMLFormElement.y.handle (jquery.min-16985e7a97b69d2a9c29e484ac3b581a.js:2)
LinkBrowser.finalizeFunction # RteLinkBrowser.js?bust=8d6016d70f0f490d5e7d24262f0ec96230f399d9:77
UrlLinkHandler.link # UrlLinkHandler.js?bust=8d6016d70f0f490d5e7d24262f0ec96230f399d9:40
dispatch # jquery.min-16985e7a97b69d2a9c29e484ac3b581a.js:2
y.handle # jquery.min-16985e7a97b69d2a9c29e484ac3b581a.js:2
The corresponding line in RteLinkBrowser.js is:
var linkElement = RteLinkBrowser.CKEditor.document.createElement('a');
The Link Wizard expects the ckeditor window to be open and uses things in the DOM that are not there.
Is there some way to directly open the link wizard for a specific link within a text field?
Or alternatively open the text field with ckeditor and have the specific link preselected.
I don't have an answer, but at least here is a work-around / alternative:
Don't open Link wizard directly, open field in editor
As an alternative, consider not using the link wizard but using the route 'record_edit' to open the edit dialog for a specific RTE field. If you double-click on a link in that, the link wizard will open.
The following example was taken from linkvalidator in the core and modified. It opens an editor dialog for the field tt_content.bodytext for the record with uid $uid.
$requestUri = GeneralUtility::getIndpEnv('REQUEST_URI') .
'&id=' . $pageid;
$uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
$url = (string)$uriBuilder->buildUriFromRoute('record_edit', [
'edit' => [
'tt_content' => [
$uid => 'edit'
]
],
'columnsOnly' => 'bodytext',
'returnUrl' => $requestUri
]);
Update: For TYPO3 9, a ViewHelper exists for opening the field with FormEngine in the Backend. This has the same result.
https://docs.typo3.org/other/typo3/view-helper-reference/9.5/en-us/typo3/backend/latest/Link/EditRecord.html

Mask and issues

Regarding the mask, in backend mask have default configurations such as below:
general.json => typo3conf/mask.json
frontend.content => fileadmin/templates/content/
frontend.layouts => fileadmin/templates/content/Layouts/
frontend.partials => fileadmin/templates/content/Partials/
backend.backend => fileadmin/templates/backend/
backend.layouts_backend => fileadmin/templates/backend/Layouts/
backend.partials_backend => fileadmin/templates/backend/Partials/
backend.preview => fileadmin/templates/preview/
While installing our theme extension, we need to change the above mask configuration option values like below:
general.json => typo3conf/ext/<extension_key>/mask.json
frontend.content => fileadmin/<extension_key>/templates/content/
frontend.layouts => fileadmin/<extension_key>/templates/content/Layouts/
frontend.partials => fileadmin/<extension_key>/templates/content/Partials/
backend.backend => fileadmin/<extension_key>/templates/backend/
backend.layouts_backend => fileadmin/<extension_key>/templates/backend/Layouts/
backend.partials_backend => fileadmin/<extension_key>/templates/backend/Partials/
backend.preview => fileadmin/<extension_key>/templates/preview/
We tried like below, but its not working:
plugin.tx_mask.general.json = EXT:user_ss4u/mask.json
module.tx_mask.general.json = EXT:user_ss4u/mask.json
It seems like you try to override the settings via typoscript, which is -
as far as i know - not possible.
The settings you want to change are saved in typo3conf/LocalConfiguration.php
in ['EXT']['extConf']['mask'] so there are two (okay, one with two ways) possibilities to change them:
1.1 via Extension Manager
Open the module "Extension" in the TYPO3 Backend and search for the mask Extension.
Click on the configure icon at the end of the row.
Now you should be able to change the settings.
Changes are stored in typo3conf/LocalConfiguration.php
1.2 via Mask itself
Open the module "Mask" in the TYPO3 Backend.
Click on the configure icon to change to the Configuration Tab.
Now you should be able to change the settings.
Changes are stored in typo3conf/LocalConfiguration.php
2. via PHP
You can add the following snippet to a file like the ext_localconf.php in typo3conf/ext/<extension_key> or in typo3conf/AdditionalConfiguration.php
$GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['mask'] = serialize([
'json' => 'typo3conf/ext/<extension_key>/mask.json',
'content' => 'fileadmin/<extension_key>/templates/content/',
'layouts' => 'fileadmin/<extension_key>/templates/content/Layouts/',
'partials' => 'fileadmin/<extension_key>/templates/content/Partials/',
'backend' => 'fileadmin/<extension_key>/templates/backend/',
'layouts_backend' => 'fileadmin/<extension_key>/templates/backend/Layouts/',
'partials_backend' => 'fileadmin/<extension_key>/templates/backend/Partials/',
'preview' => 'fileadmin/<extension_key>/templates/preview/',
]);

Adding new checkbox field to tx_news_domain_model_media

I am trying to add a new checkbox field 'showinhome' to the table 'tx_news_domain_model_media' same to the field 'showinpreview' here is my TCA Configuration in Configuration/TCA/Overrides/tx_news_domain_model_media.php
$temporaryColumns = [
'showinhome' => [
'exclude' => 1,
'label' => 'Show in Home',
'config' => [
'type' => 'check',
'default' => 0,
],
],
];
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tx_news_domain_model_media',
$temporaryColumns
);
$GLOBALS['TCA']['tx_news_domain_model_media']['ctrl']['label_alt'] .= ', showinhome';
$GLOBALS['TCA']['tx_news_domain_model_media']['interface']['showRecordFieldList'] .= ', showinhome';
$GLOBALS['TCA']['tx_news_domain_model_media']['palettes']['newsPalette']['showitem'] .= 'showinhome,';
The field is not displayed, can someone help me please?
You have mixed up some stuff here.
First: tx_news can use either the own media model or the native FAL relations. I personally always use the native FAL relation.
If you want to add this field to the media table, then there is no newsPalette there. You can use the below code to add the new field:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tx_news_domain_model_media', $temporaryColumns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tx_news_domain_model_media', implode(',', array_keys($temporaryColumns)));
If you using the normal FAL relation then the showinpreview field is added to the sys_file_reference table's TCA configuration and not to the tx_news_domain_model_media table.
If you want to add this field to the file, then you need to add it to the sys_file_reference field the same way tx_news does it (I guess that you already copied the code from it's override file)
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file_reference', $temporaryColumns);
// add special news palette
$GLOBALS['TCA']['sys_file_reference']['palettes']['newsPalette']['showitem'] .= ', showinhome';
Last but not least: you have to specify tx_news as a dependency in your extension, otherwise TYPO3 does not know that your extension has to be loaded after tx_news. If you change the dependency after you installed your extension you probably need to uninstall and install it again in the extension manager.

Customizing SugarCRM 6.5 theme

I am new to SugarCRM 6.5 CE.
I have been trying to make custom theme by copying the already available themes and changing the name of folder.
The theme is now available in the drop down but any changes I am making to its CSS is not taking place.
Thanks in advance.
Here is my themedef file
$themedef = array(
'name' => "Test",
'description' => "Default theme from Sugar 5",
'version' => array(
'regex_matches' => array('6\.*.*'),
),
'group_tabs' => true,
'parentTheme' => "Test",
);
You have to set the parent theme like this:
'parentTheme' => "Sugar5", // this is the standard theme you want to overwrite.