Hi Guru.

I try to write a code that can generate PDF with HTML input.
After generate PDF file, it will open the PDF file automatically.
These code work fine until generate PDF file but when it's
try to open the file automatically, the PDF prompt "Acrobat
could not open $filename because it is either not supported
file type or because the file has been corrupted..bla..bla..blaa

Here the code

$sql = "SELECT * FROM no_ruj_fail WHERE proj_nm = '123'";
$result = mysql_query($sql) or die(mysql_error());
while ($rows=mysql_fetch_array($result))
 {
   $nmfail = $rows['nama_fail'];
   $nofail = $rows['no'];
 }
$nofail = $nmfail.$nofail;
$nofail2 = str_replace('/','_',$nofail);
$fileName = $nofail2.'.pdf';
$surat = $uploadDir.$fileName;

$pdf = pdf_new();
  pdf_open_file($pdf, $surat);
 /*  pdf_set_info($pdf, "Author",$surat);
  pdf_set_info($pdf, "Creator", "See Author");
  pdf_set_info($pdf, "Subject", "Testing"); */
  pdf_begin_page($pdf, 595, 842);
  $font = pdf_load_font($pdf, "Helvetica","iso8859-2", "");
  pdf_setfont($pdf, $font, 11); 

 // pdf_show_xy($pdf, "Copyright G.I.S@2008", 1, 1);

  $font2 = PDF_load_font($pdf, "Helvetica-Bold","iso8859-2", "");
  pdf_setfont($pdf, $font2,11);
  pdf_show_xy($pdf,"MEMO",285,700);
  pdf_show_xy($pdf,"BAHAGIAN KAWALAN DAN KAWALAN LANDSKAP",190,680);
  pdf_show_xy($pdf,"JABATAN LANDSKAP DAN TAMAN",220,660);

  $font = PDF_load_font($pdf, "Helvetica","iso8859-2", "");
  pdf_setfont($pdf, $font, 11); 
  pdf_show_xy($pdf,"Kepada     :",50,630);
  pdf_show_xy($pdf,$to1,130, 630);
  pdf_show_xy($pdf,"Daripada   :",50,610);
  pdf_show_xy($pdf,$from,130,610);
  pdf_show_xy($pdf,"Salinan     :",50,580);
  pdf_show_xy($pdf,$copy1,130,580);
  pdf_show_xy($pdf,$copy2,130,560);
  pdf_show_xy($pdf,$copy3,130,540);
  pdf_show_xy($pdf,"Ruj. Fail   :",50,520);
  pdf_show_xy($pdf,$nofail,130,520);
  pdf_show_xy($pdf,"Tarikh      :",50,500);
  pdf_show_xy($pdf,$date,130,500);

  $font2 = PDF_load_font($pdf, "Helvetica-Bold","iso8859-2", "");
  pdf_setfont($pdf, $font2,11);
  pdf_show_xy($pdf,"Perkara :",140,470);
  pdf_show_xy($pdf,$text1,190,470);
  pdf_continue_text($pdf,$text1a);
  pdf_continue_text($pdf,$text2);
  pdf_continue_text($pdf,$text3);

   $font = PDF_load_font($pdf, "Helvetica","iso8859-2", "");
  pdf_setfont($pdf, $font, 11); 
  pdf_show_xy($pdf,$text4,50,420);
  pdf_show_xy($pdf,$text5,50,400);
  pdf_show_xy($pdf,$text6,50,390);
  pdf_show_xy($pdf,$text7,50,380);
  $font2 = PDF_load_font($pdf, "Helvetica-Bold","iso8859-2", "");
  pdf_setfont($pdf, $font2,11);
  pdf_show_xy($pdf,"Tarikh                       :",160,360);
  pdf_show_xy($pdf,$tarikh,270,360);
  pdf_show_xy($pdf,"Masa                         :",160,350);
  pdf_show_xy($pdf,$masa,270,350);
  pdf_show_xy($pdf,"Tempat Berkumpul :",160,340);
  pdf_show_xy($pdf,$loca,270,340);
  pdf_continue_text($pdf,$loca2);
  $font = PDF_load_font($pdf, "Helvetica","iso8859-2", "");
  pdf_setfont($pdf, $font, 11); 
  pdf_show_xy($pdf,$text8,50,310);
  pdf_continue_text($pdf,$text9);
  pdf_continue_text($pdf,$text10);
  pdf_show_xy($pdf,$text11,50,280);
  pdf_continue_text($pdf,$text12);
  pdf_show_xy($pdf,$text13,50,220);
  pdf_show_xy($pdf,$text14,50,200);
  pdf_show_xy($pdf,$sign,50,100);

  pdf_end_page($pdf);
 //pdf_set_parameter($pdf, "openaction", "fitpage");
  pdf_close($pdf);

  header("Pragma: public");
  header("Expires: 0");
  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  header("Cache-Control: private",false);
  header("Content-Type: application/pdf");
  header("Content-Disposition: attachment;  filename=\"".basename($fileName)."\";");
  header("Content-Transfer-Encoding: binary");
  header("Content-Length: ".@filesize($fileName));
  @readfile("$fileName") or die("File not found.");

Hope Guru can help me to solved this matter..
Thanks.

    comment out the header() and see if any php errors are occurring

      Hi HalfaBee,
      Thanks for reply,

      I follow what u ask for and no error.
      The PDF file successfully generated and i can open it using Adobe Acrobat 5.0!

        Hi HalfaBee,
        Thanks for reply,

        I follow what u ask for and no error.
        The PDF file successfully generated and i can open it using Adobe Acrobat 5.0!

          If the "file" is openable, there must be some invalid output before you do the readfile()

            HalfaBee;10884128 wrote:

            If the "file" is openable, there must be some invalid output before you do the readfile()

            I open the generated PDF file manually in folder where is generated.
            What i want is, i want the generated pdf file automatically open after i click button.

              Yes, I understand that, that is why I suggested you see if something is being output before the readfile().

                HalfaBee;10884132 wrote:

                Yes, I understand that, that is why I suggested you see if something is being output before the readfile().

                Hi HalfaBee,

                I just found out something.
                Where i click generate, in the status bar said download from site http://localhost/letter.php which is letter.php is my php source code
                and i want to download filename.php
                how to change this in header information.?
                Please view the attachment..
                Thanks

                  Just change this line
                  header("Content-Disposition: attachment; filename=\"".basename($fileName)."\";");

                  You are currently using the name that is created for the pdf creation.

                    HalfaBee;10884277 wrote:

                    Just change this line
                    header("Content-Disposition: attachment; filename=\"".basename($fileName)."\";");

                    You are currently using the name that is created for the pdf creation.

                    Hi,
                    yes i exactly want to open the pdf after created.
                    how to set the pdf file and the file path ?
                    help me..

                      The file is saved to $surat so use that instead of $fileName.

                      @readfile("$surat") or die("File not found.");

                        HalfaBee;10884291 wrote:

                        The file is saved to $surat so use that instead of $fileName.

                        @readfile("$surat") or die("File not found.");

                        how about the header("Content-Disposition: attachment; filename=\"".basename($fileName)."\";");
                        Can i still use it ?

                          Write a Reply...