Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php][ufpdf] Ilość stron w pdfie
MMX3
post
Post #1





Grupa: Zarejestrowani
Postów: 155
Pomógł: 9
Dołączył: 26.01.2004
Skąd: Poznań

Ostrzeżenie: (0%)
-----


Witam,

Natknąłem się na tutorial z fpdf:
  1. <?php
  2. require('fpdf.php');
  3.  
  4. class PDF extends FPDF
  5. {
  6. //Page header
  7. function Header()
  8. {
  9. //Logo
  10. $this->Image('logo_pb.png',10,8,33);
  11. //Arial bold 15
  12. $this->SetFont('Arial','B',15);
  13. //Move to the right
  14. $this->Cell(80);
  15. //Title
  16. $this->Cell(30,10,'Title',1,0,'C');
  17. //Line break
  18. $this->Ln(20);
  19. }
  20.  
  21. //Page footer
  22. function Footer()
  23. {
  24. //Position at 1.5 cm from bottom
  25. $this->SetY(-15);
  26. //Arial italic 8
  27. $this->SetFont('Arial','I',8);
  28. //Page number
  29. $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
  30. }
  31. }
  32.  
  33. //Instanciation of inherited class
  34. $pdf=new PDF();
  35. $pdf->AliasNbPages();
  36. $pdf->AddPage();
  37. $pdf->SetFont('Times','',12);
  38. for($i=1;$i<=40;$i++)
  39. $pdf->Cell(0,10,'Printing line number '.$i,0,1);
  40. $pdf->Output();
  41. ?>

lecz w ufpdf nie działa. wyświetla {nb} zamiast liczby stron dokumentu. Rozwiązał to ktoś jakoś po ludzku?

Pozdr,
mmx3


--------------------
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
tomalec
post
Post #2





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 7.01.2006

Ostrzeżenie: (0%)
-----


Mi się chyba udało, co prawda chyba mało zgrabnie :/

do
ufpdf.php nadpisujemy fdpfową metodę
  1. <?php
  2. function AliasNbPages($alias='{nb}')
  3. {
  4. //Define an alias for total number of pages
  5. $this->AliasNbPages=$this->utf8_to_utf16be($alias,false);
  6. }
  7. ?>


w fpdf.php w _putpages()

  1. <?php
  2. $nb=$this->page;
  3. if(!empty($this->AliasNbPages))
  4. {
  5. //Replace number of pages
  6. for($n=1;$n<=$nb;$n++)
  7. $this->pages[$n]=str_replace($this->AliasNbPages,$nb,$this->pages[$n]);
  8. }
  9. ?>


zmianiamy na

  1. <?php
  2. $nb=(string)$this->page;//wymuszamy string'a żeby utf8_to_utf16be dobrze zadziałał
  3. if(!empty($this->AliasNbPages))
  4. {
  5. //Replace number of pages
  6. for($n=1;$n<=$nb;$n++)
  7. $this->pages[$n]=str_replace($this->AliasNbPages,$this->utf8_to_utf16be($nb,false),$this->pages[$n]);
  8. }
  9. ?>


Ten post edytował tomalec 1.08.2008, 13:26:55
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 08:14