Я использую dompdf для cakephp для конвертирования html в pdf, но проблема все изображение не отображается, как я отображаю изображение? этоКак я отображаю изображение в pdf-файле, используя dompdf в cakephp 2
Router::parseExtensions('pdf');
и это AppController
public $components = array('RequestHandler');
это app/View/Layouts/pdf/admin.ctp
:
<?php
require_once(APP . 'Vendor' . DS . 'dompdf' . DS . 'dompdf_config.inc.php');
spl_autoload_register('DOMPDF_autoload');
$dompdf = new DOMPDF();
$dompdf->set_paper = 'A4';
$dompdf->load_html(utf8_decode($content_for_layout), Configure::read('App.encoding'));
$dompdf->render();
echo $dompdf->output();
и это приложение/Controller/LocationsController:
public function admin_view_pdf($id = null) {
$this->Location->id = $id;
if (!$this->Location->exists()) {
throw new NotFoundException(__('Invalid post'));
}
// increase memory limit in PHP
ini_set('memory_limit', '512M');
$this->set('post', $this->Location->read(null, $id));
$options = array('conditions' => array('Location.' . $this->Location->primaryKey => $id));
$location=$this->Location->find('first', $options);
$this->set('location', $location);
$country=new Country();
$options2 = array('conditions' => array('Country.' . $country->primaryKey => $location['User']['country_id']));
$this->set('country',$country->find('first',$options2));
$city=new City();
$options3 = array('conditions' => array('City.' . $city->primaryKey => $location['User']['city_id']));
$this->set('city',$city->find('first',$options3));
$permit=new Permit();
$options4 = array('conditions' => array('Permit.' . $permit->primaryKey => $location['User']['permit_id']));
$this->set('permit',$permit->find('first',$options4));
$category=new Category();
$options5 = array('conditions' => array('Category.' . $category->primaryKey => $location['Car']['category_id']));
$this->set('category',$category->find('first',$options5));
$subcategory=new Subcategory();
$options6 = array('conditions' => array('Subcategory.' . $subcategory->primaryKey => $location['Car']['subcategory_id']));
$this->set('subcategory',$subcategory->find('first',$options6));
$country2=new Country();
$options7 = array('conditions' => array('Country.' . $country2->primaryKey => $location['Agency']['country_id']));
$this->set('country2',$country2->find('first',$options7));
$city2=new City();
$options8 = array('conditions' => array('City.' . $city2->primaryKey => $location['Agency']['city_id']));
$this->set('city2',$city2->find('first',$options8));
}
и это app/View/Locations/admin_view.ctp
:
<?php echo $this->Html->link(__('PDF'), array('action' => 'admin_view_pdf', 'ext' => 'pdf', $location['Location']['id'])); ?>
и это app/View/Locations/pdf/admin_view_pdf.ctp
:
<div class="row" style="margin-left: 8px;">
<div class="col-lg-10 col-md-10" style="margin-left: 8px;" >
<div class="span12 columns">
<ol class="breadcrumb">
<li><?php echo $this->Html->link('Location','/');?>
</li>
<li class="active"><?php echo $location['User']['first_name'];?>
</li>
</ol>
<div class="panel panel-info">
<div class="panel-heading">
Primary Panel
</div>
<div class="panel-body">
<div class="col-lg-4 col-md-4">
<?php echo $this->Html->image($location['Car']['avatar'], array('alt'=>$location['Car']['id'],'width'=>'250'));?>
<p>
<h4><?php echo $category['Category']['name'];?></h4>
<p>
<h4><?php echo $subcategory['Subcategory']['name'];?></h4>
<h5><small style="font-family: 'Roboto Slab';"> Car pseudo </small><?php echo $location['Car']['title'];?></h5>
<h5><small style="font-family: 'Roboto Slab';"> Color </small><?php echo $location['Car']['color'];?></h5>
<h5><small style="font-family: 'Roboto Slab';"> Serial </small><?php echo $location['Car']['serial'];?></h5>
<h5><small style="font-family: 'Roboto Slab';"> Model </small><?php echo $location['Car']['model'];?></h5>
<h4><small style="font-family: 'Roboto Slab';"> Price </small><?php echo $location['Car']['price'];?></h4>
</div>
<div class="col-lg-4 col-md-4">
<div><?php echo $this->Html->image($location['User']['picture'], array('alt'=>$location['User']['first_name'],'width'=>'150'));?></div>
<h4><?php echo $location['User']['last_name'];?></h4>
<h5><small style="font-family: 'Roboto Slab';"> First name </small><?php echo $location['User']['first_name'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">Id </small><?php echo $location['User']['id'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">Username </small><?php echo $location['User']['username'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">Birthday </small><?php echo $location['User']['birthday'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">Created </small> <?php echo $location['User']['created'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">Modified </small> <?php echo $location['User']['modified'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">Email</small> <?php echo $location['User']['email'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">CIN </small> <?php echo $location['User']['cin'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">Role </small> <?php echo $location['User']['role'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">Status </small> <?php echo $location['User']['status'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">Permit </small> <?php echo $location['User']['permit'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">Phone </small> <?php echo $location['User']['phone'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">Country </small> <?php echo $country['Country']['country'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">City </small> <?php echo $city['City']['city'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">Permit Type </small> <?php echo $permit['Permit']['category'];?></h5>
</div>
<div class="col-lg-4 col-md-4">
<div><?php echo $this->Html->image('logo.png', array('width' => '100', 'height'=>'60')); ?></div>
<h5><small style="font-family: 'Roboto Slab';"> First name </small><?php echo $location['Agency']['id'];?></h5>
<h5><small style="font-family: 'Roboto Slab';"> First name </small><?php echo $location['Agency']['name'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">Country </small> <?php echo $country2['Country']['country'];?></h5>
<h5><small style="font-family: 'Roboto Slab';">City </small> <?php echo $city2['City']['city'];?></h5>
</div>
<h5><small style="font-family: 'Roboto Slab';"> </small></h5>
</div>
<div class="panel-footer">Panel Footer</div>
</div>
</div>
</div>
</div>
кто-нибудь может мне помочь!
PS: все работы в Locations/admin_view.ctp
и тот же код в admin_view_pdf.ctp
Это не связано, но довольно важно. Избавьтесь от 'uff8_decode()' ... это разрушительно для вашего контента. – BrianS