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 / c / quickreference.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-07-04  |  1.8 KB  |  84 lines  |  [TEXT/CWIE]

  1. /* $Id: quickreference.c,v 1.8 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.h"
  9.  
  10. int
  11. main(void)
  12. {
  13.     PDF *p;
  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 = PDF_new();
  24.  
  25.     if (PDF_open_file(p, "quickreference.pdf") == -1) {
  26.     fprintf(stderr, "Error: cannot open PDF file 'quick_reference.pdf'.\n");
  27.     exit(2);
  28.     }
  29.  
  30.     PDF_set_info(p, "Creator", "quickreference.c");
  31.     PDF_set_info(p, "Author", "Thomas Merz");
  32.     PDF_set_info(p, "Title", "mini imposition demo (C)");
  33.  
  34.     manual = PDF_open_pdi(p, 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.         PDF_begin_page(p, width, height);
  46.         font = PDF_findfont(p, "Helvetica-Bold", "host", 0);
  47.         PDF_setfont(p, font, 18);
  48.         PDF_set_text_pos(p, 25, height-24);
  49.         PDF_show(p, "PDFlib 4.0 Quick Reference");
  50.     }
  51.  
  52.     page = PDF_open_pdi_page(p, 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.     PDF_place_pdi_page(p, page, width/maxcol*col, height - (row + 1) 
  60.             * height/maxrow, (float) 1/maxrow, (float) 1/maxrow);
  61.     PDF_close_pdi_page(p, page);
  62.  
  63.     col++;
  64.     if (col == maxcol) {
  65.         col = 0;
  66.         row++;
  67.     }
  68.     if (row == maxrow) {
  69.         row = 0;
  70.         PDF_end_page(p);
  71.     }
  72.     }
  73.  
  74.     /* finish the last partial page */
  75.     if (row != 0 || col != 0)
  76.     PDF_end_page(p);
  77.  
  78.     PDF_close(p);
  79.     PDF_close_pdi(p, manual);
  80.     PDF_delete(p);
  81.  
  82.     return 0;
  83. }
  84.