PDFlib und GDlib kombinieren

gordonk

Erfahrenes Mitglied
Guten Morgen ;)

Ich möchte ein mit GDlib erstelltes image in ein PDF einbinden das mit PDFlib-lite erstellt wird.

Hier schonmal der Code:
pdftest.php
PHP:
<?php

    $searchpath = "/"; 
    
    $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", " the author ");
   $p->set_info("Title", " gd-image insert ");
   $p->begin_page_ext(595, 842, "");
   
    
    $image_create = "pdftest_create_barcode.php";

    $image = $p->load_image("auto", $image_create, "");
    if (!$image) {    die("Error: " . $p->get_errmsg());    }
    
    $p->fit_image($image, 50, 55, "");
    $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;
?>
pdftest_create_barcode.php
PHP:
<?php

	$fontfile = "./code128f";
	$text = "BARCODE!";
	
	$size = 48;
	
	$image_x = 250;
	$image_y = 75;

	$image_test_x = 50;
	$image_test_y = 65;
	
	$image  =  imagecreate($image_x, $image_y);

	$fill = ImageColorAllocate($image, 255, 255, 255);

	$barcode_color = ImageColorAllocate($image, 0, 0, 0);

	ImageTTFText($image, $size, 0, $image_test_x, $image_test_y, $barcode_color, $fontfile, $text);

	header("Content-Type: image/jpeg");
	ImageJPEG($image);
?>

Error: Unknown image type in file 'pdftest_create_barcode.php'
 
Habe die Lösung gefunden.
PHP:
//Set up a document (PHP5 standard.)
$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, ""); // This is letter.

if ($stream = fopen('http://xxhostnamexx.de/pdftest_create_barcode.php', 'r')) {
   $MyImage= stream_get_contents($stream, -1);
   fclose($stream);
}

//First, create a PDF Virtual File (PVF) out of our data...
$pvf_filename = "hallo123.jpg";
//and store the $MyImage data (picture data from above)
//    in it!
$p->create_pvf($pvf_filename,$MyImage, "");
//Load the image from the PVF into, er, uh, ram..., and, uh...
$image = $p->load_image("jpeg", $pvf_filename,"");
//Put it on the screen! :)
$p->fit_image($image, 100,500,"");
//Be cool and clean up after yourself...
$p->delete_pvf($pvf_filename);

//And... Render!
$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;
 
Zurück