我的框架是codeigniter。
我正在使用mPDF库。(创建pdf文件的库)。现在,我想做一个pdf文件。
mpdf库有如下所示的函数:
$pdf->WriteHTML($html);我想将我的data传递给一个view文件并获得结果,但是我不想向用户显示任何view。
$html = $this->load->view('print' ,$data,true);以上代码将print视图加载给用户。
我的代码超过200行:
http://codepad.org/qDDHfn57
如何解决这个问题?
发布于 2016-01-13 10:37:06
$html = $this->load->view('print' ,$data,true);
$pdf->WriteHTML($html);使用后,您可以重定向到其他页面.
或者加载其他视图,显示pdf文件或其他
发布于 2015-12-30 10:20:55
将mpdf60文件夹放入库中。
在控制器中放置以下代码。
public function doprint($book_id,$pdf=false)
{
$this->load->library('parser');
$page_data['sold_book'] = "Hello world data";
$output = $this->parser->parse('sold_book_detail_print',$page_data,true);
if ($pdf=='print')
$this->_gen_pdf($output);
else
$this->output->set_output($output);
}
//GENRATE PDF FILE
public function _gen_pdf($html,$paper='A4')
{
//this the the PDF filename that user will get to download
$pdfFilePath = "output_pdf_name.pdf";
//load mPDF library
$this->load->library('mpdf60/mpdf');
$mpdf=new mPDF('utf-8',$paper);
//generate the PDF from the given html
$mpdf->WriteHTML($html);
$mpdf->Output();
}将下面的代码放在视图中。
<a href="<?php echo base_url();?>index.php/soldtextbook/doprint/<?php echo $row->buy_book_id; ?>/print" target="_blank" class="post-ad">print shipping Detail</a>并在view.and中创建view.and,用file.php Ex编写html:
<?php if(!empty($sold_book)){
foreach($sold_book as $row){ ?>
<?php if($row->diffrent_address == "0"){ ?>
<div class="col-lg-7 col-md-8">
<div class="book-detail-right">
<div class="book-seller"><h4 style="color:#00a0db;">Shipping Address</h4></div>
<div class="book-seller col-lg-12"><span class="col-lg-4" style="font-weight:bold;">Name:</span> <span class="col-lg-9"><?php echo $row->first_name. " " .$row->last_name; ?></span></div>
<div class="book-seller col-lg-12"><span class="col-lg-4" style="font-weight:bold;">Address : </span><span><?php echo $row->address_1;?></span></div>
<div style="margin-left:72px;"><span class="col-lg-9"><?php echo $row->address_2. "<br/>" .$row->city. "," .$row->county_name. ",<br/>United Kingdom- " .$row->postcode. ".";?></span></div>
<div class="book-seller col-lg-12"><span class="col-lg-4" style="font-weight:bold;">phone : </span><span class="col-lg-9"><?php echo $row->phone_number;?></span></div>
</div><!--en dof book-detail-right-->
</div><!--end of col-lg-8-->
<?php } ?>https://stackoverflow.com/questions/34524143
复制相似问题