I create website based on drupal 7 with module to generate pdf - i use fpdf library.
I dont know how I can make form to send some data to node where i have php code for generate pdf.
Also i still get error message:
FPDF error: Some data has already been output, can't send PDF file (output started at Z:\xampp\htdocs\domain\includes\common.inc:2748)
where i found:
ob_flush();
when i try change it to
ob_clean()
all nodes generate pdf :/
You can try use other module which is a simple - pdf_using_mpdf
With this module you can get PDF of some node calling www.YOUR_SITE.DOMAIN/node/NID_ID/pdf - where NID_ID is the id of node what you want to render as PDF.
Or also you can use hook_menu() if you need render as PDF only some fields of your node - add your item like
$items['%node/create_pdf'] = array(
'title' => '',
'description' => '',
'page callback' => 'custom_callback_create_pdf',
'page arguments' => array(1),
'access callback' => 'node_access',
'type' => MENU_CALLBACK,
);
Define you callback like
function custom_callback_create_pdf($node) {
// Check if current node has needed field.
if (isset($node->field_my_custom_field_of_node)) {
// Render only field 'field_my_custom_field_of_node';
$view = node_view($node);
$output = render($view['field_my_custom_field_of_node']);
return pdf_using_mpdf_api($output, $node->title);
}
else {
return pdf_using_mpdf_api("<html><body>Current page do not required field.</body></html>", $node->title);
}
}
and print button for download:
$pdf_button = l(t('Download as PDF'), 'node/' . $node->nid . '/create_pdf', array(
'attributes' => array(
'target' => '_blank',
'class' => array('render_as_pdf'),
),
));
echo '<p>' . $pdf_button . '</p>';
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
How can convert view page into a pdf in Yii from controller.
in main.php i added this code
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'mpdf' => array(
'librarySourcePath' => 'application.vendors.mpdf.*',
'constants' => array(
'_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'),
),
'class'=>'mpdf', // the literal class filename to be loaded from the vendors folder
),
'HTML2PDF' => array(
'librarySourcePath' => 'application.vendors.html2pdf.*',
'classFile' => 'html2pdf.class.php', // For adding to Yii::$classMap
)
),
),
Controller Code is
$mPDF1 = Yii::app()->ePdf->mpdf('', 'A5');
$mPDF1->WriteHTML($this->renderPartial('printformat', array(), true));
$mPDF1->Output();
Error : include(mpdf.php) [function.include]: failed to open stream: No such file or directory
The Error says, you have to include mpdf.php before using it.
You are using YiiPdf Bundle with html2pdf and mpdf.
First download Yii Pdf from here and include in extension as protected/extensions/yii-pdf (ext.yii-pdf as in 'class' => 'ext.yii-pdf.EYiiPdf',). This means your extension folder contains yii-pdf as directory.
Then, download mpdf from here. and place it in vendors as protected/vendors/mpdf as in
'librarySourcePath' => 'application.vendors.mpdf.*',
All explanation is here.
I am trying to make a Magento module, to enable our Magento-webshop customers to import all our products automatically. Since I'm not yet very proficient in Magento development, I run into a few stops on the way... :-)
Right now I try to make a AdminController in which the index page should simply display a text and a button to start the import process. It's the "addButton" part, that I have trouble with:
public function indexAction() {
$this->loadLayout();
$block = $this->getLayout()
->createBlock('core/text', 'example-block')
->setText("
<h1>Import/update products</h1>
<p>On this page you can start the import of all products from Misstoro.</p>
...bla bla bla...
");
$this->_addContent($block);
$url = $this->getUrl('*/*/do_import');
$this->_addButton('button_import', array(
'label' => Mage::helper('import')->__('Start import'),
'onclick' => 'setLocation(\'' . $url .'\')',
'class' => 'add',
));
$this->renderLayout();
}
$this->_addButton gives me an "Call to undefined method" error.
What is the right way to do this?
/ Carsten
Figured it out with a little more research:
$url = $this->getUrl('*/*/do_import');
$block = $this->getLayout()
->createBlock('adminhtml/widget_button')
->setData(array(
'label' => Mage::helper('import')->__('Start import'),
'onclick' => 'setLocation(\'' . $url .'\')',
'class' => 'add',
));
$this->_addContent($block);
I'd like to upload multiple files using Form API.
'#type' => 'file' provides upload only one file.
$form['picture_upload'] = array(
'#type' => 'file',
'#title' => t(''),
'#size' => 50,
'#description' => t(''),
'#weight' => 5,
);
How can i provide multiple upload?
Aside from putting the form element in a for loop, I would suggest (for now) using the plupload form element.
http://drupal.org/project/plupload
Then:
$form['picture_upload'] = array(
'#type' => 'plupload',
'#title' => t(''),
'#size' => 50,
'#description' => t(''),
'#weight' => 5,
);
This is similar to a issue I had: Drupal 7 retain file upload
You can use managed_file element type instead of file
here's the drupal documentation: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/7#managed_file
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.