home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 110 / EnigmaAmiga110CD.iso / indispensabili / utility / apdf / xpdf-0.80 / xpdf / pdftops.cc < prev    next >
C/C++ Source or Header  |  1999-04-27  |  3KB  |  133 lines

  1. //========================================================================
  2. //
  3. // pdftops.cc
  4. //
  5. // Copyright 1996 Derek B. Noonburg
  6. //
  7. //========================================================================
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <stddef.h>
  12. #include <string.h>
  13. #include "parseargs.h"
  14. #include "GString.h"
  15. #include "gmem.h"
  16. #include "Object.h"
  17. #include "Stream.h"
  18. #include "Array.h"
  19. #include "Dict.h"
  20. #include "XRef.h"
  21. #include "Catalog.h"
  22. #include "Page.h"
  23. #include "PDFDoc.h"
  24. #include "PSOutputDev.h"
  25. #include "Params.h"
  26. #include "Error.h"
  27. #include "config.h"
  28.  
  29. static int firstPage = 1;
  30. static int lastPage = 0;
  31. static GBool noEmbedFonts = gFalse;
  32. static GBool doForm = gFalse;
  33. GBool printCommands = gFalse;
  34. static GBool printHelp = gFalse;
  35.  
  36. static ArgDesc argDesc[] = {
  37.   {"-f",      argInt,      &firstPage,     0,
  38.    "first page to print"},
  39.   {"-l",      argInt,      &lastPage,      0,
  40.    "last page to print"},
  41.   {"-paperw", argInt,      &paperWidth,    0,
  42.    "paper width, in points"},
  43.   {"-paperh", argInt,      &paperHeight,   0,
  44.    "paper height, in points"},
  45.   {"-level1", argFlag,     &psOutLevel1,   0,
  46.    "generate Level 1 PostScript"},
  47.   {"-noemb",  argFlag,     &noEmbedFonts,  0,
  48.    "don't embed Type 1 fonts"},
  49.   {"-form",   argFlag,     &doForm,        0,
  50.    "generate a PostScript form"},
  51.   {"-h",      argFlag,     &printHelp,     0,
  52.    "print usage information"},
  53.   {"-help",   argFlag,     &printHelp,     0,
  54.    "print usage information"},
  55.   {NULL}
  56. };
  57.  
  58. int main(int argc, char *argv[]) {
  59.   PDFDoc *doc;
  60.   GString *fileName;
  61.   GString *psFileName;
  62.   PSOutputDev *psOut;
  63.   GBool ok;
  64.   char *p;
  65.  
  66.   // parse args
  67.   ok = parseArgs(argDesc, &argc, argv);
  68.   if (!ok || argc < 2 || argc > 3 || printHelp) {
  69.     fprintf(stderr, "pdftops version %s\n", xpdfVersion);
  70.     fprintf(stderr, "%s\n", xpdfCopyright);
  71.     printUsage("pdftops", "<PDF-file> [<PS-file>]", argDesc);
  72.     exit(1);
  73.   }
  74.   if (doForm && psOutLevel1) {
  75.     fprintf(stderr, "Error: forms are only available with Level 2 output.\n");
  76.     exit(1);
  77.   }
  78.   fileName = new GString(argv[1]);
  79.  
  80.   // init error file
  81.   errorInit();
  82.  
  83.   // read config file
  84.   initParams(xpdfConfigFile);
  85.  
  86.   // open PDF file
  87.   xref = NULL;
  88.   doc = new PDFDoc(fileName);
  89.   if (!doc->isOk())
  90.     exit(1);
  91.  
  92.   // construct PostScript file name
  93.   if (argc == 3) {
  94.     psFileName = new GString(argv[2]);
  95.   } else {
  96.     p = fileName->getCString() + fileName->getLength() - 4;
  97.     if (!strcmp(p, ".pdf") || !strcmp(p, ".PDF"))
  98.       psFileName = new GString(fileName->getCString(),
  99.                    fileName->getLength() - 4);
  100.     else
  101.       psFileName = fileName->copy();
  102.     psFileName->append(".ps");
  103.   }
  104.  
  105.   // get page range
  106.   if (firstPage < 1)
  107.     firstPage = 1;
  108.   if (lastPage < 1 || lastPage > doc->getNumPages())
  109.     lastPage = doc->getNumPages();
  110.   if (doForm)
  111.     lastPage = firstPage;
  112.  
  113.   // write PostScript file
  114.   if (doc->okToPrint()) {
  115.     psOut = new PSOutputDev(psFileName->getCString(), doc->getCatalog(),
  116.                 firstPage, lastPage, !noEmbedFonts, doForm);
  117.     if (psOut->isOk())
  118.       doc->displayPages(psOut, firstPage, lastPage, 72, 0);
  119.     delete psOut;
  120.   }
  121.  
  122.   // clean up
  123.   delete psFileName;
  124.   delete doc;
  125.   freeParams();
  126.  
  127.   // check for memory leaks
  128.   Object::memCheck(errFile);
  129.   gMemReport(errFile);
  130.  
  131.   return 0;
  132. }
  133.