LARAVEL 5.7 FPDF - Config file to change orientation of PDF is not working - fpdf

I'm using Laravel 5.7 on my application and I installed codedge/laravel-fpdf to create PDF files. The installation was successful and I was able to generate PDF file with their sample on the documentation:
Fpdf::AddPage();
Fpdf::SetFont('Courier', 'B', 18);
Fpdf::Cell(50, 25, 'Hello World!');
Fpdf::Output();
exit();
However, I want to change the paper size and page orientation. So I run:
php artisan vendor:publish --provider="Codedge\Fpdf\FpdfServiceProvider" --tag=config
and it generates config file at config/fpdf.php
When I try to change the orientation and size it doesn't work.
'orientation' => 'L',
'unit' => 'mm',
'size' => 'Letter',
What could be the possible reason to this?

I did like below code. It's working. what you have to do, you can create a class to extend FPDF.
Class Name: class.custom.print.php. you can keep file location where you want.
use Codedge\Fpdf\Fpdf\Fpdf;
class customPdf extends Fpdf
{
public function Header()
{
//you can add your own code
}
public function Footer()
{
//you can add your own code
}
}
You can add a function in your Controller.
require_once 'class.custom.print.php';
$objPdf = new customPdf('L', 'mm', 'A4');
$objPdf->SetTitle("Title");
$objPdf->SetAuthor('Author');
$objPdf->AddPage();
$objPdf->AliasNbPages();
ob_start();
$objPdf->Output("Title.pdf", 'I');
ob_flush();
exit;
If you are getting any difficulties, please let me know.

Related

TYPO3 extbase, the php based views do not work when migrating from 9 to 10 version

I have developed a custom TYPO3 extbase extension that was perfectly worked on 8 and 9 version of TYPO3.
Recently I upgraded my installation to TYPO3 10 version but the php based views of my TYPO3 extbase extension do not work anymore.
The error that is displayed is:
Sorry, the requested view was not found.
The technical reason is: No template was found. View could not be resolved for action "getIcal" in class "Luc\Lucevents2\Controller\EventController"
I have read the instructions in the page
https://docs.typo3.org/m/typo3/book-extbasefluid/10.4/en-us/8-Fluid/9-using-php-based-views.html, but there is nothing different from what I have already done in my extension.
So, I am very confused because there is no explanation why the code stopped to work, the above link doesn't include any instructions about deprecated code or possible changes after migration!!
Could you give me any help?
Thank you very much!
George
I hit this problem today. The documentation for "php based views" seems to be outdated.Below is a description of my setup and the solution for TYPO3 10
What I had:
My situation was that I had a Controller with a showAction() action method.
In typoscript, I had setup a new format through the type parameter. Something like
rss = PAGE
rss {
typeNum = 58978
10 =< tt_content.list.20.skevents_eventfeeds
}
For this type (parameter type=58978) I had setup a class named View\EventFeeds\ShowRss with a render() method.
TYPO3 automatically resolved this class based on the type (rss) and the action name (show). This does not work any more.
What solves this issue:
in order for TYPO3 to find the correct class with the render method, it is sufficient to set the defaultViewObjectName variable of the Controller to the correct class name for the specific action. This can be done in the controller with the following new method
public function initializeShowAction()
{
$this->defaultViewObjectName = \Skar\Skevents\View\EventFeeds\ShowRss::class;
}
So now, before calling the showAction method, defaultViewObjectName is set to my ShowRss class which produces the output.
Please note that my ShowRss class extends \TYPO3\CMS\Extbase\Mvc\View\AbstractView . According to https://docs.typo3.org/m/typo3/book-extbasefluid/master/en-us/8-Fluid/9-using-php-based-views.html this is deprecated in TYPO3 11 and will have to change for TYPO3 12
the static template is already included and all the other operations of the extension are working very well except the php based views. The ext_localconf.php looks as follows: <?php
defined('TYPO3_MODE') || die('Access denied.');
$boot = function () {
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Luc.Lucevents2',
'Luceventsdisplay',
[
'Event' => 'list, show, delete, edit, monthview, test, ajax, deleteConfirm, showRss, getIcal, addForm, add, editForm, importeventtoforum',
'Channel' => 'list, show',
'Tag' => 'filter, show'
],
// non-cacheable actions
[
'Event' => 'list, show, delete, edit, monthview, test, ajax, deleteConfirm, showRss, getIcal, addForm, add, editForm, importeventtoforum',
'Channel' => 'list, show',
'Tag' => 'filter, show'
]
);
};
$boot();
unset($boot);
The action is registered in EventController.php and looks as follows:
/**
* action geticalaction
*
* #param \Luc\Lucevents2\Domain\Model\Event $event
* #return void
*/
public function getIcalAction(\Luc\Lucevents2\Domain\Model\Event $event = NULL)
{
$base_url = $this->request->getBaseUri();
$channel=$this->settings['channel_for_simple_users'];
if($this->request->hasArgument('duration'))
{
if ($this->request->getArgument('duration')=='6month') {
$duration=$this->request->getArgument('duration');
}
else
{
$duration='month';
}
$events = $this->eventRepository->get_events_for_rss_and_ical($duration,$channel);
$eventsarray= array();
foreach ($events as $obj){
$this->uriBuilder->setCreateAbsoluteUri(true);
$uri = $this->controllerContext->getUriBuilder()
->setUseCacheHash(false)
->uriFor('show', array("event" => $obj->getUid()));
$eventsarray[] = array($obj->getTitle(), $obj->getDescription(), $obj->getStartdatetime(),$obj->getEnddatetime(), $obj->getBuildingid(), $obj->getRoomid(), $obj->getPlace(), $obj->getCrdate(), $uri, $obj->getUid());
}
$this->view->assign('events', $eventsarray);
$this->view->assign('baseurl', $base_url);
}
else
{
$this->uriBuilder->setCreateAbsoluteUri(true);
$uri = $this->controllerContext->getUriBuilder()
->setUseCacheHash(false)
->uriFor('show', array("event" => $event->getUid()));
$this->view->assign('event', $event);
$this->view->assign('baseurl', $base_url);
$this->view->assign('uri', $uri);
}
}
Thank you very much!

File Upload in Userfrosting

We need to have the user upload an image as a part of sign up process.
Had tried accessing $_FILES['filename'] in the controller, which turns out to be undefined under slim.
Had seen about Slim's way of file uploading in a couple of articles, which are reported to be working, but I hit the wall.
The twig part works fine with Bootstrap File Input library
For the server part using File Upload library for Slim
Controller code (modifications to AccountController) looks like this
...
$storage = new \Upload\Storage\FileSystem('c:/xampp/htdocs/userfrosting/public/images/');
$file = new \Upload\File('imagefile', $storage);
$new_filename = 'test.jpg';
$file->setName($new_filename);
$file->addValidations(array(
// Ensure file is of type "image/jpg"
new \Upload\Validation\Mimetype('image/jpg'),
// Ensure file is no larger than 500K (use "B", "K", M", or "G")
new \Upload\Validation\Size('500K')
));
// Access data about the file that has been uploaded
$uploadfiledata = array(
'name' => $file->getNameWithExtension(),
'extension' => $file->getExtension(),
'mime' => $file->getMimetype(),
'size' => $file->getSize(),
'md5' => $file->getMd5(),
'dimensions' => $file->getDimensions()
);
error_log('$uploadfiledata' . print_r($uploadfiledata, true));
// Try to upload file
try {
// Success!
$file->upload();
} catch (\Exception $e) {
// Fail!
$errors = $file->getErrors();
}
...
This returns the following error,
Type: InvalidArgumentException
Message: Cannot find uploaded file identified by key: imagefile
File: C:\xampp\htdocs\userfrosting\userfrosting\vendor\codeguy\upload\src\Upload\File.php
Line: 139
The relevant twig chunk is
<input id="imagefile" type="file" name="imagefile" class="file" data-show-upload="false">
Has anyone been able to get file upload working as a part of any Userfrosting code?
Appreciate any help / pointers.
Thanks!
My guess is that you're using ufFormSubmit to submit your registration form, and it is not grabbing the file input. So, you will probably need to add some extra code on the client side to explicitly submit the file input along with the rest of the form. See this example using Dropzone and UF: https://gist.github.com/frostbitten/c1dce70023321158a2fd#file-upload-twig
By the way, you can use your browser to see what data is actually being sent in your POST request. For example, in Firefox you can use the Network Monitor.

Cakephp 3 Image Upload to Cloudinary via API

I was about to upload images to cloudinary - a Image CDN look cloudinary.com, It supports all languages and frameworks including Cakephp 3, but for cakephp 3 the steps we're not included in their site. Can anyone possibly say me steps for uploading images in ease?
As per their site, I'm providing procedures for uploading.
Base Documentation:
http://cloudinary.com/documentation/php_integration#getting_started_guide
Step 1:
Installation
{
"require": {
"cloudinary/cloudinary_php": "dev-master"
}
}
Add the above to your composer.json located in your project folder.
You can use composer to update it and fetch dependencies. Run the following in composer after navigating to your project folder.
php composer.phar update
Step 2:
Installation in Cake PHP.
Open your AppController and add the following in the initialize function
It apparently looks like the following:
public function initialize() {
parent::initialize();
$this->loadComponent('Flash');
\Cloudinary::config(array(
"cloud_name" => "sample",
"api_key" => "874837483274837",
"api_secret" => "a676b67565c6767a6767d6767f676fe1"
));
}
In the above you can find the cloudinary configuration, replace with your own credentials.
To fetch credentials, follow the link below and sign in,
https://cloudinary.com/users/login
Step 3:
Image Upload Procedure
<?php
echo $this->Form->create('upload_form', ['enctype' => 'multipart/form-data']);
echo $this->Form->input('upload', ['type' => 'file']);
echo $this->Form->button('Change Image', ['class' => 'btn btn-primary']);
echo $this->Form->end();
?>
Use the above code in your view file. (you can modify as you need)
In your controller, you can use in the following way,
if (!empty($this->request->data['upload']['name'])) {
$file = $this->request->data['upload']; //put the data into a var for easy use
$cloudOptions = array("width" => 1200, "height" => 630, "crop" => "crop");
$cloudinaryAPIReq = \Cloudinary\Uploader::upload($file["tmp_name"], $cloudOptions);
$imageFileName = $cloudinaryAPIReq['url'];
}
You can save the $imagefilename in your database, in here the complete url is saved and repopulated.

Create Email HTML Using Partial in Zend Framework 2?

I'm working on a system where we want to queue up a batch of emails and then send them using a queue (so I can't use \Zend\Mail directly). The goal is to not have HTML inside the models that are creating the emails but instead have them in a view file. I'm trying to call the partial view helper inside the models (which I did in ZF1) but can't find anything on the web on how to do this. Is this possible in ZF2 or is there a better way? I've managed it before where we've had the HTML inside the models and it's been a mess. :-)
You can just create a template somewhere, pull the renderer from your service locator, and render away:
<?php
// this assumes you're in some AbstractActionController,
// but you could be in some service class that has the
// renderer injected, etc.
// template vars
$vars = array(/* .... */);
// create a ViewModel
$vm = new \Zend\View\Model\ViewModel($vars);
// path to your email template, compatible with your template map config.
$tpl = 'mymodule/emails/some-email-template.phtml';
$vm->setTemplate($tpl);
// get the renderer from the ServiceManager, so it's all nicely configured.
$renderer = $this->getServiceLocator()->get('Zend\View\Renderer\RendererInterface');
// render some HTML
$html = $renderer->render($vm);
You could do it this way:
1. In the module.config define those HTML mail content template views.
'view_manager' => array(
(...)
'template_map' => array(
'mail_content_1' => __DIR__ . '/../view/<MODULE_NAME>/mail_content_1.phtml',
),
(...)
)
2. Load the Template View in your model and get the HTML.
use Zend\View\Model\ViewModel;
public function getMailHTML() {
$view = new ViewModel;
$variables = array( "parm1" => "value1" );
//SET THE VARIABLES, LIKE IN PARTIALS
$view->setVariables( $variables );
//SET THE TEMPLATE VIEW KEY DEFINED IN THE module.config
$view->setTemplate( 'mail_content_1' );
//YOU'LL HAVE TO BE ABLE TO USE THE ServiceManager IN YOUR MAIL MODELS.
//RENDERING THE VIEW YOU'LL GET THE HTML
return $this->serviceManager->get( 'viewrenderer' )->render( $view );
}

Class Sofzo_From not found error when implementing Sozfo TinyMCE solution

I'm trying to implement TinyMCE to text areas using the solution mentioned in Sofzo. But when I try to extend the Sofzo_Form I get the following error :
Fatal error: Class 'Sozfo_Form' not found in /home/foldername/public_html/application/forms/PageForm.php on line 4
What I have done so far -
Uploaded the Sofzo files to library with following directory structure
/library
../Sozfo
../Form.php
../../Form
../../../Element
../../../../TinyMce.php
../../View
../../../Helper
../../../Exception.php
../../../../FormTinyMce.php
../../../../TinyMce.php
Loaded the classes in application.ini as
Autoloadnamaspaces[] = "Sofzo_"
And in bootstrap as
$autoLoader = Zend_Loader_Autoloader::getInstance();
$autoLoader->registerNamespace('Zend_');
$autoLoader->registerNamespace('SF_');
$autoLoader->registerNamespace('CMS_');
$autoLoader->registerNamespace('Sofzo_');
$loader = new Zend_Loader_PluginLoader();
$loader->addPrefixPath('Zend_View_Helper', 'Zend/View/Helper/')
->addPrefixPath('Storefront_View_Helper',
'application/modules/storefront/views/helpers')
->addPrefixPath('Sozfo_Form', 'Sozfo/');
$view=new Zend_View();
$view->addHelperPath('Sozfo/View/Helper', 'Sozfo_View_Helper');
But when I try to extent the Sofzo_Form in Page_Form as
class Form_PageForm extends Sozfo_Form { }
This issue was solved thanks to Tim Fountain. But now when I load an element as
$this->addElement('tinyMce', 'message', array(
'label' => 'Message',
'required' => true,
'cols' => '50',
'rows' => '10',
'editorOptions' => new Zend_Config_Ini(APPLICATION_PATH . '/configs/tinymce.ini', 'moderator')
));
I get the following error
Plugin by name 'FormTinyMce' was not found in the registry
Read through several comments in original site and they are said to add
$view->addHelperPath('Sozfo/View/Helper', 'Sozfo_View_Helper');
to bootstrap. I've already done that, but I'm guessing I'm not doing something right. Help is much appreciated.
I think the issue is ZF can't find the class because it doesn't know about the Sozfo_ namespace. You've attempted to register this namespace in two different ways, but both of them are incorrect.
In application.ini, you have:
Autoloadnamaspaces[] = "Sofzo_"
But this should be:
autoloaderNamespaces[] = "Sozfo_"
Then in the bootstrap you've tried to register it with:
$autoLoader->registerNamespace('Sofzo_');
but presumably this should be:
$autoLoader->registerNamespace('Sozfo_');
(note spelling). Which ever fix you apply you should only use one of these methods, as they do the same thing.
If it still doesn't work after that then there's an issue with your include_path.
Edit: To fix the view helper path, try this instead of the two lines you currently have:
$view = new Zend_View();
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer($view);
$stack = Zend_Controller_Action_HelperBroker::getStack();
$stack->push($viewRenderer);
$view->addHelperPath('Sozfo/View/Helper', 'Sozfo_View_Helper');
This adds the helper path to a view object like you have but also supplies it to the view renderer (which is what renders all the view scripts). If you don't do this then the view renderer uses its own view object, so the view object you setup in the bootstrap is never used for anything.
If this doesn't work, try passing a full path as the first parameter to addHelperPath instead:
$view->addHelperPath(APPLICATION_PATH.'/../library/Sozfo/View/Helper', 'Sozfo_View_Helper');