Page 1 of 2

Create PDF

Posted: Sun Feb 19, 2006 5:05 pm
by icesolid
I tried to use this code provided on the php.net web site and I get this error:

Fatal error: Call to undefined function: pdf_new() in /home/caposcom/public_html/savecase.php on line 2

Code: Select all

<?php
$p = PDF_new();

/*  open new PDF file; insert a file name to create the PDF on disk */
if (PDF_begin_document($p, "", "") == 0) {
   die("Error: " . PDF_get_errmsg($p));
}

PDF_set_info($p, "Creator", "hello.php");
PDF_set_info($p, "Author", "Rainer Schaaf");
PDF_set_info($p, "Title", "Hello world (PHP)!");

PDF_begin_page_ext($p, 595, 842, "");

$font = PDF_load_font($p, "Helvetica-Bold", "winansi", "");

PDF_setfont($p, $font, 24.0);
PDF_set_text_pos($p, 50, 700);
PDF_show($p, "Hello world!");
PDF_continue_text($p, "(says PHP)");
PDF_end_page_ext($p, "");

PDF_end_document($p, "");

$buf = PDF_get_buffer($p);
$len = strlen($buf);

header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=hello.pdf");
print $buf;

PDF_delete($p);
?>
Any ideas?

Posted: Sun Feb 19, 2006 5:05 pm
by feyd
your host doesn't have the pdf extension loaded.

Posted: Sun Feb 19, 2006 5:06 pm
by John Cartwright
http://php.net/pdf
Requirements

PDFlib is available for download at http://www.pdflib.com/products/pdflib/index.html, but requires that you purchase a license for commercial use.

Posted: Sun Feb 19, 2006 5:07 pm
by RobertPaul
Did you install the pdflib extension?


[edit]Foiled once again! :oops: [/edit]

My Host Sucks

Posted: Sun Feb 19, 2006 5:16 pm
by icesolid
Nah I just talked to my host, they dont have it installed, I also have another problem they don't have the exif lib installed.

I'm moving to a liquidweb.com dedicated server tomorrow so I will be back for more help I'm sure.

Posted: Sun Feb 19, 2006 5:35 pm
by onion2k
http://www.fpdf.org/ .. in my opinion, the best PDF library for PHP. It doesn't require any extensions.

That's Pretty Handy

Posted: Sun Feb 19, 2006 6:59 pm
by icesolid
That a pretty nice and easy to use library.

Requires a lot of work to get the final PDF document to look how you want it tho.

Explain to me, how is using that not illegal, aren't you suppose to pay to create PDF files?

Posted: Sun Feb 19, 2006 7:01 pm
by John Cartwright
aren't you suppose to pay to create PDF files?
In a word, no. You only have to pay if you are using the pdflib library for commercial use.. and even then all you have to do is buy a license..

Re: That's Pretty Handy

Posted: Mon Feb 20, 2006 3:05 am
by onion2k
icesolid wrote:Requires a lot of work to get the final PDF document to look how you want it tho.
No more than any other output.

Posted: Mon Feb 20, 2006 3:06 am
by JayBird
Check in code snippets....i posted a quick intro to creating PDFs

Question

Posted: Mon Feb 20, 2006 1:07 pm
by icesolid
I am trying to use this library http://www.fpdf.org/ to create PDFs.

I want to print out all of the columns in one record from my database into a PDF.

I tried using their example script here http://www.fpdf.org/en/script/script10.php , but it is for printing out all of the records in the database.

I just want to print out all of the columns in one row.

I want to result to look like this

Code: Select all

<table>
  <tr>
    <td colspan="2">TICKET INFORMATION FOR CONTROL <?php echo $row["control_number"]; ?></td>
  </tr>
  <tr>
    <td>column title 1</td>
    <td><?php echo $row["column 1"]; ?></td>
  </tr>
  <tr>
    <td>column title 2</td>
    <td><?php echo $row["column 2"]; ?></td>
  </tr>
  <tr>
    <td>column title 3</td>
    <td><?php echo $row["column 3"]; ?></td>
  </tr>
  etc...
</table>
Anyone?

Posted: Mon Feb 20, 2006 2:49 pm
by onion2k

Code: Select all

$pdf = new PDF('P','mm','A4');
$pdf->SetTitle('My First PDF');
$pdf->SetAuthor('Chris Neale');
	
$pdf->AddPage();

$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','',10);

while ($record = mysql_fetch_object($result)) {				
	$pdf->Cell(100,7,"TICKET INFORMATION FOR CONTROL ".$record->control_number,'BT',0,'L',0);
	$pdf->Cell(40,7,$record->column1,'BT',0,'L',0);
	$pdf->Cell(40,7,$record->column2,'BT',0,'L',0);
	$pdf->Cell(30,7,$record->column3,'BT',0,'L',0);
	$pdf->Ln();
}
Basically.. $pdf->Cell is the equivalent of <td>, and $pdf->Ln() is the equivalent of <tr> .. if you need more complex layouts remember that you can move around the page with $pdf->setXY() .. but it gets complicated if you do.

Posted: Mon Feb 20, 2006 3:24 pm
by icesolid
I get an error using the code below on line 13 (bold tags around it):

Fatal error: Cannot instantiate non-existent class: pdf in /home/caposcom/public_html/savecase.php on line 13

Code: Select all

<?php
define('FPDF_FONTPATH','font/');
require('fpdf153/fpdf.php');

//Connect to your database
include("connect.php");

[b]$pdf = new PDF('P','mm','A4'); [/b]
$pdf->SetTitle('My First PDF'); 
$pdf->SetAuthor('Chris Neale'); 
     
$pdf->AddPage(); 

$pdf->SetTextColor(0,0,0); 
$pdf->SetFont('Arial','',10); 

$result = mysql_query("SELECT * FROM cases WHERE id='" . $_GET["id"] . "'");

while ($record = mysql_fetch_object($result)) {                 
    $pdf->Cell(100,7,"TICKET INFORMATION FOR CONTROL ".$record->control_number,'BT',0,'L',0); 
    $pdf->Cell(40,7,$record->column1,'BT',0,'L',0); 
    $pdf->Cell(40,7,$record->column2,'BT',0,'L',0); 
    $pdf->Cell(30,7,$record->column3,'BT',0,'L',0); 
    $pdf->Ln(); 
}

$pdf->Output();
?>

Posted: Mon Feb 20, 2006 4:03 pm
by Ree
Include your PDF class, it's non-existant in your script. May want to check letter case as well.

Posted: Mon Feb 20, 2006 4:16 pm
by icesolid
This is the class right here isent it?

require('fpdf153/fpdf.php');

I have it included in my code.