PDFlib Cookbook

cookbook

interchange/control_nexpress_trays

For NexPress digital color printing machines, create special annotations to control the input tray.

Download PHP Code  Switch to Java Code  Show Output 

<?php
/*
 * Control NexPress trays:
 * For NexPress digital color printing machines, create some special kind of
 * annotations to control the input tray.
 * 
 * Use the "custom" option of create_annotation() to create a "Stamp" annotation
 * with NexPress-specific custom extensions.   
 * The "P" in "PDF" means "Portable", which excludes the use of device-specific
 * parameters such as tray control. This technique is not really in the spirit
 * of portable PDF documents, but NexPress digital printing machines expect it
 * this way nevertheless.
 * 
 * The annotation is created outside the page area to ensure that it won't
 * be visible on the printed page.
 * 
 * Required software: PDFlib/PDFlib+PDI/PPS 9
 * Required data: none
 */

/* This is where the data files are. Adjust as necessary. */
$searchpath = dirname(__FILE__,3)."/input";
$outfile = "";
$title = "Control NexPress trays";

$font;

try {
    $p = new PDFlib();

    $p->set_option("searchpath={" . $searchpath . "}");

    /* This means we must check return values of load_font() etc. */
    $p->set_option("errorpolicy=return");
    
    /* Start the document */
    if ($p->begin_document($outfile, "") == 0)
        throw new Exception("Error: " . $p->get_errmsg());
    
    /* Set document info entries */
    $p->set_info("Creator", "PDFlib Cookbook");
    $p->set_info("Title", $title );
    
    /* Load font */
    $font = $p->load_font("NotoSerif-Regular", "unicode", "");
    if ($font == 0)
        throw new Exception("Error: " . $p->get_errmsg());
            
    /* Create a template for visualizing the Stamp annotation */
    $tmpl = $p->begin_template_ext(100, 50, "");

    $path = $p->add_path_point(0, 50, 25, "rect",
        "round=15 width=94 height=44");

    $p->draw_path($path, 0, 0, "fill fillcolor=lightblue stroke " .
        "strokecolor=blue linewidth=3");

    $p->fit_textline("Cover", 10, 5,
        "font=" . $font . " fontsize=24 position=center " .
        "fitmethod=meet boxsize={80 40} fillcolor=black");

    $p->end_template_ext(0, 0);

    /* Start page */
    $p->begin_page_ext(0, 0, "width=a4.width height=a4.height");
    
    /* Set font */
    $p->setfont($font, 12);
    
    /* Output some descriptive text */
    $p->fit_textline("Use the \"custom\" option of create_annotation() to " .
         "create a \"Stamp\" annotation with", 20, 600, "");
    $p->fit_textline("NexPress-specific custom extensions in the document.",
        20, 580, "");
    
    /* Create a "Stamp" annotation with NexPress-specific custom 
     * extensions. 
     * Some names which can be used in the "Name" key for tray selection:
     * SubstrateTypeCover, SubstrateTypeInsert,
     * SubstrateTypeInsert1 ... SubstrateTypeInsert9.
     * More details are available in the printer-specific documentation
     * provided by Kodak.
     */
    $optlist =
        "custom={{key=Open type=boolean value=false} " .
        "{key=Name type=name value=SubstrateTypeCover} " .
        "{key=Subj type=string value={Cover}}} " .
        "contents={Stamp Annotation for tray selection} "  .
                        
        // Provide a template as visualization of the annotation
        "template={normal=" . $tmpl . "}";


    $p->create_annotation(620, 450, 720, 500, "Stamp", $optlist);
    
    $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=control_nexpress_trays.pdf");
    print $buf;

}
catch (PDFlibException $e) {
    echo("PDFlib exception occurred in control_nexpress_trays sample:\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;
?>