set_option("searchpath={" . $searchpath . "}"); /* This means we must check return values of load_font() etc. */ $p->set_option("errorpolicy=return"); /* Set an output path according to the name of the topic */ if ($p->begin_document($outfile, "") == 0) throw new Exception("Error: " . $p->get_errmsg()); $p->set_info("Creator", "PDFlib Cookbook"); $p->set_info("Title", $title ); /* Page 1 */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); $font = $p->load_font("NotoSerif-Bold", "unicode", ""); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Place a text line with an orientation of west, east, or south */ $p->setfont($font, 24); $p->fit_textline("The famous rocket looper", 100, 500, "orientate=west"); $p->setfont($font, 20); $p->fit_textline("The famous rocket looper", 200, 500, "orientate=east"); $p->setfont($font, 16); $p->fit_textline("The famous rocket looper", 300, 500, "orientate=south"); /* Rotate a text line by 30 degrees */ $p->setfont($font, 16); $p->fit_textline("The famous rocket looper", 50, 350, "rotate=30"); /* Place a Textflow with a rotation of 30 degrees */ $tf = $p->add_textflow($tf, $textflow, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf, 250, 50, 400, 400, "rotate=30"); if ($result != "_stop") { /* Check for errors or more text to be placed */ } $p->delete_textflow($tf); $p->end_page_ext(""); /* Page 2 */ $p->begin_page_ext(0, 0, "width=a4.width height=a4.height"); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Set the stroke color to red */ $p->setcolor("stroke", "rgb", 1, 0, 0, 0); /* Place a Textflow with a rotation of 30 degrees. Visualize the fitbox * of the Textflow with the "showborder" option */ $tf = 0; $tf = $p->add_textflow($tf, $textflow, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf, 150, 450, 400, 650, "showborder rotate=30"); if ($result != "_stop") { /* Check for errors or more text to be placed */ } $p->delete_textflow($tf); $p->fit_textline("rotate=30", 300, 500, "font=" . $font . " fontsize=14"); /* Now, place the Textflow with a rotation of 30 degrees and orientate * it to the west */ $tf = 0; $tf = $p->add_textflow($tf, $textflow, $optlist); if ($tf == 0) throw new Exception("Error: " . $p->get_errmsg()); $result = $p->fit_textflow($tf, 150, 100, 400, 300, "showborder rotate=30 orientate west"); if ($result != "_stop") { /* Check for errors or more text to be placed */ } $p->delete_textflow($tf); $p->fit_textline("rotate=30 orientate=west", 300, 150, "font=" . $font . " fontsize=14"); $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=rotated_text.pdf"); print $buf; } catch (PDFlibException $e) { echo("PDFlib exception occurred:\n". "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " . $e->get_errmsg() . "\n"); exit(1); } catch (Throwable $e) { echo("PHP exception occurred: " . $e->getMessage() . "\n"); exit(1); } $p = 0; ?>