set_option("searchpath={" . $searchpath . "}"); /* This means we must check return values of load_font() etc. */ $p->set_option("errorpolicy=return"); $p->set_option("stringformat=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); $font = $p->load_font("Helvetica", "unicode", ""); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Create some pages while counting the total number of pages. * Suspend the creation of each page to be able to add the total number * of pages later. Resume the page creation to add the total number of * pages in a footer like "Page X of Y". * * Create page 1 */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); $pagecount++; $p->setcolor("fill", "rgb", 0, 0.4, 0.4, 0); $p->setfont($font, 12); $p->show_xy("Page 1", $x, $y); /* Suspend page 1 to resume it later */ $p->suspend_page(""); /* Create page 2 */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); $pagecount++; $p->setcolor("fill", "rgb", 0, 0.4, 0.4, 0); $p->setfont($font, 12); $p->show_xy("Page 2", $x, $y); /* Suspend page 2 to resume it later */ $p->suspend_page(""); /* Create page 3 */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); $pagecount++; $p->setcolor("fill", "rgb", 0, 0.4, 0.4, 0); $p->setfont($font, 12); $p->show_xy("Page 3", $x, $y); /* Suspend page 3 to resume it later */ $p->suspend_page(""); /* Revisit page 1 */ $p->resume_page("pagenumber 1"); /* Add the total number of pages */ $p->show(" of " . $pagecount); $p->end_page_ext(""); /* Revisit page 2 */ $p->resume_page("pagenumber 2"); /* Add the total number of pages */ $p->show(" of " . $pagecount); $p->end_page_ext(""); /* Revisit page 3 */ $p->resume_page("pagenumber 3"); /* Add the total number of pages */ $p->show(" of " . $pagecount); $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=page_x_of_y.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred:\n". "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Exception $e) { echo($e->getMessage()); exit(1); } $p = 0; ?>