As the title says I can't visualize the footer and header with knp_snappy.pdf, I have seen several examples and none has worked for me, I get the pdf but not the footer and header, I don't know is config problem or something else, this link below works but others but not in my code.
I am using symfony 3.4 , "knplabs/knp-snappy-bundle": "^1.5" and wkhtmltopdf-0.12.2.4
Examples:
https://github.com/KnpLabs/KnpSnappyBundle/issues/195
https://github.com/KnpLabs/KnpSnappyBundle/issues/154
This is my code:
config.yml
knp_snappy:
pdf:
enabled: true
binary: /usr/bin/xvfb-run /usr/bin/wkhtmltopdf
options: []
pdf/report.html.twig
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My PDF</title>
</head>
<body>
<h1>My PDF</h1>
<p>Harum trium sententiarum nulli prorsus assentior.</p>
<h1>My PDF</h1>
</body>
</html>
pdf/footer.html.twig
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Contrat Thuasne Services</title>
<script>
/* page counter */
function subst() {
var vars={};
var x=document.location.search.substring(1).split('&');
for (var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
var x=['topage','page'];
for (var i in x) {
var y = document.getElementsByClassName(x[i]);
for (var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
}
}
</script>
</head>
<body onload="subst()">
<footer>
<table>
<tr>
<td style="width: 33%;">Test</td>
<td style="width: 34%;" class="center"><span class="page"></span>/<span class="topage"></span></td>
<td style="width: 33%;" class="right">© Society {{ "now"|date("Y") }}</td>
</tr>
</table>
</footer>
</body>
</html>
controler
public function testPDFAction()
{
$snappy = $this->get('knp_snappy.pdf');
$content = $this->renderView( 'pdf/report.html.twig' );
$footer = $this->renderView( 'pdf/footer.html.twig' );
//$snappy->setOption('header-html', $header);
$snappy->setOption('footer-html', $footer);
$html = $snappy->getOutputFromHtml($content);
return new Response($html,200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="test.pdf"'
]
);
// Others test i make
/*$html = $snappy->getOutputFromHtml($content,
[
// 'images' => true,
'enable-javascript' => true,
'page-size' => 'A4',
// 'viewport-size' => '1280x1024',
'header-html' => $header,
'footer-html' => $footer,
'margin-left' => '10mm',
'margin-right' => '10mm',
'margin-top' => '30mm',
'margin-bottom' => '25mm',
]);*/
//$snappy->setOption('header-html', $header);
// $snappy->getOutputFromHtml($html);
/*$options = [
'header-html' => $header,
'footer-html' => $footer
];*/
/*return new PdfResponse(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html, $options),
'file.pdf'
);*/
/*return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html,$options),
200,
[
'Content-Type' => 'application/pdf',
'Content-Disposition' => sprintf('attachment; filename="%s"', "test"),
]
);*/
}
I don't know what is the problem, thanks in advance!!
Related
I have a "custom plugin" for scraping a website content and putting on my webiste via shortcode. After update on newset version of wordpress (and switching to HTTPS) the shortcode is not working.
I tried to switch on other theme, but not helped.
<?php
function file_get_contents_utf8($fn) {
$content = file_get_contents($fn);
$ary[] = "ISO-8859-2";
$ary[] = "UTF-8";
$ary[] = "ASCII";
return w1250_to_utf8($content);
/*return mb_convert_encoding($content, 'UTF-8',
mb_detect_encoding($content,$ary, true));*/
}
function w1250_to_utf8($text) {
// map based on:
// http://konfiguracja.c0.pl/iso02vscp1250en.html
// http://konfiguracja.c0.pl/webpl/index_en.html#examp
// http://www.htmlentities.com/html/entities/
$map = array(
chr(0x8A) => chr(0xA9),
chr(0x8C) => chr(0xA6),
chr(0x8D) => chr(0xAB),
chr(0x8E) => chr(0xAE),
chr(0x8F) => chr(0xAC),
chr(0x9C) => chr(0xB6),
chr(0x9D) => chr(0xBB),
chr(0xA1) => chr(0xB7),
chr(0xA5) => chr(0xA1),
chr(0xBC) => chr(0xA5),
chr(0x9F) => chr(0xBC),
chr(0xB9) => chr(0xB1),
chr(0x9A) => chr(0xB9),
chr(0xBE) => chr(0xB5),
chr(0x9E) => chr(0xBE),
chr(0x80) => '€',
chr(0x82) => '‚',
chr(0x84) => '„',
chr(0x85) => '…',
chr(0x86) => '†',
chr(0x87) => '‡',
chr(0x89) => '‰',
chr(0x8B) => '‹',
chr(0x91) => '‘',
chr(0x92) => '’',
chr(0x93) => '“',
chr(0x94) => '”',
chr(0x95) => '•',
chr(0x96) => '–',
chr(0x97) => '—',
chr(0x99) => '™',
chr(0x9B) => '’',
chr(0xA6) => '¦',
chr(0xA9) => '©',
chr(0xAB) => '«',
chr(0xAE) => '®',
chr(0xB1) => '±',
chr(0xB5) => 'µ',
chr(0xB6) => '¶',
chr(0xB7) => '·',
chr(0xBB) => '»',
);
if(strpos(get_permalink(),"eurojackpot") !== false)
return $text;
else
return html_entity_decode(mb_convert_encoding(strtr($text, $map), 'UTF-8', 'ISO-8859-2'), ENT_QUOTES, 'UTF-8');
}
function download_tipos( $atts ) {
$atts = shortcode_atts( array(
'url' => '',
), $atts, 'download_tipos' );
$content = file_get_contents_utf8($atts["url"]);
if($atts["url"] == "http://eurojackpot.tipos.sk/sk/eurojackpot/vysledky"){
preg_match('/(<div class="row".*?)<div id="footer"/s',$content,$vys);
}
else{
preg_match('/(<div class="bgResultsPnlTop".*?)<div class="bgResultsPnlBottom"/s',$content,$vys);
}
$ret = str_replace('<div id="M5_pnlOptional1"',$reklama.'<div id="M5_pnlOptional1"',$vys[1]).$reklama2;
$ret = str_replace('<div id="_7b7b0a087277_pnlOptional1"',$reklama.'<div id="_7b7b0a087277_pnlOptional1"',$ret);
$ret = str_replace('<p class="kenoPlusNo"',$reklama.'<p class="kenoPlusNo"',$ret);
$ret = str_replace('<div class="content col-md-6 right-col"',$reklama.'<div class="content col-md-6 right-col"',$ret);
$ret = preg_replace('#<a.*?>.*?</a>#i', '', $ret);
$ret = preg_replace('#<img.*?>#i', '', $ret);
return $ret;
}
add_shortcode( 'download_tipos', 'download_tipos' );
add_action('wp_head','hook_css');
function hook_css() {?>
<style>
.orderedNumbers span,.unorderedNumbers span,.result-number li{
border-radius: 50px;
background-color: #eee;
width: 50px;
display: inline-block;
text-align: center;
font-size: 20px;
}
</style>
<?php
}
?>
In the output page ther is this shortode:
<p>[download_tipos url="http://www.tipos.sk/Default.aspx?CatID=711"]
</p>
My expect was the table with numbers, but I dont get any output and on the output URL i dont find in the source code (download_tipos tag). Is there a way how to debug this problem?
In the theme vendor file I have:
$element = array(
'#tag' => 'meta',
'#attributes' => array(
'name' => 'viewport',
'content' => 'width=device-width, initial-scale=1.0',
),
);
drupal_add_html_head($element, 'bootstrap_responsive');
I do not want to touch that file, but I would like to override this setting somewhere else. I can of course do:
drupal_add_html_head(array(
'#tag' => 'meta',
'#attributes' => array(
'name' => 'viewport',
'content' => 'maximum-scale=1.0' // Change is here
)
), 'bootstrap_responsive_2');
That will work but would also be pretty ugly since it will create 2 meta tags in the end.
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="viewport" content="maximum-scale=1.0" />
Can I simply override the already added meta tag?
From within a custom module implement hook_html_head_alter. Read the comments on that page behind the link, you'll find some useful snippets there.
function MYMODULE_html_head_alter(&$head_elements) {
foreach ($head_elements as $key => $element) {
if (isset($element['#attributes']['name']) && $element['#attributes']['name'] == 'viewport') {
// Override 'content'.
$head_elements[$key]['#attributes']['content'] = 'maximum-scale=1.0';
}
}
}
I want to create using ObHighchartsBundle a bar chart(image below) but I couldnt do that the chart is rendered empty !! the problem is in the type of the chart bar
is that even possible using the ObHighchartsBundle
My code:
chartingController .php :
public function productionEst($date,$liste1,$liste2,$liste3)
{
$ob = new Highchart();
$dates = $date;
$production = array(
$liste1,
$liste2,
$liste3
);
$ob->chart->type('bar');
$ob->chart->renderTo('container'); // The #id of the div where to render the chart
$ob->plotOptions->bar(
array(
'dataLabels' => array(
'enabled' => true
)
)
);
$ob->title->text('Production);
$ob->xAxis->categories($dates );
$ob->xAxis->title(array('text' => "Horizontal axis title"));
$ob->yAxis->title(array('text' => "Vertical axis title"));
$ob->legend->legend(
array(
'layout' => 'vertical',
'align'=> 'right',
'verticalAlign' =>'top',
'floating'=> true,
'borderWidth' =>1,
'shadow' =>true
)
);
$ob->series($production);
return $ob;
}
index.twig :
<div id="container" style="min-width: 200px; height: 600px; margin: 0 auto"></div>
<script type="text/javascript">
{{ chart(container) }}
</script>
i have a problem with the assetic:dump command. Here is main main admin twig template: Basically all resources which are needed in the admin are stored in the CoreBundle:
Twig admin_base:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% block title -%}<title>Admin</title>{% endblock %}
{% block stylesheets %}
{% stylesheets
'#CoreBundle/Resources/public/css/bootstrap-theme.min.css'
'#CoreBundle/Resources/public/css/bootstrap.min.css'
'#CoreBundle/Resources/public/css/buttons.bootstrap.min.css'
'#CoreBundle/Resources/public/css/datatables.min.css'
'#CoreBundle/Resources/public/css/fine-uploader.min.css'
'#CoreBundle/Resources/public/css/font-awesome.min.css'
'#CoreBundle/Resources/public/css/jquery-ui.min.css'
'#CoreBundle/Resources/public/css/jquery-ui.structure.min.css'
'#CoreBundle/Resources/public/css/jquery-ui.theme.min.css'
'#CoreBundle/Resources/public/css/main.css'
'#CoreBundle/Resources/public/css/rowReorder.dataTables.min.css'
'#CoreBundle/Resources/public/css/signin.css'
%}
<link href="{{ asset(asset_url) }}" rel="stylesheet">
{% endstylesheets %}
{% endblock %}
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
{% block menu -%} {% endblock %}
{% block body -%} {% endblock %}
{% block javascripts -%}
{% javascripts
'#CoreBundle/Resources/public/js/jquery-1.11.3.min.js'
'#CoreBundle/Resources/public/js/bootstrap.min.js'
'#CoreBundle/Resources/public/js/fine-uploader.min.js'
'#CoreBundle/Resources/public/js/jquery-ui.min.js'
'#CoreBundle/Resources/public/js/datatables.min.js'
'#CoreBundle/Resources/public/js/Buttons-1.1.0/js/dataTables.buttons.min.js'
'#CoreBundle/Resources/public/js/Buttons-1.1.0/js/buttons.html5.js'
'#CoreBundle/Resources/public/js/Buttons-1.1.0/js/buttons.bootstrap.min.js'
'#CoreBundle/Resources/public/js/JSZip-2.5.0/jszip.min.js'
'#CoreBundle/Resources/public/js/RowReorder-1.1.0/js/dataTables.rowReorder.min.js'
%}
<script src="{{ asset(asset_url) }}" type="text/javascript"></script>
{% endjavascripts %}
{% endblock %}
{% block readyjs -%}
{{ tinymce_init() }}
<script type="text/javascript" >
function post_order ( ord, url)
{
$.ajax({
method: "POST",
url: url,
data: { elem: ord }
})
.done(function( msg ) {
// alert( msg );
});
}
$(document).ready(function () {
var optionsDatatables = {
dom: 'Bfrtip',
buttons: [
'copyHtml5', 'excelHtml5', 'csvHtml5'
]
}
if($('#dattab').hasClass('allow-order'))
{
//if we want more properties
// optionsDatatables.rowReorder = {
//selector: 'tr',
// update: true,
// dataSrc: '.ord-id'
// }
optionsDatatables.rowReorder = true;
}
var table = $('#dattab').DataTable(optionsDatatables);
var order;
if($('#dattab').hasClass('allow-order')) {
$('#dattab').on('draw.dt', function () {
var rows = table.rows().data();
var ord = new Array();
for (var i = 0, ien = rows.length; i < ien; i++) {
ord[i] = rows[i].DT_RowId;
}
order = ord;
$('#save_sort').fadeIn();
});
}
$('#save_sort').click(function(){
post_order(order,$('#dattab').data('url'));
$(this).fadeOut();
});
$('.datec').datepicker();
});
</script>
{% endblock %}
</body>
</html>
I install the assets and then try to dump them.
I have looked in the cache so it is trying to locate it in the same bundle but with no css folder:
<?php
// CoreBundle:Components:edit_delete.html.twig
return array (
'53dc317' =>
array (
0 =>
array (
0 => '#CoreBundle/Resources/public/css/bootstrap-theme.min.css',
1 => '#CoreBundle/Resources/public/css/bootstrap.min.css',
2 => '#CoreBundle/Resources/public/css/buttons.bootstrap.min.css',
3 => '#CoreBundle/Resources/public/css/datatables.min.css',
4 => '#CoreBundle/Resources/public/css/fine-uploader.min.css',
5 => '#CoreBundle/Resources/public/css/font-awesome.min.css',
6 => '#CoreBundle/Resources/public/css/jquery-ui.min.css',
7 => '#CoreBundle/Resources/public/css/jquery-ui.structure.min.css',
8 => '#CoreBundle/Resources/public/css/jquery-ui.theme.min.css',
9 => '#CoreBundle/Resources/public/css/main.css',
10 => '#CoreBundle/Resources/public/css/rowReorder.dataTables.min.css',
11 => '#CoreBundle/Resources/public/css/signin.css',
),
1 =>
array (
),
2 =>
array (
'output' => '_controller/css/53dc317.css',
'name' => '53dc317',
'debug' => NULL,
'combine' => NULL,
'vars' =>
array (
),
),
),
'c985255' =>
array (
0 =>
array (
0 => '#CoreBundle/Resources/public/js/jquery-1.11.3.min.js',
1 => '#CoreBundle/Resources/public/js/bootstrap.min.js',
2 => '#CoreBundle/Resources/public/js/fine-uploader.min.js',
3 => '#CoreBundle/Resources/public/js/jquery-ui.min.js',
4 => '#CoreBundle/Resources/public/js/datatables.min.js',
5 => '#CoreBundle/Resources/public/js/Buttons-1.1.0/js/dataTables.buttons.min.js',
6 => '#CoreBundle/Resources/public/js/Buttons-1.1.0/js/buttons.html5.js',
7 => '#CoreBundle/Resources/public/js/Buttons-1.1.0/js/buttons.bootstrap.min.js',
8 => '#CoreBundle/Resources/public/js/JSZip-2.5.0/jszip.min.js',
9 => '#CoreBundle/Resources/public/js/RowReorder-1.1.0/js/dataTables.rowReorder.min.js',
),
1 =>
array (
),
2 =>
array (
'output' => '_controller/js/c985255.js',
'name' => 'c985255',
'debug' => NULL,
'combine' => NULL,
'vars' =>
array (
),
),
),
'103aba8' =>
array (
0 =>
array (
0 => 'bundles/core/css/bootstrap.min.css',
1 => 'bundles/core/bootstrap-theme.min.css',
2 => 'bundles/core/datatables.min.css',
3 => 'bundles/core/fine-uploader.min.css',
4 => 'bundles/core/font-awesome.min.css',
5 => 'bundles/core/jquery-ui.css',
6 => 'bundles/core/jquery-ui.structure.min.css',
7 => 'bundles/core/jquery-ui.theme.min.css',
8 => 'bundles/core/main.css',
9 => 'bundles/core/rowReorder.dataTables.min.css',
10 => 'bundles/core/signin.css',
),
1 =>
array (
),
2 =>
array (
'output' => '_controller/css/103aba8.css',
'name' => '103aba8',
'debug' => NULL,
'combine' => NULL,
'vars' =>
array (
),
),
),
);
So it has it also in multiple files in the cache. I cannot understand what is going on..
You have another Twig template that has {% stylesheets ... %} block. And in this block you have exactly this string: bundles/core/bootstrap-theme.min.css.
Try to find it with your IDE and repair it.
I'm trying to get Knockout.js to work with Drupal. Seems like the Knockout calls inside a Drupal template file is not reading any of my Knockout calls. Has anyone gotten these two to work together?
You probably forgot all about this but I got it to work by including the js inline in the footer:
$header = array(
'type' => 'file'
);
$footer = array(
'type' => 'file',
'scope' => 'footer'
);
drupal_add_js(drupal_get_path('theme', 'MyTheme'). '/js/knockout.js', $header);
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<h2>Hello, <span data-bind="text: fullName"> </span>!</h2>
drupal_add_js('var ViewModel = function(first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
this.fullName = ko.computed(function() {
// Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName.
return this.firstName() + " " + this.lastName();
}, this);
};
ko.applyBindings(new ViewModel("Planet", "Earth")); // This makes Knockout get to work
',
array('type' => 'inline', 'scope' => 'footer', 'weight' => 1)
);
If you found a way to do it from a file let me know, this is no good having to do it this way.
Edit: nevermind, it works if you include the file at the footer:
drupal_add_js(drupal_get_path('theme', 'MyTheme'). '/js/MyKnockoutScript.js', $footer);