Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: php to dpf

  1. #1
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts

    php to dpf

    i am trying to achieve a php to pdf simple example with PDFlib (bounded with php) but i get the error :

    Code:
    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:

    Code:
    <?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>

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Google is a great new tool. Try it out:

    http://www.google.com/search?q=Canno...s+already+sent
    Are you a Help Vampire?

  • #3
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    yes google is a great new tool but it has nothing to do with the classic header problem (white space).

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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.
    Are you a Help Vampire?

  • #5
    Regular Coder
    Join Date
    Jul 2006
    Posts
    399
    Thanks
    33
    Thanked 7 Times in 7 Posts
    thanks mate , you know what ? it was a BOM problem , had to change the file from UTF to ANSI.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •