I have a problem. How to add a new page from HTML to PDF?
Immediately I will say that I do not know why, but solutions such as:
<pagebreak />
or
h1 {page-break-before: always}
not working.
My PHP Code:
$pdf = new Pdf([
'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_FILE,
'filename' => $path,
'content' => $content,
'cssInline' => '.font_next{font-family:DoodlePen}table{border-collapse:collapse;width:100%}td{border:1px solid #000}',
]);
return $pdf->render();
Does anyone have this experience and can help you?
From the docs, looks like you can either use HTML like:
<pagebreak />
or
<tocpagebreak />
Or PHP:
$mpdf->AddPage();
$mpdf->TOCpagebreak();
But you already said you tried the html and din't work. Maybe you have a parent element with float?
OK, it works.
I use this method: https://davidwalsh.name/css-page-breaks
In HTML:
<div className="page-break"></div>
In PHP:
$pdf = new Pdf([
'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_FILE,
'filename' => $path,
'content' => $content,
'cssInline' => '
#media all{
.font_next{font-family:DoodlePen}table{border-collapse:collapse;width:100%}td{border:1px solid #000}.page-break {display: none;}
}
#media print{
.page-break{display: block;page-break-before: always;}
}
',
]);
return $pdf->render();
Related
1) I have my Yii2 in subfilder, so all my link starts from Yii/, like http:/localhost/Yii/settings/usertype-activitytype/type/3
2) request component config
'request' => [
'cookieValidationKey' => 'somecookiekey',
'baseUrl' => '/Yii',
],
3) Trying to build Menu, current route is http:/localhost/Yii/settings/usertype-activitytype/type/1 the 1 is id in route, and I should specify current route as Yii::$app->request->pathInfo for Nav widget
Attempt 1 - no bracets as string NOT FIND ACTIVE ELEMENT
Nav::widget([
'items' => array_map(function($userType) {
return [
'label' => $userType->name,
'url' => Url::current(['id' => $userType->id]),
];
}, $userTypes),
'route' => Yii::$app->request->pathInfo,
'options' => ['class' =>'nav-pills'],
]);
Attempt 2 - use bracets as route NOT FIND ACTIVE ELEMENT
Nav::widget([
'items' => array_map(function($userType) {
return [
'label' => $userType->name,
'url' => [Url::current(['id' => $userType->id])]
];
}, $userTypes),
'route' => Yii::$app->request->pathInfo,
'options' => ['class' =>'nav-pills'],
]);
Attempt 3 - remove baseUrl from generated route FIND ACTIVE ELEMENT !!!
Nav::widget([
'items' => array_map(function($userType) {
return [
'label' => $userType->name,
'url' => [str_replace('Yii/', '', Url::current(['id' => $userType->id]))]
];
}, $userTypes),
'route' => Yii::$app->request->pathInfo,
'options' => ['class' =>'nav-pills'],
]);
So you should notice I have to use dirty hack to force Nav work with generated Url, it seems very unconvient.
The question is - is there are ways to force NAV widget to recognize current active item ?
If you want buil an url based on your param you should use Url::to()as
'url' => Url::to(your-controller/your-view', ['id' => $userType->id]),
so accessing the view type for controller usertype-activitytype
'url' => Url::to('usertype-activitytype/type', ['id' => $userType->id]),
current Creates a URL by using the current route and the GET parameters.
and remember that
By Design UrlManager always prepends base URL to the generated URLs.
By default base URL is determined based on the location of entry
script. If you want to customize this, you should configure the
baseUrl property of UrlManager.
Looking to your comment the url is correcly formed .. then if you need http:/localhost/Yii instead of Yii then you can:
don't set so the localhost ... url is atomatically created
OR add the proper base url configureation as http:/localhost/Yii/ in config /main and remember that you can use main.php and main-local.php for manage different congiguration
I'm making a customization in a PrestaShop 1.6.0.14 where I need to offer an HTML editor when the employee answers to a customer thread. This part I achieved and the I'm getting to send the HTML in the e-mail message.
My problem is to show in the history, I need to show the HTML in the history (sometimes employees send links etc..). To achieve that I need to be able to save HTML in the message field of the customer_message table. When I go to the definition of the ObjectModel (classes/CustomerMessage.php) I see this:
'message' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 65000),
Which is cleaning the HMTL. So I created a new file at override/classes/CustomerMessage.php with this content:
class CustomerMessage extends CustomerMessageCore
{
public function __construct($id = null) {
self::$definition['fields']['message'] = array('type' => self::TYPE_STRING, 'validate' => 'isAnything', 'required' => true, 'size' => 65000);
parent::__construct($id);
}
}
This I believe that would override the property allowing me to save HTML in this field. But it doesn't work. Am I doing it the wrong way? If so, how can I redefine this field?
Thanks for any help
you have to use this settings:
self::$definition['fields']['message'] = array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 65000);
the type should be TYPE_HTML, and don't change validation isCleanHtml because it check about parts of html code that you don't want (like js, script, iframe, etc)
Let me know :)
PS: Every time that we make an override, delete the class_index.php that is stored in cache folder
I have a gird, that works normally while I'm working locally, but when I deploy the code on a server I cannot edit anymore the grid.
#(Html.Kendo().Grid<BussinessUnitDto>()
.Name("FunctionsGrid")
.AutoBind(true)
.Scrollable()
.ToolBar(toolBar =>
{
toolBar.Create();
toolBar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell).DisplayDeleteConfirmation(false))
.DataSource(ds=>ds.Ajax().Batch(true).ServerOperation(false)
.Read("GetDeliveryUnits","DeliveryUnits")
.Create("Editing_Create", "DeliveryUnits")
.Update("Editing_Update", "DeliveryUnits")
.Destroy("Editing_Destroy", "DeliveryUnits")
.Model(model =>
{
model.Id(m => m.UnitID);
})
)
.Columns(c =>
{
c.Bound(e => e.UnitName);
c.Command(com => com.Destroy());
}
))
If I'm looking with FireBug for example, I see that the input for editing cell is not created.
Does anyone know why this behaviour?
Thank you :)
I have mess all day with this decorator, i read many source to implement dojo tab container via zend framework, but i tried it self result nothing.
is there any misscode with this snippet
$form = new Zend_Dojo_Form();
$form->setName('name')
->setLegend('legend')
;
$form->setDecorators(array(
'formElements',
array('tabContainer', array(
'id' => 'tabContainer',
'style' => 'width: 600px; height: 500px;',
'dijitParams' => array(
'tabPosition' => 'top'
),
)),
'DijitForm',
));
$a = new Zend_Dojo_Form_Element_TimeTextBox('time');
$a->setLabel('label');
$sf = new Zend_Dojo_Form_SubForm();
$sf->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'dl')),
'ContentPane',
));
$sf->addElement($a);
$form->addSubForm($sf, 'subform');
thanks before
this?
or this?
Dojo view helpers in Zend use captureStart() and captureEnd()
I'm looking for a script that will call a random image linked to its corresponding site on pageload. Anyone know a javascript or php way to do this?
<?php
$random = array(
array('image' => 'http://example.com/image1.jpg', 'url' => 'http://example1.com/'),
array('image' => 'http://example.com/image2.jpg', 'url' => 'http://example2.com/'),
array('image' => 'http://example.com/image3.jpg', 'url' => 'http://example3.com/'),
array('image' => 'http://example.com/image4.jpg', 'url' => 'http://example4.com/'),
);
$current = rand(0, count($random) - 1);
print "<img src=\"" . $random[$current]['image'] . "\" alt=\"\" />\n";
?>
Quick and easy. Might not be the best way of doing it - I'd personally hook it into a database instead of a static array - but it'll have you up and running in seconds.