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 / perl / quickreference.pl < prev    next >
Encoding:
Perl Script  |  2001-07-04  |  1.6 KB  |  77 lines  |  [TEXT/McPL]

  1. #!/usr/bin/perl
  2. # $Id: quickreference.pl,v 1.6 2001/04/18 09:41:16 tm Exp $
  3. #
  4. # PDFlib/PDI client: mini imposition demo
  5. #
  6.  
  7. use pdflib_pl 4.0;
  8.  
  9. $infile = "../../doc/PDFlib-manual.pdf";
  10. $maxrow = 2;
  11. $maxcol = 2;
  12. $pagecount = 4;
  13. $width = 500.0;
  14. $height = 770.0;
  15. $startpage = 122;
  16. $endpage = 125;
  17.  
  18. $p = PDF_new();
  19.  
  20. if (PDF_open_file($p, "quickreference.pdf") == -1) {
  21.     printf(STDERR "Error: cannot open PDF file 'quick_reference.pdf'.\n");
  22.     exit(2);
  23. }
  24.  
  25. PDF_set_info($p, "Creator", "quickreference.pl");
  26. PDF_set_info($p, "Author", "Thomas Merz");
  27. PDF_set_info($p, "Title", "mini imposition demo (Perl)");
  28.  
  29. $manual = PDF_open_pdi($p, $infile, "", 0);
  30. if ($manual == -1) {
  31.     printf(STDERR "Couldn't open input file '%s'.\n", $infile);
  32.     exit(2);
  33. }
  34.  
  35. $row = 0;
  36. $col = 0;
  37.  
  38. for ($pageno = $startpage; $pageno <= $endpage; $pageno++) {
  39.     if ($row == 0 && $col == 0) {
  40.     PDF_begin_page($p, $width, $height);
  41.     $font = PDF_findfont($p, "Helvetica-Bold", "host", 0);
  42.     PDF_setfont($p, $font, 18);
  43.     PDF_set_text_pos($p, 25, $height-24);
  44.     PDF_show($p, "PDFlib 4.0 Quick Reference");
  45.     }
  46.  
  47.     $page = PDF_open_pdi_page($p, $manual, $pageno, "");
  48.  
  49.     if ($page == -1) {
  50.     printf(STDERR "Couldn't open page %d in '%s'.\n", $pageno, $infile);
  51.     exit(2);
  52.     }
  53.  
  54.     PDF_place_pdi_page($p, $manual, $width/$maxcol*$col,
  55.         $height - ($row + 1) * $height/$maxrow, 1/$maxrow, 1/$maxrow);
  56.     PDF_close_pdi_page($p, $page);
  57.  
  58.     $col++;
  59.     if ($col == $maxcol) {
  60.     $col = 0;
  61.     $row++;
  62.     }
  63.     if ($row == $maxrow) {
  64.     $row = 0;
  65.     PDF_end_page($p);
  66.     }
  67. }
  68.  
  69. # finish the last partial page
  70. if ($row != 0 || $col != 0) {
  71.     PDF_end_page($p);
  72. }
  73.  
  74. PDF_close($p);
  75. PDF_close_pdi($p, $manual);
  76. PDF_delete($p);
  77.