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

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

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,

how to use custom font in kartik 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"

How to disable HTML escaping of labels in KnpMenuBundle

I want to render an HTML label like:
$menu->addChild('Dashboard', array(
'route' => 'dashboard',
'label' => '<i class="fa-icon-bar-chart"></i><span class="hidden-tablet"> Dashboard</span></a>',
'extra' => array('safe_label' => true)
)
);
And I've pass the proper option while rendering:
{{ knp_menu_render('WshCmsHtmlBundle:Builder:mainMenu', {'allow_safe_labels': true} ) }}
But my label is still being escaped. What am I doing wrong?
Ok, the answer is!
You set up extra items on menu item not by 'extra' key but by 'extras' key.
So when you setup the item like this:
$menu->addChild('Dashboard', array(
'route' => 'dashboard',
'label' => '<i class="fa-icon-bar-chart"></i><span class="hidden-tablet"> Dashboard</span></a>',
'extras' => array('safe_label' => true)
)
);
it works fine!
There's two steps to achieve this.
1. MenuBuilder
You have to set safe_label to true in extras. Note that you can now write HTML in your label.
$menu->addChild('Home<i><b></b></i>', array(
'route' => 'homepage',
'extras' => array(
'safe_label' => true
),
));
2. Twig
You have to filter the output of knp_menu_render() so that it prints raw HTML (see documentation).
{{ knp_menu_render('main', {'allow_safe_labels': true}) | raw }}
Warning
Please be aware that this may be dangerous. From the documentation:
Use it with caution as it can create some XSS holes in your application if the label is coming from the user.
I used FyodorX's method to add a strong tag. It works like a charm but I must say that the raw filter is not necessary

Adding wp_editor to custom WP widget

I want to add WP editor with TinyMCE to my custom text widget, but it won't show TinyMCE buttons it just shows textarea. When I test my code on page.php it works perfectly - editor shows with all the buttons and metabox. Can You please tell me what I'm doing wrong?EDITWidgets screenshot.Same code used in page.php screenshot
The code I use :
$settings = array(
'wpautop' => true,
'media_buttons' => false,
'textarea_name' => 'test-editor',
'textarea_rows' => get_option('default_post_edit_rows', 10),
'tabindex' => '',
'editor_css' => '',
'editor_class' => '',
'teeny' => true,
'dfw' => true,
'tinymce' => array(
'theme_advanced_buttons1' => 'bold,italic,underline'
),
'quicktags' => false
);
wp_editor( 'Text in editor', 'test-editor', $settings );
Looks like you need to find another WYSIWYG editor. Reading the Codex, there are two issues with your code:
The $editor_id
can only be composed of lower-case letters. No underscores, no hyphens. Anything else will cause the WYSIWYG editor to malfunction.
And this one that prevents the editor from working in a meta box
Once instantiated, the WYSIWYG editor cannot be moved around in the DOM. What this means in practical terms, is that you cannot put it in meta-boxes that can be dragged and placed elsewhere on the page.

Custom styles for Wordpress TinyMCE

I've read several tutorials for adding custom styles to the WYSIWYG (TinyMCE) editor. None of them seem to work in the newest version(s) of Wordpress. I'm using v3.3.2. The instructions from the codex work, but in a limited way...
NOTE: To be 100% clear, I'm trying to add a "Styles" dropdown which the author can use to apply my custom styles to the text. (Please don't confuse my question with how to style the editor its self, using editor-style.css... )
I managed to get the code working, but only using the commented-out line in my_mce_before_init(). The problem with this version is that it adds the class with a generic <span>. I'm trying to use the more powerful version of the code (as shown below), but something isn't quite right. The styles drop-down box appears, but it's blank. If I click it the first item is says "Styles" but does nothing. I suspect there's something off about my array. Hopefully someone more knowledgeable than me can set me straight.
Here's the relevant code in my theme's functions.php...
Here's how I add the button:
// Add the Style selectbox to the second row of MCE buttons
function my_mce_buttons_2($buttons)
{
array_unshift($buttons, 'styleselect');
return $buttons;
}
add_filter('mce_buttons_2', 'my_mce_buttons_2');
Here's how I add the styles (it works when I uncomment the ):
//Define the actual styles that will be in the box
function my_mce_before_init($init_array)
{
// add classes using a ; separated values
//$init_array['theme_advanced_styles'] = "Section Head=section-head;Sub Section Head=sub-section-head";
$temp_array['theme_advanced_styles'] = array(
array(
'title' => 'Section Head',
'block' => 'h3',
'classes' => 'section-head'
),
array(
'title' => 'Sub Section Head',
'block' => 'h4',
'classes' => 'sub-section-head'
)
);
$styles_array = json_encode( $temp_array['theme_advanced_styles'] );
// THIS IS THE PROBLEM !!!! READ BELOW
$init_array['theme_advanced_styles'] = $styles_array;
return $init_array;
}
add_filter('tiny_mce_before_init', 'my_mce_before_init');
UPDATE: I figured it out (see my answer below). Before you scroll down, notice in the code above, theme_advanced_styles is the wrong key. It should be style_formats when defining the custom styles in the way that I'm doing. I suspect this is a common mistake.
It seems you're using this (awesome) tutorial: http://alisothegeek.com/2011/05/tinymce-styles-dropdown-wordpress-visual-editor/
Worked great for me so I compared your code with mine: it seems you lack a
'wrapper' => true
as a fourth parameter to each sub-array. This is needed for adding a class on a parent element of your selection (it can broaden your selection) and not creating a new element around your exact selection before adding it a class.
Thus if you select part of a paragraph or part of 2 paragraphs, it'll select the whole paragraph(s) (not so sure about the 2 paragraphs thing, please test :) but at least it won't create inline element around your exact selection).
From the documentation (above link):
wrapper [optional, default = false]
if set to true, creates a new block-level element
around any selected block-level elements
My customization:
$style_formats = array(
array(
'title' => 'Column',
'block' => 'div',
'classes' => 'col',
'wrapper' => true
),
array(
'title' => 'Some div with a class',
'block' => 'div',
'classes' => 'some_class',
'wrapper' => true
),
array(
'title' => 'Title with other CSS',
'selector' => 'h3',
'classes' => 'other_style'
),
array(
'title' => 'Read more link',
'selector' => 'a',
'classes' => 'more'
)
);
Hope it works for you
AHA!
I found the problem: the two different versions of defining the custom classes must be added to different keys in the settings array.
This version...
"Section Head=section-head;Sub Section Head=sub-section-head";
...needs to be the value of 'theme_advanced_styles'.
Whereas this version...
$style_formats = array(
array(
'title' => 'Column',
'block' => 'div',
'classes' => 'col',
'wrapper' => true
),
);
...needs to be the value of 'style_formats' in the TinyMCE settings array.
I had changed to the second style but hadn't noticed the different key for the array.
Wordpress provides a function for adding a custom stylesheet to the editor: http://codex.wordpress.org/Function_Reference/add_editor_style

Resources