PDF GENERATION

Hi ,

Am working on the PDF generation,am using the following http://www.yiiframework.com/extension/tcpdf,so i can put the tCPDF in extensions folder and i add the following code


  D:\Dev\Apache\htdocs\first\protected\views\layouts\main.php,[code]<?php

$pdf = Yii::createComponent(‘application.extensions.tcpdf.ETcPdf’,

                        'P', 'cm', 'A4', true, 'UTF-8');

$pdf->SetCreator(PDF_CREATOR);

$pdf->SetAuthor("Nicola Asuni");

$pdf->SetTitle("TCPDF Example 002");

$pdf->SetSubject("TCPDF Tutorial");

$pdf->SetKeywords("TCPDF, PDF, example, test, guide");

$pdf->setPrintHeader(false);

$pdf->setPrintFooter(false);

$pdf->AliasNbPages();

$pdf->AddPage();

$pdf->SetFont("times", "BI", 20);

$pdf->Cell(0,10,“Example 002”,1,1,‘C’);

$pdf->Output("example_002.pdf", "I"); ?>

/code]

i got the following error

require_once(D:\Dev\Apache\htdocs\first\protected\extensions\tcpdf/tcpdf/tcpdf.php): failed to open stream: No such file or directory.

please help me

You should check the files that you have put in the ext folder

I think you have tcpdf folder and then in it there is again tcpdf folder

which is making problems

put the files as

ext /tcpdf/ETcPdf.php

i can remove the all tcpdf ,and also i got the same error

What I mean is that

You should place all the files of tcpdf ext in ext folder as

ext/tcpdf

As

pdf = Yii::createComponent('application.extensions.tcpdf.ETcPdf

this line of code suggests that

the ETcPdf file is located in application/extensions/tcpdf folder

ya ,i will do that way ,but i cant get any progress,i will remove all the errors,how to see pdf file in the application

tHE PDF will be displayed in the webpage accessing the current controller

If you need sample code, then let me know

thankk you for giving reply.please send me sample code,


public function actionTest(){


//require_once('../config/lang/eng.php');

//require_once('../tcpdf.php');

$pdf = Yii::createComponent('application.extensions.tcpdf.TcPdf',

                            'P', 'cm', 'A4', true, 'UTF-8');

//$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);


// set document information

$pdf->SetCreator(PDF_CREATOR);

$pdf->SetAuthor('Nicola Asuni');

$pdf->SetTitle('TCPDF NAGRAJ');

$pdf->SetSubject('TCPDF Tutorial');

$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

$pdf->setPrintHeader(true);

$pdf->setPrintFooter(true);

// set default header data

$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING);


// set header and footer fonts

$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));

$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));


// set default monospaced font

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);


//set margins

$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);

$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);


//set auto page breaks

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);


//set image scale factor

$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);


// ---------------------------------------------------------


// set default font subsetting mode

$pdf->setFontSubsetting(true);


// Set font

// dejavusans is a UTF-8 Unicode font, if you only need to

// print standard ASCII chars, you can use core fonts like

// helvetica or times to reduce file size.

$pdf->SetFont('dejavusans', '', 14, '', true);


// add a page

$pdf->AddPage();


// This method has several options, check the source code documentation for more information.

// Set some content to print

//Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M')


// test Cell stretching

$pdf->Cell(0, 0, 'TEST CELL STRETCH: no stretch', 1, 1, 'C', 0, '', 0);

$pdf->Cell(0, 0, 'TEST CELL STRETCH: scaling', 1, 1, 'C', 0, '', 1);

$pdf->Cell(0, 0, 'TEST CELL STRETCH: force scaling', 1, 1, 'C', 0, '', 2);

$pdf->Cell(0, 0, 'TEST CELL STRETCH: spacing', 1, 1, 'C', 0, '', 3);

$pdf->Cell(0, 0, 'TEST CELL STRETCH: force spacing', 1, 1, 'C', 0, '', 4);


$pdf->Ln(5);


$pdf->Cell(45, 0, 'TEST CELL STRETCH: scaling', 1, 1, 'C', 0, '', 1);

$pdf->Cell(45, 0, 'TEST CELL STRETCH: force scaling', 1, 1, 'C', 0, '', 2);

$pdf->Cell(45, 0, 'TEST CELL STRETCH: spacing', 1, 1, 'C', 0, '', 3);

$pdf->Cell(45, 0, 'TEST CELL STRETCH: force spacing', 1, 1, 'C', 0, '', 4);


$pdf->AddPage();


// example using general stretching and spacing


for ($stretching = 90; $stretching <= 110; $stretching += 10) {

	for ($spacing = -0.254; $spacing <= 0.254; $spacing += 0.254) {


		// set general stretching (scaling) value

		$pdf->setFontStretching($stretching);


		// set general spacing value

		$pdf->setFontSpacing($spacing);


		$pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, no stretch', 1, 1, 'C', 0, '', 0);

		$pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, scaling', 1, 1, 'C', 0, '', 1);

		$pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, force scaling', 1, 1, 'C', 0, '', 2);

		$pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, spacing', 1, 1, 'C', 0, '', 3);

		$pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, force spacing', 1, 1, 'C', 0, '', 4);


		$pdf->Ln(2);

	}

}

// ---------------------------------------------------------


// Close and output PDF document

// This method has several options, check the source code documentation for more information.

$pdf->Output('NAGRAJ.pdf', 'I');




with this code i may get empty pdf,but i want to get details pdf,

i have table with

1.username,

2.password,

3.email

i may display the all the above values in that pdf,please help me


public function actionTest(){


//require_once('../config/lang/eng.php');

//require_once('../tcpdf.php');

$pdf = Yii::createComponent('application.extensions.tcpdf.TcPdf',

                            'P', 'cm', 'A4', true, 'UTF-8');

//$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);


// set document information

$pdf->SetCreator(PDF_CREATOR);

$pdf->SetAuthor('Nicola Asuni');

$pdf->SetTitle('TCPDF NAGRAJ');

$pdf->SetSubject('TCPDF Tutorial');

$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

$pdf->setPrintHeader(true);

$pdf->setPrintFooter(true);

// set default header data

$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING);


// set header and footer fonts

$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));

$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));


// set default monospaced font

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);


//set margins

$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);

$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);


//set auto page breaks

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);


//set image scale factor

$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);


// ---------------------------------------------------------


// set default font subsetting mode

$pdf->setFontSubsetting(true);


// Set font

// dejavusans is a UTF-8 Unicode font, if you only need to

// print standard ASCII chars, you can use core fonts like

// helvetica or times to reduce file size.

$pdf->SetFont('dejavusans', '', 14, '', true);


// add a page

$pdf->AddPage();


// This method has several options, check the source code documentation for more information.

// Set some content to print

//Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M')


// test Cell stretching

$pdf->Cell(0, 0, 'TEST CELL STRETCH: no stretch', 1, 1, 'C', 0, '', 0);

$pdf->Cell(0, 0, 'TEST CELL STRETCH: scaling', 1, 1, 'C', 0, '', 1);

$pdf->Cell(0, 0, 'TEST CELL STRETCH: force scaling', 1, 1, 'C', 0, '', 2);

$pdf->Cell(0, 0, 'TEST CELL STRETCH: spacing', 1, 1, 'C', 0, '', 3);

$pdf->Cell(0, 0, 'TEST CELL STRETCH: force spacing', 1, 1, 'C', 0, '', 4);


$pdf->Ln(5);


$pdf->Cell(45, 0, 'TEST CELL STRETCH: scaling', 1, 1, 'C', 0, '', 1);

$pdf->Cell(45, 0, 'TEST CELL STRETCH: force scaling', 1, 1, 'C', 0, '', 2);

$pdf->Cell(45, 0, 'TEST CELL STRETCH: spacing', 1, 1, 'C', 0, '', 3);

$pdf->Cell(45, 0, 'TEST CELL STRETCH: force spacing', 1, 1, 'C', 0, '', 4);


$pdf->AddPage();


// example using general stretching and spacing


for ($stretching = 90; $stretching <= 110; $stretching += 10) {

	for ($spacing = -0.254; $spacing <= 0.254; $spacing += 0.254) {


		// set general stretching (scaling) value

		$pdf->setFontStretching($stretching);


		// set general spacing value

		$pdf->setFontSpacing($spacing);


		$pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, no stretch', 1, 1, 'C', 0, '', 0);

		$pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, scaling', 1, 1, 'C', 0, '', 1);

		$pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, force scaling', 1, 1, 'C', 0, '', 2);

		$pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, spacing', 1, 1, 'C', 0, '', 3);

		$pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, force spacing', 1, 1, 'C', 0, '', 4);


		$pdf->Ln(2);

	}

}

// ---------------------------------------------------------


// Close and output PDF document

// This method has several options, check the source code documentation for more information.

$pdf->Output('NAGRAJ.pdf', 'I');




with this code i may get empty pdf,but i want to get details pdf,

i have table with

1.username,

2.password,

3.email

i may display the all the above values in that pdf,please help me

How I Generate PDF

1 - I created a a controller action that have no View

I set all the data to PDF and use the output function to make it as PDF




Yii::createComponent('application.extensions.tcpdf.ETcPdf', 

															'P', 'cm', 'A4', true, 'UTF-8');

								$pdf->SetCreator(PDF_CREATOR);

								$pdf->SetAuthor("");

								$pdf->SetTitle("Jurney Info");

								$pdf->SetSubject("Journey");

								$pdf->SetKeywords("TCPDF, PDF, example, test, guide");

								$pdf->setPrintHeader(false);

								$pdf->setPrintFooter(false);

								$pdf->AliasNbPages();

								$pdf->AddPage();


								

$html='';							

// Add Your data to make it in PDF 




// After having PDF data, use this to make PDF output

	$pdf->writeHTML($html, true, false, false, false, '');

								$pdf->LastPage();


								$pdf->Output('pdf file name.pdf', 'F');

								Yii::app()->end();





public function actionTest(){


//require_once('../config/lang/eng.php');

//require_once('../tcpdf.php');

$pdf = Yii::createComponent('application.extensions.tcpdf.TcPdf',

                            'P', 'cm', 'A4', true, 'UTF-8');

//$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);


// set document information

$pdf->SetCreator(PDF_CREATOR);

$pdf->SetAuthor('Nicola Asuni');

$pdf->SetTitle('TCPDF NAGRAJ');

$pdf->SetSubject('TCPDF Tutorial');

$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

$pdf->setPrintHeader(true);

$pdf->setPrintFooter(true);

// set default header data

$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', PDF_HEADER_STRING);


// set header and footer fonts

$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));

$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));


// set default monospaced font

$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);


//set margins

$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);

$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);

$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);


//set auto page breaks

$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);


//set image scale factor

$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);


// ---------------------------------------------------------


// set default font subsetting mode

$pdf->setFontSubsetting(true);


// Set font

// dejavusans is a UTF-8 Unicode font, if you only need to

// print standard ASCII chars, you can use core fonts like

// helvetica or times to reduce file size.

$pdf->SetFont('dejavusans', '', 14, '', true);


// add a page

$pdf->AddPage();


// This method has several options, check the source code documentation for more information.

// Set some content to print

//Cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=0, $link='', $stretch=0, $ignore_min_height=false, $calign='T', $valign='M')


// test Cell stretching

$pdf->Cell(0, 0, 'TEST CELL STRETCH: no stretch', 1, 1, 'C', 0, '', 0);

$pdf->Cell(0, 0, 'TEST CELL STRETCH: scaling', 1, 1, 'C', 0, '', 1);

$pdf->Cell(0, 0, 'TEST CELL STRETCH: force scaling', 1, 1, 'C', 0, '', 2);

$pdf->Cell(0, 0, 'TEST CELL STRETCH: spacing', 1, 1, 'C', 0, '', 3);

$pdf->Cell(0, 0, 'TEST CELL STRETCH: force spacing', 1, 1, 'C', 0, '', 4);


$pdf->Ln(5);


$pdf->Cell(45, 0, 'TEST CELL STRETCH: scaling', 1, 1, 'C', 0, '', 1);

$pdf->Cell(45, 0, 'TEST CELL STRETCH: force scaling', 1, 1, 'C', 0, '', 2);

$pdf->Cell(45, 0, 'TEST CELL STRETCH: spacing', 1, 1, 'C', 0, '', 3);

$pdf->Cell(45, 0, 'TEST CELL STRETCH: force spacing', 1, 1, 'C', 0, '', 4);


$pdf->AddPage();


// example using general stretching and spacing


for ($stretching = 90; $stretching <= 110; $stretching += 10) {

        for ($spacing = -0.254; $spacing <= 0.254; $spacing += 0.254) {


                // set general stretching (scaling) value

                $pdf->setFontStretching($stretching);


                // set general spacing value

                $pdf->setFontSpacing($spacing);


                $pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, no stretch', 1, 1, 'C', 0, '', 0);

                $pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, scaling', 1, 1, 'C', 0, '', 1);

                $pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, force scaling', 1, 1, 'C', 0, '', 2);

                $pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, spacing', 1, 1, 'C', 0, '', 3);

                $pdf->Cell(0, 0, 'Stretching '.$stretching.'%, Spacing '.sprintf('%+.3F', $spacing).'mm, force spacing', 1, 1, 'C', 0, '', 4);


                $pdf->Ln(2);

        }

}

// ---------------------------------------------------------


// Close and output PDF document

// This method has several options, check the source code documentation for more information.

$pdf->Output('NAGRAJ.pdf', 'I');



the following code shoud be placed in cntroller and go to browser

http://localhost/applicationname/index.php/(the code placed controller table name/test

hi all,

Am struck with problem am generating pdf files but i cant enter data into that file .please any one help me for that problem.

Use my code

and use $html variable to store data to be printed.

How to get the data

Use Models to get the data form database

Example

1 - Table : Products

2 - Model : Products

3 - $product_data=Products::model()->findByPk(1);

4 - $html.=’<b>Product Name</b>:’.$product_data->name;

5 - Place data to pdf object as $pdf->writeHTML($html, true, false, false, false, ‘’);

now print the page.

What I can Understand by your last post is that, you does not know How to get the data that you want to print, so for that, you need to work with your database/text file and take the data from your either source and use HTML to store and print it.

Thanks

Don’t forget to +Vote if your issue get Solved.

Thank you for giving reply,

but i cant get it please send me any sample code

Oh buddy,

let me give a short example




$html.='Hello World';

$pdf->writeHTML($html, true, false, false, false, '');



So, what happened?

what we set for $html, will be written on PDF.

If you have no understanding of How to assign values to a variable or do not know how to fetch and process data from database, then you should study first about these.

Thanks

thanks for giving reply …any sample code send me .

i have table name tbl_enter

1.uniqueid

2.name.

3.passworld,

am new to this yii frame work

thanks for giving reply …any sample code send me .

i have table name tbl_enter

1.uniqueid

2.name.

3.passworld,

am new to this yii frame work

Ok

Following Code will fetch data from Enter model which is for table tbl_enter




$html='<table><tr><td>ID</td><td>Name </td><td>Pass World</td></tr>';

$model=Enter::model()->findAll();

if(!empty($model)){

  foreach($model[0] as $data){

  $html.='<tr><td>'.$data['uniqueid'].'</td><td>'.$data['name'].'</td><td>'.$data['passworld'].'</td></tr>';

  }

}

$html.='</table>';



the following code is the object of PDF ext which will print the $html data to the pdf file




$pdf->writeHTML($html, true, false, false, false, '');



thank you