tags:

views:

488

answers:

1

Using the above technologies, I want to create a PDF, store it in my db, and email it. All with the click of one button.

I also want to call it up and have it be able to display with a hyperlink.

I am very new to FPDF. Therefore, I am trying to start off very slowly.

I began with this link stackoverflow Q

I put both parts of his code into the same page and tried with separate pages. I made the suggested changes/additions and even did a line by line comparison.

I still get the message, "format error: not a PDF or corrupted"

If I just $pdf->Output(); I get the pdf to display. It's either the way the string is being Output, or it's the header() function. It's not the storage method, unless my column setup is incorrect. BUt a blob is a blob, right?

If you want, I can upload the sanitized code. Just let me know what would help answer this.

Thanks

JJ

here's the code on request here's where I enter it in:

<?php
session_start();
include "server.php";//my file to connect to db
require('fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');

$content = $pdf->Output("", "S"); //return the pdf file content as string

$sql = "update table set table_pdf= '".addslashes($content)."' " . 
    "where table_id = '188'";

mysql_query($sql);

//here's where I retrieve it

$sql2 = "select table_pdf from table where table_id = '188'"; 
$result2 = mysql_query($sql2); 
$rs = mysql_fetch_assoc($result2); 

$content2 = $rs['rdngs_hdr_pdf']; 
header('Content-Type: application/pdf'); 
header("Content-Length: ".strlen(content2)); 
header('Content-Disposition: attachment; filename=myfile.pdf'); 
print $content2; 
?>

Like I said, I have tried the other ideas on the other question link above. right now it just sits on the version where the addslashes is there.

Thanks for any help.

A: 

Give this a try. Instead of using the addslashes to escape the content, try using unpack to get it in a binary represenation:

$content = $pdf->Output("", "S"); //return the pdf file content as string
$data = unpack("H*hex", $content);

$sql = "update table set table_pdf= " . 0x".$data['hex']." . " " . 
    "where table_id = '188'";

For retrieving the data you should be able to just do a select, and then output the content, just like you are already doing.

Jeff
I tried your suggestion, in the first file, I used the coded exactly. As for the retrieval file, I had to augment the code to get it from giving me a parse error. Here is what I did. Notice the " in front of 0x. $sql = "update rdngs_hdr set rdngs_hdr_pdf= " . "0x" . $data['hex']. " " . "where rdngs_hdr_id = '187'"; However, I still get the same error. I don't think my addition was right, otherwise you would have just put the 0x after pdf= and before ". any ideas?
jj.amonit