|
|
PDF_load_image (PECL) PDF_load_image -- Open image file Описаниеint PDF_load_image ( resource pdfdoc, string imagetype, string filename, string optlist )
Opens a disk-based or virtual image file subject to various options.
klassen dot tony at gmail dot com
12-Mar-2007 07:27
I've had a difficult time trying to load images to the pdf with pdflib, and tried many examples. I came across this one and it actually works for me in IE and Firefox. I hope this can be of some help to someone.
<?php
$searchpath = "path/to/image/dir";
$p = new PDFlib();
$p->set_parameter("errorpolicy", "return"); $p->set_parameter("hypertextencoding", "winansi"); $p->set_parameter("SearchPath", $searchpath); if ($p->begin_document("", "") == 0) {
die("Error: " . $p->get_errmsg());
}
$p->set_info("Creator", " the creator");
$p->set_info("Author", " you ");
$p->set_info("Title", " imageInsert ");
$p->begin_page_ext(612, 792, ""); $certLogo = "stamp.jpg"; $image = $p->load_image("auto", $certLogo, "");
if (!$image) { die("Error: " . $p->get_errmsg()); }
$p->fit_image($image, 390,575, ""); $p->close_image($image); $p->end_page_ext("");
$p->end_document("");
$data = $p->get_buffer();
$len = strlen($data);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=hello.pdf");
print $data;
$p = 0;
?>
Mike Zmuda
11-May-2006 06:40
This program takes a picture from a dynamic image selector (ie: banner ad selector software, or whatever,) and inserts it into your pdf.
You can use something like this to insert coupons on PDFs (such as register receipts, bills, receipts, etc...) just like they do at the supermarket checkout!
<?php
$p = new PDFlib();
if ($p->begin_document("", "") == 0) {
die("Error: " . $p->get_errmsg());
}
$p->set_info("Creator", "Homer");
$p->set_info("Author", "Lisa");
$p->set_info("Title", "Simpsons Image");
$p->begin_page_ext(612, 792, ""); if ($stream = fopen('http://site.com/getimg.php?pic=18', 'r')) {
$MyImage= stream_get_contents($stream, -1);
fclose($stream);
}
$pvf_filename = "/pvf/image/image1.jpg";
$p->create_pvf($pvf_filename,$MyImage, "");
$image = $p->load_image("jpeg", $pvf_filename,"");
$p->fit_image($image, 100,500,"boxsize {100 100} position 50 fitmethod meet");
$p->delete_pvf($pvf_filename);
$p->end_page_ext("");
$p->end_document("");
$buf = $p->get_buffer();
$len = strlen($buf);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=urlImageTest.pdf");
print $buf;
?>
Nicolas Padfield nicolasatpadfielddotdk
10-Mar-2006 04:34
Example use of PDF_load_image():
<?php
$pdf = PDF_new();
PDF_open_file($pdf,'');
PDF_begin_page($pdf,595,842);
$image = PDF_load_image($pdf,"png","myimage.png","");
PDF_place_image($pdf,$image,64,26,.24);
?>
If you want something that is more free for commercial use, open source and does not require compiling, you could look at for example http://www.fpdf.org in stead of PDFlib
|