20#include "pdfdocument.h"
27#include "GlobalParams.h"
30#include "FilterDevice.h"
38 : _file(0), _object(0), _fileStream(0), _document(0), _device(0)
41KoFilter::ConversionStatus
42Document::init(
const TQString &name,
const TQString &ownerPassword,
43 const TQString &userPassword)
47 _file =
new TQFile(name);
48 if( !_file->open(IO_ReadOnly) )
return KoFilter::FileNotFound;
50 FILE *fd = fdopen(_file->handle(),
"r");
51 if ( fd==0 )
return KoFilter::InternalError;
53 globalParams =
new GlobalParams(0);
54 globalParams->setErrQuiet(gFalse);
58 _fileStream =
new FileStream(fd, 0, gFalse, 0, _object);
60 (ownerPassword.isEmpty() ? 0 :
new GString(ownerPassword.latin1()));
62 (userPassword.isEmpty() ? 0 :
new GString(userPassword.latin1()));
63 _document =
new PDFDoc(_fileStream, owner, user);
67 if ( !_document->isOk() )
return KoFilter::WrongFormat;
90TQString Document::info(
const TQCString &key)
const
94 _document->getDocInfo(&info);
95 if ( info.isDict() ) {
97 if ( info.getDict()->lookup(key.data(), &tmp)->isString() ) {
98 GString *s = tmp.getString();
99 bool isUnicode =
false;
102 if ( (s->getChar(0) & 0xff)==0xfe &&
103 (s->getChar(1) & 0xff)==0xff ) {
107 while ( i<s->getLength() ) {
109 u = ( (s->getChar(i) & 0xff)<<8 ) |
110 (s->getChar(i+1) & 0xff);
112 }
else u = s->getChar(i) & 0xff;
123uint Document::nbPages()
const
125 return _document->getNumPages();
128KoOrientation Document::paperOrientation()
const
130 if ( nbPages()==0 )
return PG_PORTRAIT;
131 return ( _document->getPageWidth(1)<_document->getPageHeight(1) ?
132 PG_PORTRAIT : PG_LANDSCAPE );
135DRect Document::paperSize(KoFormat &format)
const
137 KoOrientation orientation = paperOrientation();
140 if ( nbPages()==0 ) {
142 w = mmToPoint(KoPageFormat::width(format, orientation));
143 h = mmToPoint(KoPageFormat::height(format, orientation));
144 return DRect(0, w, 0, h);
147 w = _document->getPageWidth(1);
148 h = _document->getPageHeight(1);
150 double min = kMin(w, h);
151 double max = kMax(w, h);
155 for (uint i=0; i<=PG_LAST_FORMAT; i++) {
156 if ( i==PG_CUSTOM || i==PG_SCREEN )
continue;
157 w = mmToPoint(KoPageFormat::width(KoFormat(i), orientation));
158 h = mmToPoint(KoPageFormat::height(KoFormat(i), orientation));
159 double v = fabs(min/w - 1) + fabs(max/h - 1);
163 format = KoFormat(i);
169 return DRect(0, width, 0, height);
172void Document::initDevice(Data &data)
174 Q_ASSERT( _device==0 );
175 _device =
new Device(data);
183void Document::treatPage(uint i)
187 _document->displayPage(_device, i,
int(72*1), 0, gTrue);
190bool Document::isEncrypted()
const
192 return _document->getXRef()->isEncrypted();
195void Document::dumpPage(uint i)
197 _device->dumpPage(i);