Commit 2fcb76df authored by Jeff Muizelaar's avatar Jeff Muizelaar

2007-04-06 Jeff Muizelaar <jeff@infidigm.net>

	* poppler/ABWOutputDev.cc:
	* utils/pdftoabw.cc: Fix a number of issues with the new AbiWord code:
		*) Allows you to save to a file other than stdout
		*) Checks for error conditions when reading the PDF doc and
		   writing the ABW doc
		*) Removes dead code in pdftoabw.cc
		*) Fixes a SEGV I encountered when converting my new home's floor plan
		*) Returns proper error conditions should the conversion fail for any reason
	Patch by Dominic Lachowicz
parent 29da65ec
2007-04-06 Jeff Muizelaar <jeff@infidigm.net>
* poppler/ABWOutputDev.cc:
* utils/pdftoabw.cc: Fix a number of issues with the new AbiWord code:
*) Allows you to save to a file other than stdout
*) Checks for error conditions when reading the PDF doc and
writing the ABW doc
*) Removes dead code in pdftoabw.cc
*) Fixes a SEGV I encountered when converting my new home's floor plan
*) Returns proper error conditions should the conversion fail for any reason
Patch by Dominic Lachowicz
2007-04-05 Albert Astals Cid <aacid@kde.org>
* poppler/PSOutputDev.cc: Readd code wrongly removed when doing the
......
......@@ -652,6 +652,9 @@ void ABWOutputDev::interpretXYTree(){
void ABWOutputDev::ATP_recursive(xmlNodePtr N_parent){
xmlNodePtr N_first, N_second, N_line, N_tempCol, N_tempColset;
N_first = N_parent->children;
if (!N_first)
return;
N_second = N_first->next;
char buf[20];
/*
......
......@@ -34,22 +34,13 @@
#include <libxml/parser.h>
#include <libxml/tree.h>
static int firstPage = 1;
static int lastPage = 0;
GBool printCommands = gTrue;
GBool prettyPrint = gFalse;
static GBool printHelp = gFalse;
GBool stout=gFalse;
GBool stout = gFalse;
static char ownerPassword[33] = "";
static char userPassword[33] = "";
static GooString* getInfoString(Dict *infoDict, char *key);
static GooString* getInfoDate(Dict *infoDict, char *key);
xmlDocPtr XMLdoc;
static char textEncName[128] = "";
static ArgDesc argDesc[] = {
......@@ -61,8 +52,6 @@ static ArgDesc argDesc[] = {
"print usage information"},
{"--help", argFlag, &printHelp, 0,
"print usage information"},
{"--format", argFlag, &prettyPrint, 0,
"print usage information"},
{"--stdout" ,argFlag, &stout, 0,
"use standard output"},
{"--opw", argString, ownerPassword, sizeof(ownerPassword),
......@@ -75,64 +64,92 @@ static ArgDesc argDesc[] = {
int main(int argc, char *argv[]) {
PDFDoc *doc = NULL;
GooString *fileName = NULL;
GooString *docTitle = NULL;
GooString *author = NULL, *keywords = NULL, *subject = NULL, *date = NULL;
GooString *htmlFileName = NULL;
GooString *psFileName = NULL;
ABWOutputDev *htmlOut = NULL;
PSOutputDev *psOut = NULL;
GooString *abwFileName = NULL;
ABWOutputDev *abwOut = NULL;
GBool ok;
char *p;
char extension[16] = "png";
GooString *ownerPW, *userPW;
Object info;
int result = 1;
char * outpName;
xmlDocPtr XMLdoc = NULL;
// parse args
parseArgs(argDesc, &argc, argv);
globalParams = new GlobalParams();
fileName = new GooString(argv[1]);
/*
if (stout){*/
if (stout || (argc < 2)){
outpName = "-";
/* }
}
else {
//FIXME: add outputfilename stuff
outpName = argv[2];
}
*/
doc = new PDFDoc(fileName);
XMLdoc = xmlNewDoc(BAD_CAST "1.0");
htmlOut = new ABWOutputDev(XMLdoc);
htmlOut->setPDFDoc(doc);
/* check for copy permission
if (ownerPassword[0]) {
ownerPW = new GooString(ownerPassword);
} else {
ownerPW = NULL;
}
if (userPassword[0]) {
userPW = new GooString(userPassword);
} else {
userPW = NULL;
}
doc = new PDFDoc(fileName, ownerPW, userPW);
if (userPW) {
delete userPW;
}
if (ownerPW) {
delete ownerPW;
}
if (!doc || !doc->isOk())
{
fprintf (stderr, "Error opening PDF %s\n", fileName);
goto error;
}
// check for copy permission
if (!doc->okToCopy()) {
error(-1, "Copying of text from this document is not allowed.");
fprintf(stderr, "Copying of text from this document is not allowed.\n");
goto error;
}*/
}
// write text file
XMLdoc = xmlNewDoc(BAD_CAST "1.0");
abwOut = new ABWOutputDev(XMLdoc);
abwOut->setPDFDoc(doc);
if (lastPage == 0) lastPage = doc->getNumPages();
if (lastPage == 0 || lastPage > doc->getNumPages ()) lastPage = doc->getNumPages();
if (firstPage < 1) firstPage = 1;
if (htmlOut->isOk())
if (abwOut->isOk())
{
doc->displayPages(htmlOut, 1, lastPage, 72, 72, 0, gTrue, gFalse, gFalse);
htmlOut->createABW();
doc->displayPages(abwOut, firstPage, lastPage, 72, 72, 0, gTrue, gFalse, gFalse);
abwOut->createABW();
}
xmlSaveFormatFileEnc(outpName, XMLdoc, "UTF-8", 1);
// clean up
if (xmlSaveFormatFileEnc(outpName, XMLdoc, "UTF-8", 1) == -1)
{
fprintf (stderr, "Error saving to %s\n", outpName);
goto error;
}
result = 0;
error:
// clean up
if(globalParams) delete globalParams;
//if(fileName) delete fileName;
if(doc) delete doc;
if(XMLdoc) xmlFreeDoc(XMLdoc);
if(htmlOut) delete htmlOut;
if(abwOut) delete abwOut;
// check for memory leaks
Object::memCheck(stderr);
gMemReport(stderr);
return 0;
return result;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment