"Fossies" - the Fresh Open Source Software Archive

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

    1 /* $Id: hellodl.c,v 1.10 2004/04/16 20:01:35 tm Exp $
    2  *
    3  * PDFlib client: hello example in C with dynamic DLL loading
    4  */
    5 
    6 #include <stdio.h>
    7 #include <stdlib.h>
    8 
    9 #include "pdflibdl.h"
   10 
   11 int
   12 main(void)
   13 {
   14     PDF *p;
   15     int font;
   16     PDFlib_api *PDFlib;
   17 
   18     /* load the PDFlib dynamic library and create a new PDFlib object*/
   19     if ((PDFlib = PDF_new_dl(&p)) == (PDFlib_api *) NULL)
   20     {
   21         printf("Couldn't create PDFlib object (DLL not found?)\n");
   22         return(2);
   23     }
   24 
   25     PDF_TRY_DL(PDFlib, p) {
   26     if (PDFlib->PDF_begin_document(p, "hellodl.pdf", 0, "") == -1) {
   27         printf("Error: %s\n", PDFlib->PDF_get_errmsg(p));
   28         return(2);
   29     }
   30 
   31     /* This line is required to avoid problems on Japanese systems */
   32     PDFlib->PDF_set_parameter(p, "hypertextencoding", "host");
   33 
   34     PDFlib->PDF_set_info(p, "Creator", "hello.c");
   35     PDFlib->PDF_set_info(p, "Author", "Thomas Merz");
   36     PDFlib->PDF_set_info(p, "Title", "Hello, world (C DLL)!");
   37 
   38     PDFlib->PDF_begin_page_ext(p, a4_width, a4_height, "");
   39 
   40     /* Change "host" encoding to "winansi" or whatever you need! */
   41     font = PDFlib->PDF_load_font(p, "Helvetica-Bold", 0, "host", "");
   42 
   43     PDFlib->PDF_setfont(p, font, 24);
   44     PDFlib->PDF_set_text_pos(p, 50, 700);
   45     PDFlib->PDF_show(p, "Hello, world!");
   46     PDFlib->PDF_continue_text(p, "(says C DLL)");
   47     PDFlib->PDF_end_page_ext(p, "");
   48 
   49     PDFlib->PDF_end_document(p, "");
   50     }
   51 
   52     PDF_CATCH_DL(PDFlib, p) {
   53         printf("PDFlib exception occurred in hellodl sample:\n");
   54         printf("[%d] %s: %s\n",
   55     PDFlib->PDF_get_errnum(p), PDFlib->PDF_get_apiname(p),
   56     PDFlib->PDF_get_errmsg(p));
   57     PDF_delete_dl(PDFlib, p);
   58         return(2);
   59     }
   60 
   61     /* delete the PDFlib object and unload the library */
   62     PDF_delete_dl(PDFlib, p);
   63 
   64     return 0;
   65 }