Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8500403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:56:09+00:00 2026-06-11T00:56:09+00:00

I’m working on a way for users to be able to generate PDF copies

  • 0

I’m working on a way for users to be able to generate PDF copies of invoices and other tabular data. To do this, I’ve wrapped dompdf into a library that I can use with CI and created a method that will generate a PDF based on the return value of CI’s output->get_output(). The wrapper is similar to this one on Github.

The problem is, I can’t figure out a way to get the view (and HTML/CSS needed for the PDF) into CI’s output class other than load->view(), which is going to write to the browser.

My only other choice would be to use curl to request the page, but that seems so silly to do since I can get it right from the output buffer. I just don’t want the HTML sent to the browser, since I set headers telling the browser to expect a PDF.

To be clear, this is what I want to accomplish (in the order that I want to accomplish it):

  1. Do everything I’d normally do to prepare the view for display
  2. Load the view into the CI output class, but not display it
  3. Pass the return value of output->get_output() to my dompdf library
  4. Set the appropriate headers
  5. Execute my dompdf method that will send the PDF to the browser

I don’t see any way of doing step 2 based on the output class documentation.

Is it possible to get a view into the output class without displaying it? If so, how? I’m using CI 2.0.3.

Edit

The very helpful Anthony Sterling pointed out that I can just get what I want from the loader class by setting the third argument telling it to return a string rather than render the view to TRUE. E.g.:

$lotsaHtml = $this->load->view('fooview', $somearray, TRUE);

And that would be better in my particular instance since I don’t need to load partials. However, this is still a valid and (I think) interesting question, it would also be handy to know if I could get the same from the OB, perhaps if I did have a bunch of partials. Those could be concatenated, but yuck.

It seems like I should be able to get the output class to not render anything (else, why does get_output() exist?) so I can do something else with everything it knows about. I just can’t find a way to make that happen.

Edit 2

Some pseudo (but not far from reality) code illustrating what I hope to do, by showing what I did and then explaining what I actually wanted to do.

Let’s say I have a public method genpdf($id) in a controller named invoice using a model named inv:

public function genpdf($invoiceId) {
    $this->load->library('dompdflib');
    $this->pagedata['invoice_data'] = $this->inv->getInvoice($invoiceId);
    $html = $this->load->view('pdfgen', $this->pagedata, TRUE);
    $this->dompdflib->sendPdf($html);
}

That is almost identical to code that I have that works right now. There, I ask the loader to parse and give me the results of the pdfgen view as a string, which I pass to the function in my dompdf wrapper that sets headers and sends the PDF to the browser.

It just seemed like this would be easy to do by just getting the output buffer itself (after setting headers correctly / etc).

Or do I just have to call the output class append_output() in succession with every partial I load?

Multiple methods loading a plethora of models need to work together to generate these (they’re going in as an afterthought), so I was hoping to just collect it all and retrieve it directly from the output class. It could be that I just have to talk gradually to output->append_output() to make that happen.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:56:11+00:00Added an answer on June 11, 2026 at 12:56 am

    …so – do I understand correctly – you want to get the whole final output (not just the view) as a string AND not display it to the user? Why dont you just overload the controllers _output() function?

    class Your_controller extends CI_Controller
    {
           function stuff()
           {
               // do whatever - prep $data etc
               $this->load->view('your_view', $data);
           }
    
           function _output($output)
           {
               // send $output to your library - get results blah blah
               $result_pdf_file = $this->your_pdf_library_generator($output);
    
               // Show something else to the user
               echo "hi - I'm not what you expected - but here is your PDF";
    
               echo $result_pdf_file; // or something like that
           }
     }
    

    This means you can send ANYTHING you like to the output class – but nothing is displayed except what you want.

    There are ways to improve this idea (i.e. hooks, variables to turn output on/off etc) – but the simplest would be to have this controller specifically for your pdf_generation command.

    I don’t see any way of doing step 2 based on the output class documentation. Is it possible to get a view into the output class without displaying it? If so, how? I’m using CI 2.0.3.

    The controller _output() documentation is actually in the CI controller documentation, which is why it eluded you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.