"Fossies" - the Fresh Open Source Software Archive

Member "PDFlib-Lite-7.0.5p3/bind/pdflib/php/starter_textline.php" (6 Jun 2012, 7348 Bytes) of package /linux/misc/old/PDFlib-Lite-7.0.5p3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "starter_textline.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 # $Id: starter_textline.php,v 1.1.2.1 2007/12/29 23:26:05 rjs Exp $
    3 # Starter text line:
    4 # Demonstrate various options for placing a text line
    5 #
    6 # Place a text line with different font sizes.
    7 # Output overlined, stroke out, and underlined text.
    8 # Output text and define character spacing, work spacing, or horizontal
    9 # scaling.
   10 # Output text with a defined fill color. Output text including its outlines
   11 # with a defined stroke color.
   12 # Place text into a box at various positions. Place text completely into a box
   13 # with automatic scaling if required.
   14 #
   15 # Required software: PDFlib Lite/PDFlib/PDFlib+PDI/PPS 7
   16 # Required data: none
   17 
   18 # This is where the data files are. Adjust as necessary.
   19 $searchpath = "../data";
   20 $title = "Starter Text Line";
   21 
   22 # create a new PDFlib object
   23 $p = PDF_new();
   24 
   25 $x = 10;
   26 $xt = 280;
   27 $y = 800;
   28 $yoff = 50;
   29 $textline = "Giant Wing Paper Plane";
   30 
   31     PDF_set_parameter($p, "SearchPath", $searchpath);
   32 
   33     # This means we must check return values of load_font() etc.
   34     PDF_set_parameter($p, "errorpolicy", "return");
   35 
   36     # Set an output path according to the name of the topic
   37     if (PDF_begin_document($p, "", "") == 0) {
   38     die("Error: " .  PDF_get_errmsg($p));
   39     }
   40 
   41     PDF_set_info($p, "Creator", "PDFlib Cookbook");
   42     $buf = $title . '  $Revision: 1.1.2.1 $';
   43     PDF_set_info($p, "Title", $buf);
   44 
   45     # Start Page
   46     PDF_begin_page_ext($p, 0, 0, "width=a4.width height=a4.height");
   47 
   48     # For PDFlib Lite: change "unicode" to "winansi"
   49     $font = PDF_load_font($p, "Helvetica", "winansi", "");
   50 
   51     if ($font == 0) {
   52     die("Error: " .  PDF_get_errmsg($p));
   53     }
   54 
   55     # Set the font with a font size of 14
   56     PDF_setfont($p, $font, 14);
   57 
   58 
   59     # Place the text line without any options applied
   60     PDF_fit_textline($p, $textline, $x, $y, "");
   61 
   62     # Output descriptive text
   63     PDF_fit_textline($p, "fit_textline() without any options", $xt, $y,
   64     "fontsize=12");
   65 
   66 
   67     # Place the text with a different font size
   68     $optlist = "fontsize=22";
   69     
   70     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist); # sample text
   71     PDF_fit_textline($p, $optlist, $xt, $y, "fontsize=12"); # description
   72     
   73     
   74     # Place stroke out text
   75     $optlist = "strikeout";
   76     
   77     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist); # sample text
   78     PDF_fit_textline($p, $optlist, $xt, $y, "fontsize=12"); # description
   79     
   80     
   81     # Place underlined text
   82     $optlist = "underline underlinewidth=7% underlineposition=-20%";
   83     
   84     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist); # sample text
   85     PDF_fit_textline($p, $optlist, $xt, $y, "fontsize=12"); # description
   86     
   87     
   88     # Place overlined text
   89     $optlist = "overline";
   90     
   91     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist); # sample text
   92     PDF_fit_textline($p, $optlist, $xt, $y, "fontsize=12"); # description
   93     
   94     
   95     # Place the text with a horizontal scaling of 150%
   96     $optlist = "horizscaling=150%";
   97     
   98     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist); # sample text
   99     PDF_fit_textline($p, $optlist, $xt, $y, "fontsize=12"); # description
  100     
  101     
  102     # Place the text with a character spacing of 30% of the font size
  103     $optlist = "charspacing=30%";
  104     
  105     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist); # sample text
  106     PDF_fit_textline($p, $optlist, $xt, $y, "fontsize=12"); # description
  107     
  108     
  109     # Place the text with a word spacing of 50% of the font size
  110     $optlist = "wordspacing=50%";
  111     
  112     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist); # sample text
  113     PDF_fit_textline($p, $optlist, $xt, $y, "fontsize=12"); # description
  114     
  115     
  116     # Place the text with a different fill color
  117     $optlist = "fillcolor={rgb 0.5 0.2 0.5}";
  118     
  119     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist);
  120     PDF_fit_textline($p, $optlist, $xt, $y, "fontsize=12");
  121     
  122     
  123     # Place the text including its outlines using a text rendering mode of
  124     # 2 for "filling and stroking text" and different fill and stroke
  125     # colors
  126     
  127     $optlist = 
  128     "fontsize=22 fillcolor={rgb 0.6 0.3 0.6} strokecolor={gray 0} " .
  129     "strokewidth=0.4 textrendering=2";
  130     
  131     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist);
  132     
  133     # Output descriptive text
  134     PDF_fit_textline($p, "fillcolor={rgb 0.6 0.3 0.6} strokecolor={gray 0} ",
  135     $xt, $y+10, "fontsize=12");
  136     PDF_fit_textline($p, "strokewidth=0.4 textrendering=2 fontsize=22",
  137     $xt, $y-5, "fontsize=12");
  138     
  139     
  140     # Place the text with its outlines using a text rendering mode of
  141     # 1 for "stroking text" and a stroke color of black
  142     
  143     $optlist =
  144     "fontsize=22 strokecolor={gray 0} strokewidth=0.4 textrendering=1";
  145     
  146     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist);
  147     
  148     # Output descriptive text
  149     PDF_fit_textline($p, "strokecolor={gray 0} strokewidth=0.4", $xt, $y+10,
  150     "fontsize=12");
  151     PDF_fit_textline($p, "textrendering=1 fontsize=22", $xt, $y-=5,
  152     "fontsize=12");
  153     
  154     
  155     # Place the text in a box with default positioning and fitting
  156     $optlist = "boxsize={200 20} showborder";
  157     
  158     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist);   # sample text
  159     PDF_fit_textline($p, $optlist, $xt, $y+3, "fontsize=12"); # description
  160     
  161     
  162     # Place the text in a box on the top right
  163     $optlist = "boxsize={200 20} position={top right} showborder";
  164     
  165     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist);   # sample text
  166     PDF_fit_textline($p, $optlist, $xt, $y+3, "fontsize=12"); # description
  167     
  168     
  169     # Use "fitmethod=clip" to place the text in a box not large enough to 
  170     # show the complete text. The text will be clipped.
  171     
  172     $optlist = "boxsize={130 20} fitmethod=clip showborder";
  173     
  174     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist);   # sample text
  175     PDF_fit_textline($p, $optlist, $xt, $y+3, "fontsize=12"); # description
  176     
  177     
  178     # Fit the text into the box automatically with "fitmethod=auto".
  179     # In this case, if the text doesn't fit into the box a distortion
  180     # factor is calculated which makes the text fit into the box. If this 
  181     # factor is larger than the "shrinklimit" option the text will
  182     # be distorted by that factor. Otherwise, the font size will be
  183     # be decreased until until the text fits into the box.
  184     
  185         
  186     # Use "fitmethod=auto" to place the text in a box not large enough to 
  187     # show the complete text. The text will be distorted.
  188     
  189     $optlist = "boxsize={130 20} fitmethod=auto showborder";
  190     
  191     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist);   # sample text
  192     PDF_fit_textline($p, $optlist, $xt, $y+3, "fontsize=12"); # description
  193  
  194     
  195     # Use "fitmethod=auto" to place the text in a box too small to show the
  196     # complete text. The font size will be reduced until the text fits into
  197     # the box.
  198     
  199     $optlist = "boxsize={100 20} fitmethod=auto showborder";
  200     
  201     PDF_fit_textline($p, $textline, $x, $y-=$yoff, $optlist);   # sample text
  202     PDF_fit_textline($p, $optlist, $xt, $y+3, "fontsize=12"); # description
  203 
  204     PDF_end_page_ext($p, "");
  205 
  206     PDF_end_document($p, "");
  207 
  208 $buf = PDF_get_buffer($p);
  209 $len = strlen($buf);
  210 
  211 header("Content-type: application/pdf");
  212 header("Content-Length: $len");
  213 header("Content-Disposition: inline; filename=hello.pdf");
  214 print $buf;
  215 
  216 ?>