"Fossies" - the Fresh Open Source Software Archive

Member "PDFlib-Lite-7.0.5p3/bind/pdflib/perl/starter_basic.pl" (6 Jun 2012, 2762 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) Perl 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_basic.pl" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/perl
    2 # $Id: starter_basic.pl,v 1.3.2.1 2008/12/25 13:28:41 rp Exp $
    3 #
    4 # Basic starter:
    5 # Create some simple text, vector graphics and image output
    6 #
    7 # required software: PDFlib Lite/PDFlib/PDFlib+PDI/PPS 7
    8 # required data: none
    9 #
   10 
   11 use pdflib_pl 7.0;
   12 
   13 # This is where the data files are. Adjust as necessary.
   14 $searchpath = "../data/";
   15 $imagefile = "nesrin.jpg";
   16 $outfilename = "starter_basic.pdf";
   17 
   18 $p = PDF_new();
   19 
   20 eval {
   21     # This means we must check return values of load_font() etc.
   22     PDF_set_parameter($p, "errorpolicy", "return");
   23 
   24     PDF_set_parameter($p, "SearchPath", $searchpath);
   25 
   26     # we use "utf8" as textformat, this allows to use unicode encoding
   27     PDF_set_parameter($p, "textformat", "utf8");
   28 
   29     if (PDF_begin_document($p, $outfilename, "") == -1) {
   30     die("Error: " . PDF_get_errmsg($p));
   31     }
   32 
   33     PDF_set_info($p, "Creator", "PDFlib starter sample");
   34     PDF_set_info($p, "Title", "starter_basic");
   35 
   36     # We load the $image before the first page, and use it
   37     # on all pages
   38 
   39     $image = PDF_load_image($p, "auto", $imagefile, "");
   40 
   41     if ($image == -1) {
   42     die("Error: " . PDF_get_errmsg($p));
   43     }
   44 
   45     # Page 1
   46     PDF_begin_page_ext($p, 595, 842, "");
   47 
   48     # For PDFlib Lite: change "unicode" to "winansi"
   49     $font = PDF_load_font($p, "Helvetica-Bold", "unicode", "");
   50     if ($font == -1) {
   51     die("Error: %s\n", PDF_get_errmsg($p));
   52     }
   53 
   54     PDF_setfont($p, $font, 24);
   55 
   56     PDF_set_text_pos($p, 50, 700);
   57     PDF_show($p, "Hello world!");
   58 
   59     PDF_fit_image($p, $image, 0.0, 0.0, "scale=0.25");
   60 
   61     PDF_end_page_ext($p, "");
   62 
   63     # Page 2
   64     PDF_begin_page_ext($p, 595, 842, "");
   65 
   66     # red rectangle
   67     PDF_setcolor($p, "fill", "rgb", 1.0, 0.0, 0.0, 0.0);
   68     PDF_rect($p, 200, 200, 250, 150);
   69     PDF_fill($p);
   70 
   71     # blue circle
   72     PDF_setcolor($p, "fill", "rgb", 0.0, 0.0, 1.0, 0.0);
   73     PDF_arc($p, 400, 600, 100, 0, 360);
   74     PDF_fill($p);
   75 
   76     # thick gray line
   77     PDF_setcolor($p, "stroke", "gray", 0.5, 0.0, 0.0, 0.0);
   78     PDF_setlinewidth($p, 10);
   79     PDF_moveto($p, 100, 500);
   80     PDF_lineto($p, 300, 700);
   81     PDF_stroke($p);
   82 
   83     # Using the same $image handle means the data will be copied
   84     # to the PDF only once, which saves space.
   85 
   86     PDF_fit_image($p, $image, 150.0, 25.0, "scale=0.25");
   87     PDF_end_page_ext($p, "");
   88 
   89     # Page 3
   90     PDF_begin_page_ext($p, 595, 842, "");
   91 
   92     # Fit the image to a box of predefined size (without distortion)
   93     $optlist = "boxsize={400 400} position={center} fitmethod=meet";
   94     PDF_fit_image($p, $image, 100, 200, $optlist);
   95 
   96     PDF_end_page_ext($p, "");
   97 
   98     PDF_close_image($p, $image);
   99     PDF_end_document($p, "");
  100     PDF_delete($p);
  101 };
  102 
  103 if ($@) {
  104     printf("starter_basic: PDFlib Exception occurred:\n");
  105     printf(" $@\n");
  106     exit;
  107 }