set_option("searchpath={" . $searchpath . "}"); /* This means we must check return values of load_font() etc. */ $p->set_option("errorpolicy=return"); /* all strings are expected as utf8 */ if ($p->begin_document($outfile, "") == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title); foreach ($testcases as $testcase) { $textopt = "fontname=NotoSerif-Regular fontsize=12"; $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); /* Output option list and description */ if ($testcase[0] == "") $p->fit_textline("No image option: " . $testcase[1], $x, $y2, $textopt); else $p->fit_textline("Image option '" . $testcase[0] . "': " . $testcase[1], $x, $y2, $textopt); /* Load the image with option */ $image = $p->load_image("auto", $imagefile, $testcase[0]); if ($image == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->fit_image($image, $x, $y1, "boxsize={540 800} fitmethod=meet"); $p->close_image($image); $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=image_color_manipulation.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred in image_color_manipulation sample:\n" . "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Throwable $e) { echo($e); exit(1); } $p = 0;