1 //========================================================================
5 // Copyright 1997 Derek B. Noonburg
7 //========================================================================
13 #include "parseargs.h"
24 #include "TextOutputDev.h"
29 static int firstPage = 1;
30 static int lastPage = 0;
31 static GBool useASCII7 = gFalse;
32 GBool printCommands = gFalse;
33 static GBool printHelp = gFalse;
35 static ArgDesc argDesc[] = {
36 {"-f", argInt, &firstPage, 0,
37 "first page to convert"},
38 {"-l", argInt, &lastPage, 0,
39 "last page to convert"},
40 {"-ascii7", argFlag, &useASCII7, 0,
41 "convert to 7-bit ASCII (default is 8-bit ISO Latin-1)"},
42 {"-h", argFlag, &printHelp, 0,
43 "print usage information"},
44 {"-help", argFlag, &printHelp, 0,
45 "print usage information"},
49 int main(int argc, char *argv[]) {
52 GString *textFileName;
53 TextOutputDev *textOut;
58 ok = parseArgs(argDesc, &argc, argv);
59 if (!ok || argc < 2 || argc > 3 || printHelp) {
60 fprintf(stderr, "pdftotext version %s\n", xpdfVersion);
61 fprintf(stderr, "%s\n", xpdfCopyright);
62 printUsage("pdftotext", "<PDF-file> [<text-file>]", argDesc);
65 fileName = new GString(argv[1]);
71 initParams(xpdfConfigFile);
75 doc = new PDFDoc(fileName);
79 // construct text file name
81 textFileName = new GString(argv[2]);
83 p = fileName->getCString() + fileName->getLength() - 4;
84 if (!strcmp(p, ".pdf") || !strcmp(p, ".PDF"))
85 textFileName = new GString(fileName->getCString(),
86 fileName->getLength() - 4);
88 textFileName = fileName->copy();
89 textFileName->append(".txt");
95 if (lastPage < 1 || lastPage > doc->getNumPages())
96 lastPage = doc->getNumPages();
99 textOut = new TextOutputDev(textFileName->getCString(), useASCII7);
101 doc->displayPages(textOut, firstPage, lastPage, 72, 0);
109 // check for memory leaks
110 Object::memCheck(errFile);