1
/* poppler-pdf-converter.cc: qt4 interface to poppler
2
* Copyright (C) 2008, Pino Toscano <pino@kde.org>
3
* Copyright (C) 2008, 2009, Albert Astals Cid <aacid@kde.org>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2, or (at your option)
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "poppler-qt4.h"
22
#include "poppler-private.h"
23
#include "poppler-converter-private.h"
24
#include "poppler-qiodeviceoutstream-private.h"
26
#include <QtCore/QFile>
28
#include <ErrorCodes.h>
32
class PDFConverterPrivate : public BaseConverterPrivate
35
PDFConverterPrivate();
37
PDFConverter::PDFOptions opts;
40
PDFConverterPrivate::PDFConverterPrivate()
41
: BaseConverterPrivate(), opts(0)
46
PDFConverter::PDFConverter(DocumentData *document)
47
: BaseConverter(*new PDFConverterPrivate())
50
d->document = document;
53
PDFConverter::~PDFConverter()
57
void PDFConverter::setPDFOptions(PDFConverter::PDFOptions options)
63
PDFConverter::PDFOptions PDFConverter::pdfOptions() const
65
Q_D(const PDFConverter);
69
bool PDFConverter::convert()
72
d->lastError = NoError;
74
if (d->document->locked)
76
d->lastError = FileLockedError;
80
QIODevice *dev = d->openDevice();
83
d->lastError = OpenOutputError;
87
bool deleteFile = false;
88
if (QFile *file = qobject_cast<QFile*>(dev))
89
deleteFile = !file->exists();
91
int errorCode = errNone;
92
QIODeviceOutStream stream(dev);
93
if (d->opts & WithChanges)
95
errorCode = d->document->doc->saveAs(&stream);
99
errorCode = d->document->doc->saveWithoutChangesAs(&stream);
102
if (errorCode != errNone)
106
qobject_cast<QFile*>(dev)->remove();
108
if (errorCode == errOpenFile) d->lastError = OpenOutputError;
109
else d->lastError = NotSupportedInputFileError;
112
return (errorCode == errNone);