Code Monkey home page Code Monkey logo

Comments (17)

sarahhenkens avatar sarahhenkens commented on July 29, 2024

You have to load the class before you can make an instance of it. Like this:

App::uses('CakePdf', 'CakePdf.Pdf');

from cakepdf.

jamesjacobs avatar jamesjacobs commented on July 29, 2024

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.

jamesjacobs avatar jamesjacobs commented on July 29, 2024

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.

jamesjacobs avatar jamesjacobs commented on July 29, 2024

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.

ceeram avatar ceeram commented on July 29, 2024

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.

jamesjacobs avatar jamesjacobs commented on July 29, 2024

Ok, thanks for the tip.

from cakepdf.

jamesjacobs avatar jamesjacobs commented on July 29, 2024

Sorry, just to confirm, do I use something like:

$CakePdf->viewVars('expenseClaim', $this->ExpenseClaim->read(null, $id));

from cakepdf.

elogicmedia avatar elogicmedia commented on July 29, 2024

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.

jamesjacobs avatar jamesjacobs commented on July 29, 2024

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.

elogicmedia avatar elogicmedia commented on July 29, 2024

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.

ceeram avatar ceeram commented on July 29, 2024

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.

ceeram avatar ceeram commented on July 29, 2024
$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.

Govinda-Wagle avatar Govinda-Wagle commented on July 29, 2024

$cakePdf->output() returns string. How we can again use that string to create pdf? Please help me.. I am getting stuck...

from cakepdf.

ceeram avatar ceeram commented on July 29, 2024

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.

Govinda-Wagle avatar Govinda-Wagle commented on July 29, 2024

Thank you ceeram, I have used php function like

. Is it ok?

from cakepdf.

ceeram avatar ceeram commented on July 29, 2024

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.

parixit572 avatar parixit572 commented on July 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.