...

View Full Version : php to dpf



sybil6
10-24-2009, 04:20 PM
i am trying to achieve a php to pdf simple example with PDFlib (bounded with php) but i get the error :


Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\_PHP\php_pdf\index.php:1) in C:\xampp\htdocs\_PHP\php_pdf\index.php on line 14

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\_PHP\php_pdf\index.php:1) in C:\xampp\htdocs\_PHP\php_pdf\index.php on line 15

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\_PHP\php_pdf\index.php:1) in C:\xampp\htdocs\_PHP\php_pdf\index.php on line 16
%PDF-1.4 %���� 3 0 obj <> stream x�s ��w3P04PI�2T0


the code is:


<?php
$mypdf = PDF_new();
PDF_open_file($mypdf, "");
PDF_begin_page($mypdf, 595, 842);
$myfont = PDF_findfont($mypdf, "Times-Roman", "host", 0);
PDF_setfont($mypdf, $myfont, 10);
PDF_show_xy($mypdf, "Sample PDF, constructed by PHP in real-time.", 50, 750);
PDF_show_xy($mypdf, "Made with the PDF libraries for PHP.", 50, 730);
PDF_end_page($mypdf);
PDF_close($mypdf);

$mybuf = PDF_get_buffer($mypdf);
$mylen = strlen($mybuf);
header("Content-type: application/pdf");
header("Content-Length: $mylen");
header("Content-Disposition: inline; filename=gen01.pdf");
print $mybuf;

PDF_delete($mypdf);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title></title>

</head>

<body>

</body>

</html>

tomws
10-24-2009, 05:31 PM
Google is a great new tool. Try it out:

http://www.google.com/search?q=Cannot+modify+header+information+headers+already+sent

sybil6
10-24-2009, 05:51 PM
yes google is a great new tool but it has nothing to do with the classic header problem (white space).

tomws
10-24-2009, 06:05 PM
I would suggst the "classic" header problem is any output before the header() function, but that's splitting hairs.

I can't test your code on my server since I don't have PDFLib (is it really only for PHP4?) You can test the any output idea by moving your header functions to the start of the file before the PDF functions.

I've also seen recommendations for output buffering functions in certain cases, but I've never used them and can't offer any help in that direction.

sybil6
10-24-2009, 09:12 PM
thanks mate , you know what ? it was a BOM problem , had to change the file from UTF to ANSI.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum