"Fossies" - the Fresh Open Source Software Archive

Member "PDFlib-Lite-7.0.5p3/bind/pdflib/c/hello.c" (6 Jun 2012, 1613 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) C and C++ 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 "hello.c" see the Fossies "Dox" file reference documentation.

    1 /* $Id: hello.c,v 1.39 2006/10/01 19:55:41 rjs Exp $
    2  *
    3  * PDFlib client: hello example in C
    4  */
    5 
    6 #include <stdio.h>
    7 #include <stdlib.h>
    8 
    9 #include "pdflib.h"
   10 
   11 int
   12 main(void)
   13 {
   14     PDF *p;
   15     int font;
   16 
   17     /* create a new PDFlib object */
   18     if ((p = PDF_new()) == (PDF *) 0)
   19     {
   20         printf("Couldn't create PDFlib object (out of memory)!\n");
   21         return(2);
   22     }
   23 
   24     PDF_TRY(p) {
   25     /* This means we must check return values of load_font() etc. */
   26     PDF_set_parameter(p, "errorpolicy", "return");
   27 
   28     if (PDF_begin_document(p, "hello.pdf", 0, "") == -1) {
   29         printf("Error: %s\n", PDF_get_errmsg(p));
   30         return(2);
   31     }
   32 
   33     /* This line is required to avoid problems on Japanese systems */
   34     PDF_set_parameter(p, "hypertextencoding", "host");
   35 
   36     PDF_set_info(p, "Creator", "hello.c");
   37     PDF_set_info(p, "Author", "Thomas Merz");
   38     PDF_set_info(p, "Title", "Hello, world (C)!");
   39 
   40     PDF_begin_page_ext(p, a4_width, a4_height, "");
   41 
   42     /* Change "host" encoding to "winansi" or whatever you need! */
   43     font = PDF_load_font(p, "Helvetica-Bold", 0, "host", "");
   44     if (font == -1) {
   45         printf("Error: %s\n", PDF_get_errmsg(p));
   46         PDF_delete(p);
   47         return(2);
   48     }
   49 
   50     PDF_setfont(p, font, 24);
   51     PDF_set_text_pos(p, 50, 700);
   52     PDF_show(p, "Hello, world!");
   53     PDF_continue_text(p, "(says C)");
   54     PDF_end_page_ext(p, "");
   55 
   56     PDF_end_document(p, "");
   57     }
   58 
   59     PDF_CATCH(p) {
   60         printf("PDFlib exception occurred in hello sample:\n");
   61         printf("[%d] %s: %s\n",
   62         PDF_get_errnum(p), PDF_get_apiname(p), PDF_get_errmsg(p));
   63         PDF_delete(p);
   64         return(2);
   65     }
   66 
   67     PDF_delete(p);
   68 
   69     return 0;
   70 }