Add malayalam font in mPDF in Laravel application - laravel

I am using mPDF in my Laravel application. My pdf file comes with both English and Malayalam languages. But Malayalam content not loading properly. I tried to add new font, but it's always showing missing OTL table error. Here is my code.
config/pdf.php
return [
'mode' => 'utf-8',
'format' => 'A4',
'author' => '',
'subject' => '',
'keywords' => '',
'creator' => 'Laravel Pdf',
'display_mode' => 'fullpage',
//'tempDir' => base_path('../temp/'),
'tempDir' => __DIR__.'/../temp/',
//'tempDir' => __DIR__.'/../storage/framework/pdf/',
'pdf_a' => false,
'pdf_a_auto' => false,
'icc_profile_path' => '',
'font_path' => base_path('resources/fonts/'),
'font_data' => [
'malayalam' => [
'R' => 'ECBThinkal.ttf', // regular font
'B' => 'ECBThinkal.ttf', // optional: bold font
'I' => 'ECBThinkal.ttf', // optional: italic font
'BI' => 'ECBThinkal.ttf', // optional: bold-italic font
'useOTL' => 0xFF,
'useKashida' => 75,
]
]
];
view.blade.php
<html>
<?php header('Content-Type: text/html; charset=utf-8');?>
<head>
<style>
body {
font-family: 'malayalam', sans-serif;
}
</style>
I am not pasting full code. When I try to create pdf it returns error Unable to set font "D:\xampp\htdocs\xxxxx\resources/fonts//ECBThinkal.ttf" to use OTL as it does not include OTL tables (or at least not a GDEF table).
Tried some other fonts also, but still this error is showing.

I guess this is what you are missing in your config.
'autoLangToFont' => true,
Reference: https://mpdf.github.io/fonts-languages/automatic-font-selection.html

Related

Highcarts in Laravel

I'm trying to render a chart in a Laravel view, i built the chart in the controller but it doesn't work unless i disable the js/app.js, can someone tell me why?
Controller:
$chart1 = \Chart::title([
'text' => 'Voting',
])
->chart([
'type' => 'line', // pie , columnt ect
'renderTo' => 'chart1', // render the chart into your div with id
])
->subtitle([
'text' => 'This Subtitle',
])
->colors([
'#0c2959'
])
->xaxis([
'categories' => [
'data 1',
'data 2',
'data 3',
'data 4',
],
'labels' => [
'rotation' => 15,
'align' => 'top',
'formatter' => 'startJs:function(){return this.value + " (Player)"}:endJs',
// use 'startJs:yourjavasscripthere:endJs'
],
])
->yaxis([
'text' => 'This Y Axis',
])
->legend([
'layout' => 'vertikal',
'align' => 'right',
'verticalAlign' => 'middle',
])
->series(
[
[
'name' => 'Voting',
'data' => [43934, 52503, 57177, 69658],
// 'color' => '#0c2959',
],
]
)
->display();
return view('devices.show', compact('readings', 'chart1'));
Laravel View:
<div id="chart1"></div>
</div>
</div>
</div>
{!! $chart1 !!}
</body>
</html>
The {!! $chart1 !!} is outside of the id=app div
The problem was that i installed Laravel with VUE.js, and VUE was creating the div <div id="app">, and you can't run any JavaScript inside that DIV, i disabled VUE.js and the chart worked

Is there any way to display only info on update screen?

Here is my update / edit screen on customers area Backpack's admin panel.
ID's field type like text but it just disabled and readonly.
But when i try to save changes, it doesn't work. I think its my primary column and can't changable.
$fields =
[
[ 'name' => 'id', 'label' => 'ID', 'type' => 'text', 'hint' => __('dashboard.crud_listing.customers.hint_of_id'), 'attributes' => ['disabled' => 'disabled', 'readonly' => 'readonly'], 'fake' => true],
];
$this->crud->addFields($fields);
Can anyone have any idea about displaying some data, without saving on this ?
why you setting 'readonly' => 'readonly' inside the 'attributes':
like in doc:
you should set as like:
[ // Text
'name' => 'id',
'label' => "ID",
'type' => 'text',
'readonly' => 'readonly',
],

How to increase text area size of summnote field in laravel backpack

I am using laravel backpack as a crud and i'm creating a laravel admin panel with it. I need to use the summernote wysiwyg field and there is a options field attribute with laravel backpack and I am trying to input the minheight option for summer note however it does not add it to the intiatlaztion properly
$this->crud->addField([
'name' => 'desc',
'type' => 'summernote',
'label' => "feature description",
'options' => [
'minheight: 300'
]
]);
as you can see it does not increase the mineheight does anyone have any ideas?
i have a work around but it requires me to edit vendor files which it not something i want to have to deal with.
Place this script below your page to modify size and other characteristics of summernote editor:
<script type="text/javascript">
$(document).ready(function() {
$('#summernote').summernote({
height: 250,
disableResizeEditor: true // This is optional if you want to remove resize
});
});
</script>
Place your rows and cols size in the attributes array !
$this->crud->addField([
'name' => 'desc',
'type' => 'textarea',
'label' => "feature description",
'attributes' => [
'rows' => 20,
'cols' => 20
]
]);
You wrote your options property wrong.
'options' => [
'minheight: 300'
]
While actually it should be:
'options' => [
'minheight' => 300
]
See the difference?
You can use summernote API like this:
$this->crud->addField([
'name' => 'desc',
'type' => 'summernote',
'label' => "feature description",
'options' => [
'minheight' => 300,
'height' => 400
]
]);
$this->crud->addField([
// Summernote
'name' => 'description',
'label' => 'Описание',
'type' => 'summernote',
'options' => [
'placeholder'=> 'Содержание статьи',
'height'=> 500,
'toolbar'=>[
['style', ['style']],
['font', ['bold']], // show only bold button
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['table', ['table']],
['insert', ['link', 'picture', 'video']],
['view', ['fullscreen', 'codeview', 'help']]
],
]
]);

Create Magento Backend Field ReadOnly

I would like to create a read-only field in the backend at the client's Magento.
create fields to know (through a module) is as follows:
$installer->addAttribute("customer", "attrcode", array(
"type" => "varchar",
"backend" => "",
"label" => "label",
"input" => "text",
"source" => "",
"visible" => true,
"required" => false,
"default" => "",
"frontend" => "",
"unique" => false,
));
this way it creates the field, but he's not just reading ...
Thank You
One possible solution is to use javascript to disable the button on page load
Create a js file and upload it to your admin skin/js directory (disable_button.js)
add
document.observe('dom:loaded', function(){
$("target_input_id").disabled=true;
});
Then add or update you local.xml to include the js files
<?xml version="1.0"?>
<layout version="0.1.0">
<adminhtml_customer_edit>
<reference name="head">
<action method="addItem"><type>skin_js</type><script>js/disable_button.js</script></action>
</reference>
</adminhtml_customer_edit>
</layout>
I don't think what you are trying to is possible using addAttribute(), _prepareValues($attr) method only allow specific values that are store in $data.
Take a look # app/code/core/Mage/Eav/Model/Entity/Setup.php
public function addAttribute($entityTypeId, $code, array $attr)
{
$entityTypeId = $this->getEntityTypeId($entityTypeId);
$data = array_merge(
array(
'entity_type_id' => $entityTypeId,
'attribute_code' => $code
),
$this->_prepareValues($attr);
);
.....
if ($attributeId) {
$this->updateAttribute($entityTypeId, $attributeId, $data, null, $sortOrder);
} else {
$this->_insertAttribute($data);
}
.......
}
protected function _prepareValues($attr)
{
$data = array(
'backend_model' => $this->_getValue($attr, 'backend'),
'backend_type' => $this->_getValue($attr, 'type', 'varchar'),
'backend_table' => $this->_getValue($attr, 'table'),
'frontend_model' => $this->_getValue($attr, 'frontend'),
'frontend_input' => $this->_getValue($attr, 'input', 'text'),
'frontend_label' => $this->_getValue($attr, 'label'),
'frontend_class' => $this->_getValue($attr, 'frontend_class'),
'source_model' => $this->_getValue($attr, 'source'),
'is_required' => $this->_getValue($attr, 'required', 1),
'is_user_defined' => $this->_getValue($attr, 'user_defined', 0),
'default_value' => $this->_getValue($attr, 'default'),
'is_unique' => $this->_getValue($attr, 'unique', 0),
'note' => $this->_getValue($attr, 'note'),
'is_global' => $this->_getValue($attr, 'global',
Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
),
);
return $data;
}
I have developed exactly such extension that work for products, categories and CMS pages. You just have to define some rules and choose which attributes you want to show as read-only.
Extension URL: https://www.bubbleshop.net/magento-admin-readonly.html

Using Magento 1.4's WYSIWYG editor on custom admin pages

Anyone know how to get the new 1.4 WYSIWYG editor (TinyMCE) working with custom admin pages?
I have some modules I made that have input fields in the admin->system->config section, and I’d like to get the new editor to show on the textareas there, but I can't find where they are defined.
To load the TINY MCE on a specific page, use the following function on the Adminhtml Edit block of your module:
protected function _prepareLayout() {
parent::_prepareLayout();
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}
}
To enable the editor for a certain editable textfield, just use 'wysiwyg' => true, instead of 'wysiwyg' => false. i.e.:
$fieldset->addField('description', 'editor', array(
'name' => 'description',
'label' => Mage::helper('sevents')->__('Description'),
'title' => Mage::helper('sevents')->__('Description'),
'style' => 'height:12em;width:500px;',
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
'wysiwyg' => true,
'required' => true,
));
Here are a few simple steps that will help you make TinyMCE work with Magento CMS pages.
Step 1. Download and unpack TinyMCE to root /js folder. Two things to keep in mind here. Download regular version (not jQuery version) of TinyMCE. This is due to the fact that Magento uses Prototype, so we need to avoid conflicts. Second, watch out for unpack location. Your tiny_mce.js file should be accessible on js/tiny_mce/tiny_mce.js path.
Step 2. Open the app/code/core/Mage/Adminhtml/Block/Cms/Page/Edit/Tab/Main.php file. Locate the
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('cms')->__('Content'),
'title' => Mage::helper('cms')->__('Content'),
'style' => 'height:36em;',
'wysiwyg' => false,
'required' => true,
));
and change it to
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('cms')->__('Content'),
'title' => Mage::helper('cms')->__('Content'),
'style' => 'height:36em;',
'wysiwyg' => true,
'theme' => 'advanced',
'required' => true,
));
As you can see, here we changed on existing attribute ("wysiwyg") value and added new attribute "theme".
Step 3. Open the /lib/Varien/Data/Form/Element/Editor.php file and locate the method getElementHtml(). Here we change
$html = '
<textarea name="'.$this->getName().'" title="'.$this->getTitle().'" id="'.$this->getHtmlId().'" class="textarea '.$this->getClass().'" '.$this->serialize($this->getHtmlAttributes()).' >'.$this->getEscapedValue().'</textarea>
<script type="text/javascript">
// <![CDATA[
/* tinyMCE.init({
mode : "exact",
theme : "'.$this->getTheme().'",
elements : "' . $element . '",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_path_location : "bottom",
extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
theme_advanced_resize_horizontal : "false",
theme_advanced_resizing : "false",
apply_source_formatting : "true",
convert_urls : "false",
force_br_newlines : "true",
doctype : \'< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\'
});*/
//]]>
</script>';
to
$html = '
<textarea name="'.$this->getName().'" title="'.$this->getTitle().'" id="'.$this->getHtmlId().'" class="textarea '.$this->getClass().'" '.$this->serialize($this->getHtmlAttributes()).' >'.$this->getEscapedValue().'</textarea>
<script language="javascript" type="text/javascript" src="/js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
//< ![CDATA[
Event.observe(window, "load", function() {
tinyMCE.init({
mode : "exact",
theme : "'.$this->getTheme().'",
elements : "' . $element . '",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_path_location : "bottom",
extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
theme_advanced_resize_horizontal : "false",
theme_advanced_resizing : "false",
apply_source_formatting : "true",
convert_urls : "false",
force_br_newlines : "true",
doctype : \'< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\'
});
});
//]]>
</script>';
As you can see, there were only three minor changes needed (download, modify, modify) to get the TinyMCE editor working.
Hope this helps. Cheers.
© Branko Ajzele (source)
in EW_Press_Block_Adminhtml_Press_Edit
(EW/Press/Block/Adminhtml/Press/Edit.php)
paste this function
protected function _prepareLayout()
{
parent::_prepareLayout();
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled())
{
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
}
}
and than in the form.php (EW_Press_Block_Adminhtml_Press_Edit_Tab_Form)
/(EW/Press/Block/Adminhtml/Press/Edit/Tab/Form.php)/
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
add it so it will look like below:
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('module')->__('Site Description'),
'title' => Mage::helper('module')->__('Site Description'),
'style' => 'width:400px; height:300px;',
'required' => true,
'config' => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
'wysiwyg' => true
));
now reload the page to see the effect.
Here are the steps that I followed.
Preparing editor used in edit form
app/code/local/Mynamespace/Mymodule/Block/Adminhtml/Mymodule/Edit.php
protected function _prepareLayout()
{
// added this code
if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
$this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
}
parent::_prepareLayout();
}
Transforming textarea to editor
app/code/local/Mynamespace/Mymodule/Block/Adminhtml/Mymodule/Edit/Tab/Form.php
Include the content within ‘_prepareForm()‘ function
$config = Mage::getSingleton('cms/wysiwyg_config')->getConfig(
array(
'add_widgets' => false,
'add_variables' => false,
'add_images' => false,
'files_browser_window_url'=> $this->getBaseUrl().'admin/cms_wysiwyg_images/index/',
));
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('mymodule')->__('Content'),
'title' => Mage::helper('mymodule')->__(’Content'),
'style’ => 'width:700px; height:320px;',
'wysiwyg' => true,
'required' => true,
'config' => $config,
));
Based on the above post i have written an article entitled:
How to use WYSIWYG editor (TinyMCE) in custom Admin Magento Module
Hope this helps.

Resources