"Fossies" - the Fresh Open Source Software Archive

Member "PDFlib-Lite-7.0.5p3/bind/pdflib/php/starter_textflow.php" (6 Jun 2012, 3606 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_textflow.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 /* $Id: starter_textflow.php,v 1.6 2006/10/02 21:11:38 tm Exp $
    3  *
    4  * Textflow starter:
    5  * Create multi-column text output which may span multiple pages
    6  *
    7  * required software: PDFlib/PDFlib+PDI/PPS 7 or above
    8  * required data: none
    9  */
   10 
   11 $outfilename = "starter_textflow.pdf";
   12 $tf = 0;
   13 $llx1= 50; $lly1=50; $urx1=250; $ury1=800;
   14 $llx2=300; $lly2=50; $urx2=500; $ury2=800;
   15 
   16 /* Repeat the dummy text to produce more contents */
   17 $count = 50;
   18 
   19 $optlist1 = "fontname=Helvetica fontsize=10.5 encoding=unicode " .
   20     "fillcolor={gray 0} alignment=justify";
   21 $optlist2 = "fontname=Helvetica-Bold fontsize=14 encoding=unicode " .
   22     "fillcolor={rgb 1 0 0} charref";
   23 
   24 /* Dummy text for filling the columns. Soft hyphens are marked with
   25  * the character reference "&shy;" (character references are
   26  * enabled by the charref option).
   27  */
   28 $text= 
   29 "Lorem ipsum dolor sit amet, consectetur adi&shy;pi&shy;sicing elit, sed do eius&shy;mod tempor incidi&shy;dunt ut labore et dolore magna ali&shy;qua. Ut enim ad minim ve&shy;niam, quis nostrud exer&shy;citation ull&shy;amco la&shy;bo&shy;ris nisi ut ali&shy;quip ex ea commodo con&shy;sequat. Duis aute irure dolor in repre&shy;henderit in voluptate velit esse cillum dolore eu fugiat nulla pari&shy;atur. Excep&shy;teur sint occae&shy;cat cupi&shy;datat non proident, sunt in culpa qui officia dese&shy;runt mollit anim id est laborum. ";
   30 
   31 $p = PDF_new();
   32 
   33 # This means we must check return values of load_font() etc.
   34 PDF_set_parameter($p, "errorpolicy", "return");
   35 
   36 /* we use "utf8" as textformat, this allows to use unicode encoding */
   37 PDF_set_parameter($p, "textformat", "utf8");
   38 
   39 if (PDF_begin_document($p, $outfilename, "") == 0) {
   40     die("Error: " . PDF_get_errmsg($p));
   41 }
   42 
   43 PDF_set_info($p, "Creator", "PDFlib starter sample");
   44 PDF_set_info($p, "Title", "starter_textflow");
   45 
   46 /* Create some amount of dummy text and feed it to a Textflow
   47  * object with alternating options. 
   48  */
   49 for ($i=1; $i<=$count; $i++) {
   50     $num = $i . " ";
   51 
   52     $tf = PDF_add_textflow($p, $tf, $num, $optlist2);
   53     if ($tf == 0)
   54     die("Error: " . PDF_get_errmsg($p));
   55 
   56     $tf = PDF_add_textflow($p, $tf, $text, $optlist1);
   57     if ($tf == 0)
   58     die("Error: " . PDF_get_errmsg($p));
   59 }
   60 
   61 /* Loop until all of the text is placed; create new pages
   62  * as long as more text needs to be placed. Two columns will
   63  * be created on all pages.
   64  */
   65 do {
   66     /* Add "showborder to visualize the fitbox borders */
   67     $optlist = "verticalalign=justify linespreadlimit=120% ";
   68 
   69     PDF_begin_page_ext($p, 0, 0, "width=a4.width height=a4.height");
   70 
   71     /* Fill the first column */
   72     $result = PDF_fit_textflow($p, $tf, $llx1, $lly1, $urx1, $ury1, $optlist);
   73 
   74     /* Fill the second column if we have more text*/
   75     if ($result != "_stop") {
   76     $result = PDF_fit_textflow($p, $tf, 
   77             $llx2, $lly2, $urx2, $ury2, $optlist);
   78     }
   79 
   80     PDF_end_page_ext($p, "");
   81 
   82     /* "_boxfull" means we must continue because there is more text;
   83      * "_nextpage" is interpreted as "start new column"
   84      */
   85 } while ($result == "_boxfull" || $result == "_nextpage");
   86 
   87 /* Check for errors */
   88 if (!$result == "_stop") {
   89     /* "_boxempty" happens if the box is very small and doesn't
   90      * hold any text at all.
   91      */
   92     if ($result == "_boxempty") {
   93     die("Error: Textflow box too small");
   94     } else {
   95     /* Any other return value is a user exit caused by
   96      * the "return" option; this requires dedicated code to
   97      * deal with.
   98      */
   99     die("User return '" . $result . "' found in Textflow");
  100     }
  101 }
  102 
  103 PDF_delete_textflow($p, $tf);
  104 
  105 PDF_end_document($p, "");
  106 
  107 PDF_delete($p);
  108 
  109 print "$outfilename generated";
  110 ?>