login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Overige scripts > MiPDF (PDF Classe)

MiPDF (PDF Classe)

Auteur: Wim - 04 januari 2006 - 17:51 - Gekeurd door: Ontani - Hits: 4189 - Aantal punten: (0 stemmen)




Een PDF classe die ik geschreven heb...

Het wordt weinig gebruikt, maar is wel zeer krachtig & goed!

Denk b.v. aan een facturatiesysteem, lijst van cd's/dvd's, ...

PDFLib (downloadbaar op pdflib.com) is vereist!

Greetz,
GDX^ (wimmarien)

Code:
  1. <?php
  2. class mipdf {
  3. public function __construct () {
  4. $this->pdfh = pdf_new();
  5. }
  6.  
  7. public function setformat ($format="A4") {
  8. $format = $this->formats("A4");
  9. pdf_begin_page($this->pdfh, $format[0], $format[1]);
  10. }
  11.  
  12. public function settextcolor ($r=0,$g=0,$b=0) {
  13. pdf_setcolor($this->pdfh, "stroke", "rgb", $r, $g, $b);
  14. }
  15.  
  16. public function openfile ($file) {
  17. pdf_open_file($this->pdfh, $file);
  18. }
  19.  
  20. public function setinfo ($title, $contents) {
  21. pdf_set_info($this->pdfh, $title, $contents);
  22. }
  23.  
  24. public function underline ($action=true) {
  25. pdf_set_parameter($this->pdfh, "underline", $action);
  26. }
  27.  
  28. public function overline ($action = true) {
  29. pdf_set_parameter ($this->pdfh, "overline", $action);
  30. }
  31.  
  32. public function strikeout ($action=true) {
  33. pdf_set_parameter ($this->pdfh, "strikeout", $action);
  34. }
  35.  
  36. public function line ($x,$y,$x2,$y2) {
  37. pdf_moveto($this->pdfh, $x, $y);
  38. pdf_lineto($this->pdfh, $x2, $y2);
  39. pdf_stroke($this->pdfh);
  40. }
  41.  
  42. public function add_img_gif ($file, $x, $y) {
  43. $this->add_img("gif", $file, $x, $y);
  44. }
  45.  
  46. public function add_img_jpg ($file, $x, $y) {
  47. $this->add_img("jpg", $file, $x, $y);
  48. }
  49.  
  50. public function add_img_png ($file, $x, $y) {
  51. $this->add_img("png", $file, $x, $y);
  52. }
  53.  
  54. public function add_img_tiff ($file, $x, $y) {
  55. $this->add_img("tiff", $file, $x, $y);
  56. }
  57.  
  58. private function add_img ($type, $file, $x, $y) {
  59. $img = pdf_open_image_file($this->pdfh, $type, $file);
  60. pdf_place_image($this->pdfh, $img, $x, $y, 1);
  61. }
  62.  
  63. public function setfont ($font, $size, $path) {
  64. $this->font = $font;
  65. $this->size = $size;
  66. $this->path = $path;
  67.  
  68. }
  69.  
  70. public function addTxt ($x, $y, $txt) {
  71. pdf_show_xy($this->pdfh, $txt, $x, $y);
  72. }
  73.  
  74. public function add_txt_boxed ($x, $y, $txt, $position) {
  75. pdf_show_boxed ($this->pdfh, $txt, $x, $y, 0, 0, $position);
  76. }
  77.  
  78. public function printToPage () {
  79. pdf_end_page($this->pdfh);
  80. pdf_close($this->pdfh);
  81. }
  82.  
  83. private function formats ($format = false) {
  84. $formats = array();
  85. $formats['A0'] = array(2380,3368);
  86. $formats['A1'] = array(1684,2380);
  87. $formats['A2'] = array(1190,1684);
  88. $formats['A3'] = array(842,1190);
  89. $formats['A4'] = array(595,842);
  90. $formats['A5'] = array(421,595);
  91. $formats['A6'] = array(297,421);
  92. $formats['B5'] = array(501,709);
  93. $formats['letter'] = array(612,792);
  94. $formats['legal'] = array(612,1008);
  95. $formats['ledger'] = array(1224,792);
  96. $formats['CD Front'] = array(337.33,337.33);
  97. $formats['CD Inlay + Sides'] = array(425.21,331.66);
  98. $formats['CD Inlay without Sides'] = array(389.49,331.66);
  99. $formats['11" x 17"'] = array(792,1224);
  100.  
  101. if(isset($format))
  102. return $formats[$format];
  103. else
  104. return $formats;
  105. }
  106. }
  107. ?>


Een voorbeeld om te gebruiken:
  1. <?php
  2. include ("mipdf.class.php");
  3. $pdf = new mipdf();
  4.  
  5. $pdf->setformat("A4");
  6. $pdf->settextcolor(0,0,0);
  7. $pdf->setInfo("Creator", "GDX^");
  8. $pdf->setInfo("Subject", "Pure test!");
  9.  
  10. $pdf->underline(true);
  11. $pdf->addTxt(100, 100, "Onderlijnd");
  12. $pdf->underline(false);
  13.  
  14. $pdf->line(10,50,50,10);
  15.  
  16. $pdf->printToPage();
  17. ?>


// OUTPUT:
Onderlijnd

(en een lijn natuurlijk)Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (7)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.063s