PDF GENERATION PDF
#1
Posted 23 June 2011 - 12:53 AM
Am working on the PDF generation,am using the following http://www.yiiframew...ension/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
#2
Posted 23 June 2011 - 01:40 AM
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
#3
Posted 23 June 2011 - 02:21 AM
PeRoChAk, on 23 June 2011 - 01:40 AM, said:
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
#4
Posted 23 June 2011 - 06:17 AM
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
#5
Posted 23 June 2011 - 08:00 AM
PeRoChAk, on 23 June 2011 - 06:17 AM, said:
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
#6
Posted 23 June 2011 - 09:33 PM
If you need sample code, then let me know
#8
Posted 24 June 2011 - 02:05 AM
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
#9
Posted 24 June 2011 - 02:05 AM
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
#10
Posted 24 June 2011 - 12:42 PM
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();
#11
Posted 25 June 2011 - 12:35 AM
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/app.../index.php/(the code placed controller table name/test
#12
Posted 25 June 2011 - 12:40 AM
Am struck with problem am generating pdf files but i cant enter data into that file .please any one help me for that problem.
#13
Posted 25 June 2011 - 01:18 AM
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.
#14
Posted 28 June 2011 - 01:27 AM
PeRoChAk, on 25 June 2011 - 01:18 AM, said:
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
#15
Posted 28 June 2011 - 08:42 AM
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
#16
Posted 29 June 2011 - 12:34 AM
PeRoChAk, on 28 June 2011 - 08:42 AM, said:
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 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
#17
Posted 29 June 2011 - 12:34 AM
i have table name tbl_enter
1.uniqueid
2.name.
3.passworld,
am new to this yii frame work
#18
Posted 29 June 2011 - 12:35 AM
i have table name tbl_enter
1.uniqueid
2.name.
3.passworld,
am new to this yii frame work
#19
Posted 29 June 2011 - 04:12 AM
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, '');

Help











