set_option("errorpolicy=return"); $p->set_option("searchpath={" . $searchpath . "}"); 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("NotoSerif-Regular", "winansi", "simplefont nosubsetting"); if ($font == 0) throw new Exception("Error: " . $p->get_errmsg()); /* Start page */ $p->begin_page_ext(0, 0, " width=a4.width height=a4.height"); /* For a correct formatting of the date, define a keystroke and a * formatting action for the date to be checked for compliance to the * format "mmm dd yyyy". */ $keystroke_action = $p->create_action("JavaScript", "script={AFDate_KeystrokeEx('mmm dd yyyy'); }"); /* Create a form field of type "textfield" called "date" with the * JavaScript action supplied in the "action" option */ $optlist = "backgroundcolor={rgb 0.95 0.95 1} bordercolor={gray 0} " . "currentvalue={Nov 15 2021} maxchar=11 scrollable=false " . "tooltip={Enter a date} font=" . $font. " fontsize=24" . " action={keystroke=" . $keystroke_action . "}"; $p->create_field($llx, $lly, $llx + $width, $lly + $height, "date", "textfield", $optlist); $lly-=40; $p->fit_textline("Change the date.", $llx, $lly, "fontname=NotoSerif-Regular fontsize=12"); $p->fit_textline("After pressing \"Enter\", the date is checked to be " . "correctly formatted as \"mmm dd yyy\".", $llx, $lly-=20, "fontname=NotoSerif-Regular fontsize=12"); $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=form_textfield_input_check.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; ?>