MiPDF (PDF Classe)
Auteur: Wim - 04 januari 2006 - 17:51 - Gekeurd door: Ontani - Hits: 4171 - 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: |
<?php
class mipdf {
public function __construct () {
$this->pdfh = pdf_new();
}
public function setformat ($format="A4") {
$format = $this->formats("A4");
pdf_begin_page($this->pdfh, $format[0], $format[1]);
}
public function settextcolor ($r=0,$g=0,$b=0) {
pdf_setcolor($this->pdfh, "stroke", "rgb", $r, $g, $b);
}
public function openfile ($file) {
pdf_open_file($this->pdfh, $file);
}
public function setinfo ($title, $contents) {
pdf_set_info($this->pdfh, $title, $contents);
}
public function underline ($action=true) {
pdf_set_parameter($this->pdfh, "underline", $action);
}
public function overline ($action = true) {
pdf_set_parameter ($this->pdfh, "overline", $action);
}
public function strikeout ($action=true) {
pdf_set_parameter ($this->pdfh, "strikeout", $action);
}
public function line ($x,$y,$x2,$y2) {
pdf_moveto($this->pdfh, $x, $y);
pdf_lineto($this->pdfh, $x2, $y2);
pdf_stroke($this->pdfh);
}
public function add_img_gif ($file, $x, $y) {
$this->add_img("gif", $file, $x, $y);
}
public function add_img_jpg ($file, $x, $y) {
$this->add_img("jpg", $file, $x, $y);
}
public function add_img_png ($file, $x, $y) {
$this->add_img("png", $file, $x, $y);
}
public function add_img_tiff ($file, $x, $y) {
$this->add_img("tiff", $file, $x, $y);
}
private function add_img ($type, $file, $x, $y) {
$img = pdf_open_image_file($this->pdfh, $type, $file);
pdf_place_image($this->pdfh, $img, $x, $y, 1);
}
public function setfont ($font, $size, $path) {
$this->font = $font;
$this->size = $size;
$this->path = $path;
}
public function addTxt ($x, $y, $txt) {
pdf_show_xy($this->pdfh, $txt, $x, $y);
}
public function add_txt_boxed ($x, $y, $txt, $position) {
pdf_show_boxed ($this->pdfh, $txt, $x, $y, 0, 0, $position);
}
public function printToPage () {
pdf_end_page($this->pdfh);
pdf_close($this->pdfh);
}
private function formats ($format = false) {
$formats = array();
$formats['A0'] = array(2380,3368);
$formats['A1'] = array(1684,2380);
$formats['A2'] = array(1190,1684);
$formats['A3'] = array(842,1190);
$formats['A4'] = array(595,842);
$formats['A5'] = array(421,595);
$formats['A6'] = array(297,421);
$formats['B5'] = array(501,709);
$formats['letter'] = array(612,792);
$formats['legal'] = array(612,1008);
$formats['ledger'] = array(1224,792);
$formats['CD Front'] = array(337.33,337.33);
$formats['CD Inlay + Sides'] = array(425.21,331.66);
$formats['CD Inlay without Sides'] = array(389.49,331.66);
$formats['11" x 17"'] = array(792,1224);
if(isset($format))
return $formats[$format];
else
return $formats;
}
}
?>
<?php class mipdf { public function __construct () { $this->pdfh = pdf_new(); } public function setformat ($format="A4") { $format = $this->formats("A4"); pdf_begin_page($this->pdfh, $format[0], $format[1]); } public function settextcolor ($r=0,$g=0,$b=0) { pdf_setcolor($this->pdfh, "stroke", "rgb", $r, $g, $b); } public function openfile ($file) { pdf_open_file($this->pdfh, $file); } public function setinfo ($title, $contents) { pdf_set_info($this->pdfh, $title, $contents); } public function underline ($action=true) { pdf_set_parameter($this->pdfh, "underline", $action); } public function overline ($action = true) { pdf_set_parameter ($this->pdfh, "overline", $action); } public function strikeout ($action=true) { pdf_set_parameter ($this->pdfh, "strikeout", $action); } public function line ($x,$y,$x2,$y2) { pdf_moveto($this->pdfh, $x, $y); pdf_lineto($this->pdfh, $x2, $y2); pdf_stroke($this->pdfh); } public function add_img_gif ($file, $x, $y) { $this->add_img("gif", $file, $x, $y); } public function add_img_jpg ($file, $x, $y) { $this->add_img("jpg", $file, $x, $y); } public function add_img_png ($file, $x, $y) { $this->add_img("png", $file, $x, $y); } public function add_img_tiff ($file, $x, $y) { $this->add_img("tiff", $file, $x, $y); } private function add_img ($type, $file, $x, $y) { $img = pdf_open_image_file($this->pdfh, $type, $file); pdf_place_image($this->pdfh, $img, $x, $y, 1); } public function setfont ($font, $size, $path) { $this->font = $font; $this->size = $size; $this->path = $path; } public function addTxt ($x, $y, $txt) { pdf_show_xy($this->pdfh, $txt, $x, $y); } public function add_txt_boxed ($x, $y, $txt, $position) { pdf_show_boxed ($this->pdfh, $txt, $x, $y, 0, 0, $position); } public function printToPage () { pdf_end_page($this->pdfh); pdf_close($this->pdfh); } private function formats ($format = false) { $formats['A0'] = array(2380,3368); $formats['A1'] = array(1684,2380); $formats['A2'] = array(1190,1684); $formats['A3'] = array(842,1190); $formats['A4'] = array(595,842); $formats['A5'] = array(421,595); $formats['A6'] = array(297,421); $formats['B5'] = array(501,709); $formats['letter'] = array(612,792); $formats['legal'] = array(612,1008); $formats['ledger'] = array(1224,792); $formats['CD Front'] = array(337.33,337.33); $formats['CD Inlay + Sides'] = array(425.21,331.66); $formats['CD Inlay without Sides'] = array(389.49,331.66); $formats['11" x 17"'] = array(792,1224); return $formats[$format]; else return $formats; } } ?>
Een voorbeeld om te gebruiken:
<?php
include ("mipdf.class.php");
$pdf = new mipdf();
$pdf->setformat("A4");
$pdf->settextcolor(0,0,0);
$pdf->setInfo("Creator", "GDX^");
$pdf->setInfo("Subject", "Pure test!");
$pdf->underline(true);
$pdf->addTxt(100, 100, "Onderlijnd");
$pdf->underline(false);
$pdf->line(10,50,50,10);
$pdf->printToPage();
?>
<?php include ("mipdf.class.php"); $pdf = new mipdf(); $pdf->setformat("A4"); $pdf->settextcolor(0,0,0); $pdf->setInfo("Creator", "GDX^"); $pdf->setInfo("Subject", "Pure test!"); $pdf->underline(true); $pdf->addTxt(100, 100, "Onderlijnd"); $pdf->underline(false); $pdf->line(10,50,50,10); $pdf->printToPage(); ?>
// OUTPUT:
Onderlijnd
(en een lijn natuurlijk) Download code (.txt)
|
|
Stemmen |
Niet ingelogd. |
|