home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 720 / PDF090B4-SorceCode / pdf / pdfinfo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  3.6 KB  |  145 lines

  1. //========================================================================
  2. //
  3. // pdfinfo.cc
  4. //
  5. // Copyright 1998 Derek B. Noonburg
  6. //
  7. //========================================================================
  8. //
  9. // Ported to EPOC by Sander van der Wal
  10. //
  11. // $Id: pdfinfo.cpp 1.2 2000-09-17 13:38:13+02 svdwal Exp svdwal $
  12. //
  13. // $Log: pdfinfo.cpp $
  14. // Revision 1.2  2000-09-17 13:38:13+02  svdwal
  15. // Ported
  16. //
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <stddef.h>
  21. #include <string.h>
  22. #include "parseargs.h"
  23. #include "GString.h"
  24. #include "gmem.h"
  25. #include "Object.h"
  26. #include "Stream.h"
  27. #include "Array.h"
  28. #include "Dict.h"
  29. #include "XRef.h"
  30. #include "Catalog.h"
  31. #include "Page.h"
  32. #include "PDFDoc.h"
  33. #include "Error.h"
  34. #include "config.h"
  35.  
  36. GBool printCommands = gFalse;
  37. static GBool printHelp = gFalse;
  38.  
  39. static ArgDesc argDesc[] = {
  40.   {"-h",      argFlag,     &printHelp,     0,
  41.    "print usage information"},
  42.   {"-help",   argFlag,     &printHelp,     0,
  43.    "print usage information"},
  44.   {NULL}
  45. };
  46.  
  47. int main(int argc, char *argv[]) {
  48.   PDFDoc *doc;
  49.   GString *fileName;
  50.   Object info, obj;
  51.   char *s;
  52.   GBool ok;
  53.  
  54.   // parse args
  55.   ok = parseArgs(argDesc, &argc, argv);
  56.   if (!ok || argc != 2 || printHelp) {
  57.     fprintf(stderr, "pdfinfo version %s\n", xpdfVersion);
  58.     fprintf(stderr, "%s\n", xpdfCopyright);
  59.     printUsage("pdfinfo", "<PDF-file>", argDesc);
  60.     exit(1);
  61.   }
  62.   fileName = new GString(argv[1]);
  63.  
  64.   // init error file
  65.   errorInit();
  66.  
  67.   // read config file
  68.   initParams(xpdfConfigFile);
  69.  
  70.   // open PDF file
  71.   xref = NULL;
  72.   doc = new PDFDoc(fileName);
  73.   if (!doc->isOk())
  74.     exit(1);
  75.  
  76.   // print doc info
  77.   doc->getDocInfo(&info);
  78.   if (info.isDict()) {
  79.     if (info.dictLookup("Title", &obj)->isString())
  80.       printf("Title:        %s\n", obj.getString()->getCString());
  81.     obj.free();
  82.     if (info.dictLookup("Subject", &obj)->isString())
  83.       printf("Subject:      %s\n", obj.getString()->getCString());
  84.     obj.free();
  85.     if (info.dictLookup("Keywords", &obj)->isString())
  86.       printf("Keywords:     %s\n", obj.getString()->getCString());
  87.     obj.free();
  88.     if (info.dictLookup("Author", &obj)->isString())
  89.       printf("Author:       %s\n", obj.getString()->getCString());
  90.     obj.free();
  91.     if (info.dictLookup("Creator", &obj)->isString())
  92.       printf("Creator:      %s\n", obj.getString()->getCString());
  93.     obj.free();
  94.     if (info.dictLookup("Producer", &obj)->isString())
  95.       printf("Producer:     %s\n", obj.getString()->getCString());
  96.     obj.free();
  97.     if (info.dictLookup("CreationDate", &obj)->isString()) {
  98.       s = obj.getString()->getCString();
  99.       if (s[0] == 'D' && s[1] == ':')
  100.     s += 2;
  101.       printf("CreationDate: %s\n", s);
  102.     }
  103.     obj.free();
  104.     if (info.dictLookup("ModDate", &obj)->isString()) {
  105.       s = obj.getString()->getCString();
  106.       if (s[0] == 'D' && s[1] == ':')
  107.     s += 2;
  108.       printf("ModDate:      %s\n", s);
  109.     }
  110.     obj.free();
  111.   }
  112.   info.free();
  113.  
  114.   // print page count
  115.   printf("Pages:        %d\n", doc->getNumPages());
  116.  
  117.   // print encryption info
  118.   printf("Encrypted:    ");
  119.   if (doc->isEncrypted()) {
  120.     printf("yes (print:%s copy:%s)\n",
  121.        doc->okToPrint() ? "yes" : "no",
  122.        doc->okToCopy() ? "yes" : "no");
  123.   } else {
  124.     printf("no\n");
  125.   }
  126.  
  127.   // clean up
  128.   delete doc;
  129.   freeParams();
  130.  
  131.   // check for memory leaks
  132.   Object::memCheck(stderr);
  133.   gMemReport(stderr);
  134.  
  135.   return 0;
  136. }
  137.  
  138. extern "C" void __pfnBkCheck() {}
  139.  
  140. #undef _atexit
  141. #undef atexit
  142. extern "C" int atexit(void (__cdecl *func)(void))
  143. {
  144.   return _epoc32_atexit(func);
  145. }