PDF export

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • PDF export

    Habedere,

    habe folgendes Problem...ich möchte eine pdf datei erzeugen mit daten die ich aus einer datenbank auslese....alle funzt soweit nur das in der pdf datei der HTML code nicht umgesetzt sonder ausgegeben wird, d.h. anstatt eine tabelle zu erzeugen wird <td><tr>,etc. ausgegeben UND alles wird in die erste zeile gequetscht


    PHP-Code:
    include_lists();
            
    $sql 'SELECT id,name,author,isbn,unit,location,summary FROM bibliography_t_books';
            
    $headline = array(array('Name''name'),
                                array(
    'Author''author'),
                                array(
    'ISBN''isbn'),
                                array(
    'Unit''unit'),
                                array(
    'Location''location'),
                                array(
    'Summary''summary'));
                                
                            
            
    $list = new lists('Name''name');
            
    $db_list $list->get_list($sql);
            if (
    is_array($db_list)) {
                while (list(
    $row) = each($db_list)) {
                
    $disp_list[$row][0] = $db_list[$row][1];
                        
    $disp_list[$row][1] = $db_list[$row][2];
                        
    $disp_list[$row][2] = $db_list[$row][3];
                        
    $disp_list[$row][3] = $db_list[$row][4];
                        
    $disp_list[$row][4] = $db_list[$row][5];
                        
    $disp_list[$row][5] = $db_list[$row][6];
                }
                
    $list_tabled $list->table($headline$disp_list);
            }
        
        
        
        
        
        
    $pdf PDF_new(); 
        
    PDF_open_file($pdf); 
        
    PDF_set_info($pdf"author""User");  
        
    PDF_set_info($pdf"title""Bibliography Index");  
        
    PDF_set_info($pdf"creator""User");  
        
    PDF_set_info($pdf"subject""Bibliography Index"); 
        
    PDF_begin_page($pdf500500); 
        
    $font PDF_findfont($pdf"Helvetica-Bold",  "winansi",0);     
        
    PDF_setfont($pdf$font12);
        
    PDF_show_xy($pdf$list_tabled10470);
        
    PDF_end_page($pdf); 
        
    PDF_close($pdf); 

        
    $buffer PDF_get_buffer($pdf); 
        
    header("Content-type: application/pdf"); 
        
    header("Content-Length: ".strlen($buffer)); 
        
    header("Content-Disposition: inline; filename=index_bibliograpy.pdf"); 
        echo 
    $buffer;
        
        
    PDF_delete($pdf); 


    Was ich bräuchte wäre ein zeilenumbrauch nach z.B. 490 Pixel und etwas das den HTML Tabellen code in eine echte tabelle umsetzt......Jemand ne idee!?
    Zuletzt geändert von I don't mind; 09.03.2006, 13:18.

  • #2
    Die funktion PDF_show_xy interpretiert ja keinen HTML code, musste entweder selbst nen entsprechenden parser schreiben, die sachen manuell platzieren, oder versuchst dich mal hiermit

    Kommentar


    • #3
      http://www.google.de/search?q=%22html+to+PDF%22+php

      http://www.tufat.com/script19.htm

      Kommentar


      • #4
        Ok habs geschafft das ein pdf dokument erzeugt wird und die daten in die tabelle eingefügt werden aber wenn die erste seite voll ist springt das system ja weiter auf die zweite seite....auf dieser wird nun nur die erste zelle ausgegeben, die zweite auf einer neuen seite, usw. , d.h. der datensatz der oben auf der zweiten seite sein sollte wird auf 6 seiten aufgeteilt....jemand ne idee warum?

        PHP-Code:
        require('funclib/fpdf/fpdf.php');

            class 
        PDF extends FPDF
            
        {
            var 
        $B;
            var 
        $I;
            var 
        $U;
            var 
        $HREF;

            function 
        PDF($orientation='L',$unit='mm',$format='A4')
            {
                
        //Call parent constructor
                
        $this->FPDF($orientation,$unit,$format);
                
        //Initialization
                
        $this->B=0;
                
        $this->I=0;
                
        $this->U=0;
                
        $this->HREF='';
            }

            function 
        WriteHTML($html)
            {
                
        //HTML parser
                
        $html=str_replace("\n",' ',$html);
                
        $a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
                foreach(
        $a as $i=>$e)
                {
                    if(
        $i%2==0)
                    {
                        
        //Text
                        
        if($this->HREF)
                            
        $this->PutLink($this->HREF,$e);
                        else
                            
        $this->Write(5,$e);
                    }
                    else
                    {
                        
        //Tag
                        
        if($e{0}=='/')
                            
        $this->CloseTag(strtoupper(substr($e,1)));
                        else
                        {
                            
        //Extract attributes
                            
        $a2=explode(' ',$e);
                            
        $tag=strtoupper(array_shift($a2));
                            
        $attr=array();
                            foreach(
        $a2 as $v)
                                if(
        ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
                                    
        $attr[strtoupper($a3[1])]=$a3[2];
                            
        $this->OpenTag($tag,$attr);
                        }
                    }
                }
            }

            function 
        OpenTag($tag,$attr)
            {
                
        //Opening tag
                
        if($tag=='B' or $tag=='I' or $tag=='U')
                    
        $this->SetStyle($tag,true);
                if(
        $tag=='A')
                    
        $this->HREF=$attr['HREF'];
                if(
        $tag=='BR')
                    
        $this->Ln(5);
            }

            function 
        CloseTag($tag)
            {
                
        //Closing tag
                
        if($tag=='B' or $tag=='I' or $tag=='U')
                    
        $this->SetStyle($tag,false);
                if(
        $tag=='A')
                    
        $this->HREF='';
            }

            function 
        SetStyle($tag,$enable)
            {
                
        //Modify style and select corresponding font
                
        $this->$tag+=($enable : -1);
                
        $style='';
                foreach(array(
        'B','I','U') as $s)
                    if(
        $this->$s>0)
                        
        $style.=$s;
                
        $this->SetFont('',$style);
            }

        }

            
        $pdf=new PDF();
            
        $pdf->AliasNBPages();
            
        $pdf->AddPage();
            
        $pdf->SetFont('Arial','',10);
                    
        // Tabellenlayout vorbereiten
                            
        $pdf->SetFont("Helvetica""B",16);
                            
        $pdf->SetFillColor(200,200,200);
                            
        $pdf->Write(5"Index of Bilbiography");
                            
        $pdf->SetFont("","",11);
                            
        $pdf->Ln();
                            
                            
        // Kopfzeilen schreiben
                            
        $pdf->Cell(40,5,"Name",1,0,"C",1);
                            
        $pdf->Cell(40,5,"Autor",1,0,"C",1);
                            
        $pdf->Cell(40,5,"ISBN",1,0,"C",1);
                            
        $pdf->Cell(30,5,"Unit",1,0,"C",1);
                            
        $pdf->Cell(30,5,"Location",1,0,"C",1);
                            
        $pdf->Cell(70,5,"Summary",1,0,"C",1);
                            
        $pdf->Ln();
            
                
        include_lists();
                
        $sql 'SELECT id,name,author,isbn,unit,location,summary FROM bibliography_t_books';
                
        $headline '';
                                    
                                
                
        $list = new lists('Name''name');
                
        $db_list $list->get_list($sql);
                if (
        is_array($db_list)) {
                    while (list(
        $row) = each($db_list)) {
                        
        $disp_list[$row][0] = $pdf->Ln();
                        
        $x=$pdf->GetX($db_list[$row][1]);
                        
        $y=$pdf->GetY($db_list[$row][1]);
                        
        $pdf->MultiCell(40,5,$db_list[$row][1]);
                        
        $pdf->SetXY($x+40,$y);
                        
        $pdf->MultiCell(40,5,$db_list[$row][2]);
                        
        $pdf->SetXY($x+80,$y);
                        
        $pdf->MultiCell(40,5,$db_list[$row][3]);
                        
        $pdf->SetXY($x+120,$y);
                        
        $pdf->MultiCell(30,5,$db_list[$row][4]);
                        
        $pdf->SetXY($x+150,$y);
                        
        $pdf->MultiCell(30,5,$db_list[$row][5]);
                        
        $pdf->SetXY($x+180,$y);
                        
        $pdf->MultiCell(70,5,$db_list[$row][6]);
                        
        $y=$pdf->GetY($db_list[$row][1]);
                        
        $pdf->Line(10,$y,260,$y);
                        
        $pdf->Line(10,20,10,$y);
                        
        $pdf->Line(50,20,50,$y);
                        
        $pdf->Line(90,20,90,$y);
                        
        $pdf->Line(130,20,130,$y);
                        
        $pdf->Line(160,20,160,$y);
                        
        $pdf->Line(190,20,190,$y);
                        
        $pdf->Line(260,20,260,$y);
                        
                        
                        
                                    
                        
                    }
                    
                }
            
        $pdf->Output();    

        Zuletzt geändert von I don't mind; 10.03.2006, 10:03.

        Kommentar


        • #5
          Wen es interessiert...
          hab ne lösung gefunden...


          PHP-Code:
          require('funclib/fpdf/fpdf.php');

              class 
          PDF extends FPDF
              
          {
              var 
          $B;
              var 
          $I;
              var 
          $U;
              var 
          $HREF;

              function 
          PDF($orientation='L',$unit='mm',$format='A4')
              {
                  
          //Call parent constructor
                  
          $this->FPDF($orientation,$unit,$format);
                  
          //Initialization
                  
          $this->B=0;
                  
          $this->I=0;
                  
          $this->U=0;
                  
          $this->HREF='';
              }

              function 
          WriteHTML($html)
              {
                  
          //HTML parser
                  
          $html=str_replace("\n",' ',$html);
                  
          $a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
                  foreach(
          $a as $i=>$e)
                  {
                      if(
          $i%2==0)
                      {
                          
          //Text
                          
          if($this->HREF)
                              
          $this->PutLink($this->HREF,$e);
                          else
                              
          $this->Write(5,$e);
                      }
                      else
                      {
                          
          //Tag
                          
          if($e{0}=='/')
                              
          $this->CloseTag(strtoupper(substr($e,1)));
                          else
                          {
                              
          //Extract attributes
                              
          $a2=explode(' ',$e);
                              
          $tag=strtoupper(array_shift($a2));
                              
          $attr=array();
                              foreach(
          $a2 as $v)
                                  if(
          ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
                                      
          $attr[strtoupper($a3[1])]=$a3[2];
                              
          $this->OpenTag($tag,$attr);
                          }
                      }
                  }
              }

              function 
          OpenTag($tag,$attr)
              {
                  
          //Opening tag
                  
          if($tag=='B' or $tag=='I' or $tag=='U')
                      
          $this->SetStyle($tag,true);
                  if(
          $tag=='A')
                      
          $this->HREF=$attr['HREF'];
                  if(
          $tag=='BR')
                      
          $this->Ln(5);
              }

              function 
          CloseTag($tag)
              {
                  
          //Closing tag
                  
          if($tag=='B' or $tag=='I' or $tag=='U')
                      
          $this->SetStyle($tag,false);
                  if(
          $tag=='A')
                      
          $this->HREF='';
              }

              function 
          SetStyle($tag,$enable)
              {
                  
          //Modify style and select corresponding font
                  
          $this->$tag+=($enable : -1);
                  
          $style='';
                  foreach(array(
          'B','I','U') as $s)
                      if(
          $this->$s>0)
                          
          $style.=$s;
                  
          $this->SetFont('',$style);
              }

          }

              
          $pdf=new PDF();
              
          $pdf->AliasNBPages();
              
          $pdf->AddPage();
              
          $pdf->SetFont('Arial','',10);
              
          // Tabellenlayout vorbereiten
              
          $pdf->SetFont("Helvetica""B",16);
              
          $pdf->SetFillColor(200,200,200);
              
          $pdf->Write(5"Index of Bilbiography");
              
          $pdf->SetFont("","",11);
              
          $pdf->Ln();
                              
              
          // Kopfzeilen schreiben
              
          $pdf->Cell(40,5,"Name",1,0,"C",1);
              
          $pdf->Cell(40,5,"Autor",1,0,"C",1);
              
          $pdf->Cell(40,5,"ISBN",1,0,"C",1);
              
          $pdf->Cell(40,5,"Unit",1,0,"C",1);
              
          $pdf->Cell(40,5,"Location",1,0,"C",1);
              
          $pdf->Cell(70,5,"Summary",1,0,"C",1);
              
          $pdf->Ln();
              
              
          include_lists();
              
          $sql 'SELECT id,name,author,isbn,unit,location,summary FROM bibliography_t_books';
              
          $headline '';
                                      
                                  
              
          $list = new lists('Name''name');
              
          $db_list $list->get_list($sql);
              if (
          is_array($db_list)) {
                  while (list(
          $row) = each($db_list)) {
                      
          $x=$pdf->GetX($db_list[$row][1]);
                      
          $y=$pdf->GetY($db_list[$row][1]);
                      
          $pdf->MultiCell(40,5,$db_list[$row][1]);
                      
          $pdf->SetXY($x+40,$y);
                      
          $pdf->MultiCell(40,5,$db_list[$row][2]);
                      
          $pdf->SetXY($x+80,$y);
                      
          $pdf->MultiCell(40,5,$db_list[$row][3]);
                      
          $pdf->SetXY($x+120,$y);
                      
          $pdf->MultiCell(40,5,$db_list[$row][4]);
                      
          $pdf->SetXY($x+160,$y);
                      
          $pdf->MultiCell(40,5,$db_list[$row][5]);
                      
          $pdf->SetXY($x+200,$y);
                      
          $pdf->MultiCell(70,5,$db_list[$row][6]);
                      
                      
          $y=$pdf->GetY($db_list[$row][1]);
                      
          $pdf->Line(10,$y,280,$y);
                      
          $pdf->Line(10,20,10,$y);
                      
          $pdf->Line(50,20,50,$y);
                      
          $pdf->Line(90,20,90,$y);
                      
          $pdf->Line(130,20,130,$y);
                      
          $pdf->Line(170,20,170,$y);
                      
          $pdf->Line(210,20,210,$y);
                      
          $pdf->Line(280,20,280,$y);
                  }
              }
              
              
          $pdf->Output();    

          Kommentar

          Lädt...
          X