note 34459 added to ref.pdf

From: Date: Mon, 28 Jul 2003 11:23:13 +0000
Subject: note 34459 added to ref.pdf
Groups: php.notes 
Request: Send a blank email to php-notes+get-52831@lists.php.net to get a copy of this message
About creating a PDF document based on the content of another document(let's say a text file): I have tried to send to the PDF-creator page from a link from the sender page the file name of the file I want to read the content from and generate the PDF document containing this content. The idea is is that when I tried to reffer the pdf-creator page via the link your_root/create_pdf.php?filename=$your_file_name, the pdf-creator page does not behave well when before creating the pdf document I have a line like $filename = $_GET["filename"]. I solved this using on the sender page instead of the link a form with a button, so the form has as action "create_pdf.php", as method "post" and a hidden field containing the "filename" value. And it works like this if, on the pdf-creator page I have a line like $filename = $_POST["filename"]. I would like to understand why this way it works and the other way does not. I hope this helps. Here are the pieces of code I used. Sender page: print("<form name='to_pdf' action='see_pdf_file.php' method='post'>"); print("<br/><input type='submit' value='PDF'><input type='hidden' name='filename' value='$filename'></form>"); PDF-creator page: <? $filename = $_POST["filename"]; $file_handle = fopen($filename, "r"); $file_content = file_get_contents($filename); fclose($file_handle); // $file_content = wordwrap($file_content,72,"|"); $a_row = explode("|",$file_content); $i = 0; // $pdf = pdf_new(); pdf_open_file($pdf, ""); pdf_begin_page($pdf, 595, 842); pdf_set_font($pdf, "Times-Roman", 16, "host"); pdf_add_outline($pdf, "Page 1"); pdf_set_value($pdf, "textrendering", 1); pdf_show_xy($pdf, 'The content of the file:',50,700); while ($a_row[$i] != "") { pdf_continue_text($pdf,$a_row[$i]); $i++; } pdf_end_page($pdf); pdf_close($pdf); // $data = pdf_get_buffer($pdf); // header("Content-type: application/pdf"); header("Content-disposition: inline; filename=test.pdf"); header("Content-length: " . strlen($data)); // echo $data; ?> PDFLib and PHP 431 used. Thanks. ---- Manual Page -- http://www.php.net/manual/en/ref.pdf.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34459 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34459&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34459&report=yes

« previous php.notes (#52831) next »