1
// --------------------------------------------------------------------
2
// Pdftoipe: convert PDF file to editable Ipe XML file
3
// --------------------------------------------------------------------
6
This file is part of the extensible drawing editor Ipe.
7
Copyright (C) 1993-2004 Otfried Cheong
9
Ipe is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
As a special exception, you have permission to link Ipe with the
15
CGAL library and distribute executables, as long as you follow the
16
requirements of the Gnu General Public License in regard to all of
17
the software in the executable aside from CGAL.
19
Ipe is distributed in the hope that it will be useful, but WITHOUT
20
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
22
License for more details.
24
You should have received a copy of the GNU General Public License
25
along with Ipe; if not, you can find it at
26
"http://www.gnu.org/copyleft/gpl.html", or write to the Free
27
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36
#include "parseargs.h"
39
#include "globalparams.h"
48
#include "xmloutputdev.h"
51
static int firstPage = 1;
52
static int lastPage = 0;
53
static char ownerPassword[33] = "";
54
static char userPassword[33] = "";
55
static GBool quiet = gFalse;
56
static GBool printHelp = gFalse;
57
static GBool math = gFalse;
59
static ArgDesc argDesc[] = {
60
{"-f", argInt, &firstPage, 0,
61
"first page to convert"},
62
{"-l", argInt, &lastPage, 0,
63
"last page to convert"},
64
{"-opw", argString, ownerPassword, sizeof(ownerPassword),
65
"owner password (for encrypted files)"},
66
{"-upw", argString, userPassword, sizeof(userPassword),
67
"user password (for encrypted files)"},
68
{"-q", argFlag, &quiet, 0,
69
"don't print any messages or errors"},
70
{"-math", argFlag, &math, 0,
71
"turn all text objects into math formulas"},
72
{"-h", argFlag, &printHelp, 0,
73
"print usage information"},
74
{"-help", argFlag, &printHelp, 0,
75
"print usage information"},
76
{"--help", argFlag, &printHelp, 0,
77
"print usage information"},
78
{"-?", argFlag, &printHelp, 0,
79
"print usage information"},
80
{NULL, argFlag, 0, 0, 0}
83
int main(int argc, char *argv[])
86
GBool ok = parseArgs(argDesc, &argc, argv);
87
if (!ok || argc < 2 || argc > 3 || printHelp) {
88
fprintf(stderr, "pdftoipe version %s\n", PDFTOIPE_VERSION);
89
printUsage("pdftoipe", "<PDF-file> [<XML-file>]", argDesc);
93
GString *fileName = new GString(argv[1]);
96
globalParams = new GlobalParams(0);
98
globalParams->setErrQuiet(quiet);
101
GString *ownerPW, *userPW;
102
if (ownerPassword[0]) {
103
ownerPW = new GString(ownerPassword);
107
if (userPassword[0]) {
108
userPW = new GString(userPassword);
114
PDFDoc *doc = new PDFDoc(fileName, ownerPW, userPW);
121
// check for print permission
122
if (!doc->okToPrint()) {
123
error(-1, "Printing this document is not allowed.");
127
// construct XML file name
128
GString *xmlFileName;
130
xmlFileName = new GString(argv[2]);
132
char *p = fileName->getCString() + fileName->getLength() - 4;
133
if (!strcmp(p, ".pdf") || !strcmp(p, ".PDF")) {
134
xmlFileName = new GString(fileName->getCString(),
135
fileName->getLength() - 4);
137
xmlFileName = fileName->copy();
139
xmlFileName->append(".xml");
146
if (lastPage < 1 || lastPage > doc->getNumPages()) {
147
lastPage = doc->getNumPages();
151
XmlOutputDev *xmlOut =
152
new XmlOutputDev(xmlFileName->getCString(), doc->getXRef(),
153
doc->getCatalog(), firstPage, lastPage,
156
if (xmlOut->isOk()) {
157
doc->displayPages(xmlOut, firstPage, lastPage, 72, 0, gFalse);
167
// check for memory leaks
168
Object::memCheck(stderr);
174
// --------------------------------------------------------------------