how to use custom font in kartik mpdf? - mpdf

I'm using kartik mpdf extension and trying to style the pdf using "cssFile" property.
But any font I want to set (even from Web Safe Fonts or my oun font-face) don't effect the content of pdf file.
Any help?

I thank you should configure cssFile and cssInline in kartik,
For example in PDF controller you have
public function actionPdf()
{
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $contents,
'filename' => 'Filename',
'cssFile' => '#vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.css',
'cssInline' => '.modal-footer{text-align:left;}div.modal-body{padding:0px;}',
'options' => ['title' => 'Devis'],
'methods' => [
'SetFooter'=>[$footer],
]
]);
Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'application/pdf');
return $pdf->render();
}
And you should go to this file in vendor folder to do what you want in css #vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.css
And the required style (for exemple color: #fff !important) you should do that in this ligne 'cssInline' => '.modal-footer{text-align:left;}div.modal-body{padding:0px;}',

he asked how change font-family in pdf file.
Names of basic fonts are located in config_font.php.
You can add custom fonts in this file.
Example
$this->fontdata = array( ... "pompadur" => array( 'R' => "Pompadur.ttf", ), ... )
paste to your html: style="font-family: Pompadur"

Related

yii2 mpdf view displaying debug toolbar code

I'm using kartik mpdf extension to print a report. Problem is, in print view css code displaying and in footer debug toolbar code too. Please guide me how to remove that.
i'm using following code.
$content = $this->render('print', ['modelPatientTest' => $modelPatientTest]);
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE, // leaner size using standard fonts
'content' => $content,
'format' => Pdf::FORMAT_A4,
'options' => [
'title' => 'Test Report',
],
'methods' => [
'SetHeader' => [''],
'SetFooter' => ['{PAGENO}|'],
]
]);
return $pdf->render();
As Debug toolbar should be active only in a development environment, put at the top of your controller's action this code:
if(YII_DEBUG === true || YII_ENV === "dev") {
Yii::$app->getModule('debug')->instance->allowedIPs = [];
}
(Edited thanks to #Gubberrr comment below)
Just change
'mode' => Pdf::MODE_CORE,
to
'mode' => Pdf::MODE_UTF8,

wkhtmltopdf (knp snappy bundle) Wrong text selection and wrong wrapping

I am use "knplabs/knp-snappy-bundle": "dev-master" for symfony 2.7
I generate pdf by using
$this->knp_snappy_pdf->generateFromHtml( $html, $file_path, $options);
Then i open pdf in chrome and try selection text i see
this
http://i.stack.imgur.com/soKJh.jpg
But if i use http://pdfcrowd.com/ and the same html i see
normal text selection
My $options
array(
'images' => true,
'no-pdf-compression' => true,
'page-width' => '150mm',
'page-height' => '180mm',
'minimum-font-size' => '2',
'dpi' => 300,
'disable-smart-shrinking' => true,
'zoom' => '0.6',
)
I can't find answer, so I use mpdf. It is better and works right out of the box immediately

Yii: Integrating a CSS-File on the Module Level

An excerpt from my
protected/config/main.php // given situation
looks like:
'modules' => array(
'services' => array(
'modules' => array(
"myModule"
)
)
),
....
....
and for "myModule" I want to integrate a CSS-File. I could not find information about this issue in the documentation. How could I add a CSS-File on the module-level?
Something like that would be for example awesome:
'myModule' => array(
'css-file' => array(
'css-file-name' => css-file-path,
),
),
You can call CClientScript to add this file in myModule.init() method:
public function init()
{
Yii::app()->clientScript->registerCssFile($path);
}
one must change to the module directory and find the myModuleNameModule.php file and add the following (into the function init()):
$file = Yii::getPathOfAlias('myModuleName').DIRECTORY_SEPARATOR."further_directory_structure";
$url = Yii::app()->getAssetManager()->publish($file);
$cs = Yii::app()->getClientScript();
$cs->registerCssFile($url);
now the css-file is reachable from all views within this module.

How do I properly add FILE field in drupal form via theme-setting.php?

I am building a theme with ability to upload custom background images but now I am stuck at a point.
How do I properly add FILE field in drupal form via theme-setting.php and after that how can I get public url to this file in my template files??
In your theme_form_system_theme_settings_alter hook you need to add the following form element:
$form['theme_settings']['background_file'] = array(
'#type' => 'managed_file',
'#title' => t('Background'),
'#required' => FALSE,
'#upload_location' => file_default_scheme() . '://theme/backgrounds/',
'#default_value' => theme_get_setting('background_file'),
'#upload_validators' => array(
'file_validate_extensions' => array('gif png jpg jpeg'),
),
);
This will save the file id to your theme settigns variable 'background_file', notice that i set the upload location to theme/backgrounds, this will be inside your files folder.
Finally you'll get the complete URL to the file with file_create_url:
$fid = theme_get_setting('background_file');
$image_url = file_create_url(file_load($fid)->uri);
Edit:
In your template.php you can add in the theme_preprocess_page hook the variable so all the tpl's can access it, this is how:
function theme_preprocess_page(&$variables, $hook) {
$fid = theme_get_setting('background_file');
$variables['background_url'] = file_create_url(file_load($fid)->uri);
}
Hope this helps! :D

How can I add subtitles to movie using flowplayer module?

I'm using flowplayer module to play videos on my site. I would like to add sutitles to some of the movies. How can I do it in Drupal?
I tried to add them like this:
$flowplayer = array(
'clip' => array(
'url' => str_replace('sites/default/files/videos', 'http://www.mysite.com/sites/default/files/videos', $node->field_video[0]['filepath']),
'captionURL' => str_replace('sites/default/files/videos', 'http://www.mysite.com/sites/default/files/videos', $node->field_caption[0]['filepath'])
),
....
Then the output is:
<param value="config={"clip":{"url":"http://www.mysite.com/sites/default/files/videos/video.flv","captionURL":"http://www.mysite.com/sites/default/files/videos/subtitles.srt","scaling":"fit"},...
However it says no stream found. When I erase "clip", the video is found.But how can I add subtitles?
I wonder if I need some plugin or what is wrong in my code?
Thanks.
Are you going to have more than one video? You might try using the playlist param which has support for titles. I'm not sure how you would display them (i'm doing something very similar at the moment, hopefully this is helpful). I'm using the Flowplayer API module but the js syntax should be similar.
$player = theme('flowplayer',array(
'clip' => array(
'duration' => 5,
'autoPlay' => true
),
'playlist' => array(
array('url' =>'http://localhost/episode_18.mp4','title' => 'Episode 18'),
array('url' =>'http://localhost/episode_19.mp4','title' => 'Episode 19'),
array('url' =>'http://localhost/6.jpg','title' => 'Image')
),
'plugins' => array(
'controls' => array(
'playlist' => true
)
)
)
);
return $player;

Resources