php - dompdf using curl instead of allow_url_fopen -


i've been working through problem dompdf, we've built application using codeigniter , needed feature allowed printing pdf.

locally, dompdf worked great. however, on live server images broken , not found, though provide link broken image work fine if copy/pasted url toolbar.

i did digging , discovered if in php.ini settings enabled allow_url_fopen fix problem, did!

however, success came crashing down when discovered allowing setting made our server less secure, cannot happen. have other secure apps on there.

i saw people hinting towards using programming language called "curl" done, rather enabling allow_url_fopen.

can give me advice on how implement curl dompdf? has done before?

here function generates pdf:

public function create_pdf($hash = false) {      //hash might full 12-12, or front 12 chars. must 12 or invalid     if (empty($hash) || (strlen($hash) < 12))      {         redirect('view_proposal/error/invalid');     }       $this->data['display_buttons'] = false;      $proposal = $this->proposal_model->get_by_hash($hash);      if (empty($proposal))      {         redirect('view_proposal/error/notfound');     }      $page_break  = '<p style="page-break-after: always"></p>';      //from proposal hash, get:      // cover page     $html = $this->_get_page($hash, 'cover', $proposal);     $html .= $page_break;      // contents     $this->load->model('proposal_block_model');     $blocks = $this->proposal_block_model->get_many_by('proposal_id', $proposal->id);      if (!empty($blocks))     {         foreach ($blocks $block) {             $html .= $this->_get_page($hash, $block->block_id, $proposal);         }                }         $html .= $page_break;       // pricing page     $html .= $this->_get_page($hash, 'pricing', $proposal);     $html .= $page_break;      // terms & conditions     $html .= $this->_get_page($hash, 'terms', $proposal);     $html .= $page_break;      //return $html;      //status info     //$html .= $this->_get_page($hash, 'status_info', $proposal);     //$html .= $page_break;      //create pdf version of output, , set $html      $path = 'file';      $this->load->library('my_dompdf');     $this->my_dompdf->pdf_create($html, $path, true); } 

you'll see function references function called "_get_page". collects pages in work proposal created, create_pdf function creating pdf output of dompdf.

here "_get_page" function if helps:

    function _get_page($hash, $block_id, $proposal) {     $this->data['proposal'] = $proposal;      $this->data['primary'] = (count(explode('-', $hash)) > 1);      $proposal->sent_date = (empty($activity)) ? '' : 'proposal sent date '. show_local_time((int)$activity->cdate);     $proposal->end_date = (empty($proposal->end_date)) ? '' : 'good until '. show_local_time((int)$proposal->end_date);      $proposal->accent_color = ($proposal->header_color == 'ffffff') ? '000000' : $proposal->accent_color;      $blocks = $this->block_model->get_toplevel_by_proposal($proposal->id);      $block_toc = $this->_block_toc($blocks, $block_id);      $this->data['prev_page'] = $block_toc['prev'];     $this->data['next_page'] = $block_toc['next'];         //render substitution variables     $this->load->library('proposals_lib');     $proposal->introduction = $this->proposals_lib->render_string($proposal->introduction, $proposal->id);     $proposal->terms_conditions = $this->proposals_lib->render_string($proposal->terms_conditions, $proposal->id);     $proposal->conclusion = $this->proposals_lib->render_string($proposal->conclusion, $proposal->id);       $this->data['proposal_open'] = in_array($proposal->status, array(proposal_status_draft, proposal_status_sent, proposal_status_reviewed));      $this->data['css'] = 'css/public/external/pdf_proposal.css';      switch ($block_id)     {         case 'cover':             $this->data['client'] = $this->client_model->get($proposal->client_id);             $html = $this->load->view('public/external/proposal_pages/cover_page', $this->data, true);             break;         case 'pricing':             $this->load->model('proposal_pricing_items_model');             $this->data['price_items'] = $this->proposal_pricing_items_model->order_by('order', 'asc')->order_by('id', 'asc')->as_object()->get_many_by('proposal_id',$proposal->id);             $html = $this->load->view('public/external/proposal_pages/pricing_page', $this->data, true);             break;         case 'terms': //only pdf             $this->data['terms'] = $proposal->terms_conditions;             $html = $this->load->view('public/external/proposal_pages/terms_page', $this->data, true);             break;         case 'status': //only pdf             $html = $this->load->view('public/external/proposal_pages/status_info_page', $this->data, true);             break;                        default:              $contents = $this->block_model->get_by_proposal($proposal->id);             $this->data['blocks'] = $this->_get_content($contents, $block_id, $block_toc['next']);              $this->data['blocks'] = $this->proposals_lib->render_sections($this->data['blocks'], $proposal->id);              $html = $this->load->view('public/external/proposal_pages/internal_page', $this->data, true);     }      return $html; } 

and function, small, called "get_page" used page of proposal:

    //ajax call page  public function get_page() {      $hash       = $this->input->post('proposal_hash', true);     $block_id   = $this->input->post('page_id', true);      $proposal = $this->proposal_model->get_by_hash($hash);      //confirm page_id (block_id) part of proposal hashed, content     if(is_numeric($block_id) && !$this->block_model->block_in_proposal($block_id, $proposal->id))         return $this->ajax_output(array('message'=>'the page requested not part of proposal.') , false);       $html = $this->_get_page($hash, $block_id, $proposal);      $this->ajax_output(array('html'=>$html), true); } 

here example of how 1 of images called:

 <img src="<?php echo base_url();?>uploads/clients/<?= $client->image ?>"> 

sorry if i'm pulling @ straws here help, took far long me discover fix enabling "allow_url_fopen", can't solution i'm square one. if solution using curl need help...

thanks!

edit***

here lame attempt @ using curl first time:

class my_dompdf 

{

function pdf_create($html, $filename='', $stream=true)  {   $ch = curl_init(); curl_setopt($ch, curlopt_url, 'http://hidden.com/view_proposal/vfgxkjcnsrns');  curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_followlocation, true); //$st = curl_getinfo($ch, curlinfo_http_code);   $html = curl_exec($ch); curl_close($ch);      $dompdf = new dompdf();     $dompdf->load_html($html);     $dompdf->render();     if ($stream) {         $dompdf->stream($filename.".pdf");     } else {         return $dompdf->output();     } } 

}

which spits error:

fatal error: call member function prepend_child() on non-object in c:\uniserver\www\clientsky\application\libraries\dompdf\include\frame_tree.cls.php on line 231


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -