Actualmente estoy queriendo generar un PDF, y lo logre…aunque no dela manera que esperaba, si genera el pdf, pero a pesar de que si tengo contenido que se deberia mostrar, este no se ve al generar el pdf.
Les dejare el codigo que utilizo en mi Controlador:
$model=$this->loadModel($id);
$mPDF1 = Yii::app()->ePdf->mpdf(‘utf-8’,‘Letter’,’’,’’,15,15,35,25,9,9,‘P’);
//$mPDF1->useOnlyCoreFonts = true;
$mPDF1->SetTitle(“Credencial familiar”);
$mPDF1->SetAuthor("");
//$mPDF1->SetDisplayMode(‘fullpage’);
$mPDF1->WriteHTML($this->renderPartial(‘pdf’,array(‘model’=>$model, ‘mpdf’=>$mPDF1),true));
ob_end_clean();
$mPDF1->Output(‘Credencial.pdf’, ‘I’);
exit;
Y el archivo “pdf.php” que estoy utilizando tiene un html simple que solo dice “hola”.
La verdad ya he indagado mucho y simplemente no encuentro respuesta a esta duda.
Aclaro que utilizo Yii 1.1.6 y mPDF 5.3.0, este ultimo lo debo utilizar obligatoriamente ya que asi me lo pidio la persona con la que estoy trabajando, y lo mismo con la version de Yii.
Espero y me puedan ayudar :,D
Check if only that $this->renderPartial(‘pdf’,array(‘model’=>$model, ‘mpdf’=>$mPDF1),true) works fine.
My spanish is not so good:
Prueba si el view solito funciona.
And how should I do that? xD
Something like:
actionTestpdf()
{
$this->renderPartial(‘pdf’,array(‘model’=>$model, ‘mpdf’=>$mPDF1), false)
}
then just open the corresponding url. and see if it renders something
Thanks for the help.
I think I did it well.
If it does not work … I do it and I get a blank screen.
Probably displaying of errors is disabled in your enviroment.
See https://stackoverflow.com/tags/php/info and scroll down to
“I have a typical “does not work” problem. What should I do before asking a question?”
It explains well how to enable error_reporting.
Then you should get errors displayed, if no errors appear - test if errors would appear by adding wrong code.
Once u made sure errors work, then you can probably solve it yourself; else post the errors here.
Podrias mostrarme el código de la vista pdf
Saludos y bienvenido a la comunidad, por favor si puedes dar más detalles de tu código para colaborarte.
Muchas gracias
Le he estado cambiado algunas cosas mientras intento arreglarlo, por ahora esto es lo que tengo:
-
DatosController.php
$mPDF1 = Yii::app()->ePdf->mpdf(); $mPDF1->WriteHTML($this->renderPartial('pdf',array('model'=>$this>loadModel($id)),true)); $mPDF1->Output(); exit;
-AccessRules
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete','create','update', 'index','view','Pdf', 'GenerarPDF'),
'users'=>array('admin'),
),
-pdf.php
$cuerpo= '<html>
<body>
<h1>Hola</h1>
</body>
</html>';
$mPDF1 = new mPDF('utf-8','Letter','','',15,15,35,25,9,9,'P');
$mPDF1->useOnlyCoreFonts = true;
$mPDF1->SetTitle('Credencial familiar');
$mPDF1->SetAuthor("");
$mPDF1->SetDisplayMode('fullpage');
$mPDF1->WriteHTML($cuerpo);
ob_end_clean();
$mPDF1->Output('Credencial.pdf', 'I');
exit;
-admin.php
array(
'class'=>'CButtonColumn',
'header'=>'Acciones',
//'deleteConfirmation'=>'¿Esta seguro que desea borrar el registro seleccionado?',
//Para las imagenes
'htmlOptions'=>array('style'=>'width:100px!important'),
'headerHtmlOptions'=>array('style'=>'width:100px!important'),
'template'=>'{delete} {update} {view} {pdf}',
'buttons'=>array
(
'view' => array
(
'label'=>'Ver',
'url'=>'Yii::app()->createUrl("tutelas/view", array("id"=>$data->id))',
),
'pdf' => array(
'label'=>'Ver Tutela',
'url'=>"CHtml::normalizeUrl(array('pdf', 'id'=>\$data->id))",
'imageUrl'=>Yii::app()->request->baseUrl.'/images/pdf.png',
'options' => array('class'=>'pdf'),
),
),
),
Gracias por el apoyo espero y si encuentres algo en mi codigo porque la verdad me estoy desesperando xD