"Fossies" - the Fresh Open Source Software Archive

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

    1 // $Id: quickreference.cpp,v 1.29 2006/10/01 19:18:32 rjs Exp $
    2 //
    3 // PDFlib+PDI client: mini imposition demo
    4 //
    5 
    6 #include <iostream>
    7 
    8 #include "pdflib.hpp"
    9 
   10 using namespace std;
   11 
   12 int
   13 main(void)
   14 {
   15     try {
   16     PDFlib *p;
   17     int manual, page;
   18     int font, row, col;
   19     const int maxrow = 2;
   20     const int maxcol = 2;
   21     char optlist[128];
   22     int endpage;
   23     const double width = 500, height = 770;
   24     int pageno;
   25     const string infile = "reference.pdf";
   26     /* This is where font/image/PDF input files live. Adjust as necessary.*/
   27     const string searchpath = "../data";
   28 
   29     p = new PDFlib();
   30 
   31     //  This means we must check return values of load_font() etc.
   32     p->set_parameter("errorpolicy", "return");
   33 
   34     p->set_parameter("SearchPath", searchpath);
   35 
   36     // This line is required to avoid problems on Japanese systems
   37     p->set_parameter("hypertextencoding", "host");
   38 
   39     if (p->begin_document("quickreference.pdf", "") == -1) {
   40         cerr << "Error: " << p->get_errmsg() << endl; return 2;
   41     }
   42 
   43     p->set_info("Creator", "quickreference.cpp");
   44     p->set_info("Author", "Thomas Merz");
   45     p->set_info("Title", "mini imposition demo (C++)");
   46 
   47     manual = p->open_pdi_document(infile, "");
   48     if (manual == -1) {
   49         cerr << "Error: " << p->get_errmsg() << endl; return 2;
   50     }
   51 
   52     row = 0;
   53     col = 0;
   54 
   55     p->set_parameter("topdown", "true");
   56 
   57     endpage = (int) p->pcos_get_number(manual, "length:pages");
   58 
   59     for (pageno = 1; pageno <= endpage; pageno++) {
   60         if (row == 0 && col == 0) {
   61         p->begin_page_ext(width, height, "");
   62         font = p->load_font("Helvetica-Bold", "host", "");
   63         if (font == -1) {
   64             cerr << "Error: " << p->get_errmsg() << endl; return(2);
   65         }
   66         p->setfont(font, 18);
   67         p->set_text_pos(24, 24);
   68         p->show("PDFlib Quick Reference");
   69         }
   70 
   71         page = p->open_pdi_page(manual, pageno, "");
   72 
   73         if (page == -1) {
   74         cerr << "Error: " << p->get_errmsg() << endl; return 2;
   75         }
   76 
   77         sprintf(optlist, "scale %f", 1.0/maxrow);
   78         p->fit_pdi_page(page, width/maxcol*col,
   79             (row + 1) *  height/maxrow, optlist);
   80         p->close_pdi_page(page);
   81 
   82         col++;
   83         if (col == maxcol) {
   84         col = 0;
   85         row++;
   86         }
   87         if (row == maxrow) {
   88         row = 0;
   89         p->end_page_ext("");
   90         }
   91     }
   92 
   93     // finish the last partial page
   94     if (row != 0 || col != 0)
   95         p->end_page_ext("");
   96 
   97     p->end_document("");
   98     p->close_pdi_document(manual);
   99 
  100     }
  101 
  102     catch (PDFlib::Exception &ex) {
  103     cerr << "PDFlib exception occurred in quickreference sample: " << endl;
  104     cerr << "[" << ex.get_errnum() << "] " << ex.get_apiname()
  105         << ": " << ex.get_errmsg() << endl;
  106     return 2;
  107     }
  108 
  109     return 0;
  110 }