home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 February / PCWorld_2002-02_cd.bin / Software / Vyzkuste / pdflib / pdflib-4.0.1.sit / pdflib-4.0.1 / bind / cpp / quickreference.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-04  |  1.8 KB  |  83 lines  |  [TEXT/CWIE]

  1. // $Id: quickreference.cpp,v 1.7 2001/04/18 09:41:16 tm Exp $
  2. //
  3. // PDFlib/PDI client: mini imposition demo
  4. //
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. #include "pdflib.hpp"
  9.  
  10. int
  11. main(void)
  12. {
  13.     PDF *p;            // pointer to the PDF class
  14.     int manual, page;
  15.     int font, row, col;
  16.     const int maxrow = 2;
  17.     const int maxcol = 2;
  18.     int i, startpage = 122, endpage = 125;
  19.     const float width = 500, height = 770;
  20.     int pageno;
  21.     const char *infile = "../../doc/PDFlib-manual.pdf";
  22.  
  23.     p = new PDF();
  24.  
  25.     if (p->open("quickreference.pdf") == -1) {
  26.     fprintf(stderr, "Error: cannot open PDF file 'quick_reference.pdf'.\n");
  27.     exit(2);
  28.     }
  29.  
  30.     p->set_info("Creator", "quickreference.cpp");
  31.     p->set_info("Author", "Thomas Merz");
  32.     p->set_info("Title", "mini imposition demo (C++)");
  33.  
  34.     manual = p->open_pdi(infile, "", 0);
  35.     if (manual == -1) {
  36.     fprintf(stderr, "Couldn't open input file '%s'.\n", infile);
  37.     exit(2);
  38.     }
  39.  
  40.     row = 0;
  41.     col = 0;
  42.  
  43.     for (pageno = startpage; pageno <= endpage; pageno++) {
  44.     if (row == 0 && col == 0) {
  45.         p->begin_page(width, height);
  46.         font = p->findfont("Helvetica-Bold", "host", 0);
  47.         p->setfont(font, 18);
  48.         p->set_text_pos(25, height-24);
  49.         p->show("PDFlib 4.0 Quick Reference");
  50.     }
  51.  
  52.     page = p->open_pdi_page(manual, pageno, "");
  53.  
  54.     if (page == -1) {
  55.         fprintf(stderr, "Couldn't open page %d in '%s'.\n", pageno, infile);
  56.         exit(2);
  57.     }
  58.  
  59.     p->place_pdi_page(manual, width/maxcol*col, height - (row + 1)
  60.             * height/maxrow, (float) 1/maxrow, (float) 1/maxrow);
  61.     p->close_pdi_page(page);
  62.  
  63.     col++;
  64.     if (col == maxcol) {
  65.         col = 0;
  66.         row++;
  67.     }
  68.     if (row == maxrow) {
  69.         row = 0;
  70.         p->end_page();
  71.     }
  72.     }
  73.  
  74.     // finish the last partial page
  75.     if (row != 0 || col != 0)
  76.     p->end_page();
  77.  
  78.     p->close();
  79.     p->close_pdi(manual);
  80.  
  81.     return 0;
  82. }
  83.