Comments (17)
You have to load the class before you can make an instance of it. Like this:
App::uses('CakePdf', 'CakePdf.Pdf');
from cakepdf.
Thanks for the quick answer - that's resolved my initial error but now I'm getting:
Missing View
Error: The view for ExpenseClaimsController::admin_approve() was not found.
Error: Confirm you have created the file: C:\wamp\www\expenseApp\app\View\Pdf\view.ctp
admin_approve() doesnt need a view (works fine if I remove the cakepdf code) as it just updates a few details then redirects. Its used within another function.
My pdf views are in app/view/expenseClaims/pdf/view.ctp - how can I point it at that or should I recreate it in the path its looking at?
Thanks
from cakepdf.
OK, resolved the above. Would love to see a more detailed readme of how to send a pdf as an attachment. For example, can I send straight from $pdf or do I have to create the file on the server and then send? Thanks
from cakepdf.
Ok can now create a PDF on the server but am failing to pass vars through to the view due to it being outside of my controllers view. I'm sure its me missing something easy but I want to point this bit:
$CakePdf->template('newsletter', 'default');
at MyControllersName/view/newsletter.
I'm right in thinking all this code goes into the controller function and not the view?
from cakepdf.
I am closing the ticket as it is not a bug
use $CakePdf->viewVars() to set view vars, it works just like CakeEmail class.
I believe currently email attachments can only be used with stored files, although i think someone was working on setting raw attachment data. for now just write to file and use the file as attachment
from cakepdf.
Ok, thanks for the tip.
from cakepdf.
Sorry, just to confirm, do I use something like:
$CakePdf->viewVars('expenseClaim', $this->ExpenseClaim->read(null, $id));
from cakepdf.
Did you end up getting any further with this? I cannot get it to work either. I can get the PDF to generate on the server to be used in the email but it comes though with undefined variable errors. I guess I have the same issue as above, passing the controller set variables into the view of the PDF.
Thanks
from cakepdf.
Hi, yes I did - I merged all the data I needed into one array then passed it to the view using viewVar().
$merged = array_merge($expenseClaim, $expenseTotal, $approvedBy, $disbursements);
$CakePdf->viewVars($merged);
Hope that helps.
from cakepdf.
Thanks for the information. I just tried this but I am still getting errors.
My code is as follows. The arrays are generated above this piece of code in the same function.
$CakePdf = new CakePdf();
$CakePdf->template('forms', 'default');
$merged = array_merge($user, $adverts, $incomes, $customs, $category_name, $deductions, $formvalues);
$CakePdf->viewVars($merged);
$pdf = $CakePdf->write(APP . 'webroot/files/forms' . DS . 'Beanclaim_Form_' . $id . '.pdf');
I think the issue lies in that the arrays I am sending though viewVars (e.g. $user, $incomes, $customs etc) are not found on the template so nothing happens. How do I call these merged arrays on the template page?
At the moment I am trying to call (for example) $user['User']['first_name'] on the pdf template but I get errors such as $user or $incomes is undefined.
Thanks
from cakepdf.
Merge is not correct, like i said it works like CakeEmail->viewVars() (and Controller->set())
so viewVars(array('users' => $users)); or viewVars(compact('users'))l
from cakepdf.
$CakePdf = new CakePdf();
$CakePdf->template('forms', 'default');
$CakePdf->viewVars(compact('user', 'adverts', 'incomes', 'customs', 'category_name', 'deductions', 'formvalues'));
$pdf = $CakePdf->write(WWW_ROOT . 'files' . DS . 'forms' . DS . 'Beanclaim_Form_' . $id . '.pdf');
from cakepdf.
$cakePdf->output() returns string. How we can again use that string to create pdf? Please help me.. I am getting stuck...
from cakepdf.
That string is the pdf contents, but you would not need to use output() method, just call write() as in above example and also described in earlier comments on this thread
from cakepdf.
Thank you ceeram, I have used php function like
. Is it ok?from cakepdf.
That does not look correct really.Please drop by on irc if you can, this is
not really the place for support, as this is a bug tracker.
2015-01-09 14:51 GMT+01:00 Govinda Wagle [email protected]:
Thank you ceeram, I have used php function like
. Is it ok?—
Reply to this email directly or view it on GitHub
#19 (comment)
.
from cakepdf.
It's old thread but I wanted to do same functionality as @jamesjacobs wanted. Below is my code. I have "WkHtmlToPdf" engine enabled with valid binary path given.
When I try to generate and open/download PDF in browser using same engine, it's working fine. But when I try to get PDF content in controller or save file on server directory then it give me error like
wkhtmltopdf binary is not found or not executable: /usr/bin/wkhtmltopdf
For rest of the engines I can get PDF stream and also can save on server dir. But I would like to use "WkHtmlToPdf" engine. Anyone with any idea?
My Code:
$CakePdf = new CakePdf();
$CakePdf->template('/SendPdf/pdf/email_pdf', 'default');
$CakePdf->viewVars(compact('company_details'));
$CakePdf->write(UPLOADS_PROFILE_IMAGES.'test.pdf', true);
from cakepdf.
Related Issues (20)
- CakePdf configuration ignored by the plugin HOT 2
- Add debug option for PDF rendering engine - fonts not rendering HOT 1
- CakePHP 4.x Compatibility HOT 3
- Adapt project description to mention CakePHP 4 HOT 1
- Stable release for CakePHP 4 HOT 2
- Its showing Failed to load PDF document HOT 1
- Error with Cakephp4 HOT 1
- $CakePdf->viewVars($this->_View->viewVars); problem
- wkhtmltopdf binary is not found or not executable - getBinaryPath()
- Include CSS Files in Command does not work HOT 2
- Error in documentation HOT 2
- parameters not passed to mPDF engenie HOT 3
- Using PHP8 impossible with current configuration HOT 2
- Missing CSS with wkhtmltopdf 0.12.6
- Custom Engine possible? (Trying weasyprint) HOT 1
- Problemas ao usar wkhtmltopdf HOT 3
- Windows IIS PHP 8.0.12 System error "'""c:\wkhtmltopdf\bin\wkhtmltopdf.exe" is not recognized as an internal or external command HOT 1
- Support for CakePHP version 4.3 HOT 1
- Loading fonts on CakePHP 4 from Google Fonts HOT 1
- Linux server cannot run direct /usr/bin/wkhtmltopdf
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cakepdf.