2
* Copyright (C) 2007 Jauco Noordzij <jauco@jauco.nl>
3
* Copyright (C) 2007 Dominic Lachowicz <cinamod@hotmail.com>
4
* Copyright (C) 2007 Kouhei Sutou <kou@cozmixng.org>
5
* Copyright (C) 2009 Jakub Wilk <ubanus@users.sf.net>
6
* Copyright (C) 2009, 2010 Albert Astals Cid <aacid@kde.org>
7
* Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2, or (at your option)
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
25
#include <poppler-config.h>
34
#include "parseargs.h"
35
#include "goo/GooString.h"
45
#include "PDFDocFactory.h"
46
#include "ABWOutputDev.h"
47
#include "PSOutputDev.h"
48
#include "GlobalParams.h"
50
#include "goo/gfile.h"
51
#include <libxml/parser.h>
52
#include <libxml/tree.h>
54
static int firstPage = 1;
55
static int lastPage = 0;
56
static GBool quiet = gFalse;
57
static GBool printHelp = gFalse;
58
static GBool printVersion = gFalse;
59
static GBool stout = gFalse;
60
static char ownerPassword[33] = "";
61
static char userPassword[33] = "";
63
// static char textEncName[128] = "";
65
static const ArgDesc argDesc[] = {
66
{"-f", argInt, &firstPage, 0,
67
"first page to convert"},
68
{"-l", argInt, &lastPage, 0,
69
"last page to convert"},
70
{"--stdout" ,argFlag, &stout, 0,
71
"use standard output"},
72
{"--opw", argString, ownerPassword, sizeof(ownerPassword),
73
"owner password (for encrypted files)"},
74
{"--upw", argString, userPassword, sizeof(userPassword),
75
"user password (for encrypted files)"},
76
{"-q", argFlag, &quiet, 0,
77
"don't print any messages or errors"},
78
{"-v", argFlag, &printVersion, 0,
79
"print copyright and version info"},
80
{"-h", argFlag, &printHelp, 0,
81
"print usage information"},
82
{"-help", argFlag, &printHelp, 0,
83
"print usage information"},
84
{"--help", argFlag, &printHelp, 0,
85
"print usage information"},
86
{"-?", argFlag, &printHelp, 0,
87
"print usage information"},
91
int main(int argc, char *argv[]) {
94
GooString *fileName = NULL;
95
// GooString *abwFileName = NULL;
96
ABWOutputDev *abwOut = NULL;
98
GooString *ownerPW, *userPW;
104
xmlDocPtr XMLdoc = NULL;
107
ok = parseArgs(argDesc, &argc, argv);
108
if (!ok || argc < 2 || argc > 3 || printVersion || printHelp) {
109
fprintf(stderr, "pdftoabw version %s\n", PACKAGE_VERSION);
110
fprintf(stderr, "%s\n", popplerCopyright);
111
fprintf(stderr, "%s\n", xpdfCopyright);
113
printUsage("pdftoabw", "<PDF-file> [abw-file]", argDesc);
117
globalParams = new GlobalParams();
119
globalParams->setErrQuiet(quiet);
122
fileName = new GooString(argv[1]);
123
if (stout || (argc < 3)){
130
if (ownerPassword[0]) {
131
ownerPW = new GooString(ownerPassword);
135
if (userPassword[0]) {
136
userPW = new GooString(userPassword);
141
if (fileName->cmp("-") == 0) {
143
fileName = new GooString("fd://0");
146
doc = PDFDocFactory().createPDFDoc(*fileName, ownerPW, userPW);
155
if (!doc || !doc->isOk())
157
fprintf (stderr, "Error opening PDF %s\n", fileName->getCString());
161
// check for copy permission
162
if (!doc->okToCopy()) {
163
fprintf(stderr, "Copying of text from this document is not allowed.\n");
167
XMLdoc = xmlNewDoc(BAD_CAST "1.0");
168
abwOut = new ABWOutputDev(XMLdoc);
169
abwOut->setPDFDoc(doc);
171
if (lastPage == 0 || lastPage > doc->getNumPages ()) lastPage = doc->getNumPages();
172
if (firstPage < 1) firstPage = 1;
176
doc->displayPages(abwOut, firstPage, lastPage, 72, 72, 0, gTrue, gFalse, gFalse);
180
if (xmlSaveFormatFileEnc(outpName, XMLdoc, "UTF-8", 1) == -1)
182
fprintf (stderr, "Error saving to %s\n", outpName);
190
if(globalParams) delete globalParams;
193
if(XMLdoc) xmlFreeDoc(XMLdoc);
194
if(abwOut) delete abwOut;
196
// check for memory leaks
197
Object::memCheck(stderr);