KoFilter::ConversionStatus MSWordImport::convert( const QCString& from, const QCString& to ) { // check for proper conversion if ( to != "application/x-kword" || from != "application/msword" ) return KoFilter::NotImplemented; kdDebug(30513) << "######################## MSWordImport::convert ########################" << endl; QDomDocument mainDocument; QDomElement framesetsElem; prepareDocument( mainDocument, framesetsElem ); QDomDocument documentInfo; documentInfo.appendChild (documentInfo.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) ); Document document( QFile::encodeName( m_chain->inputFile() ).data(), mainDocument, documentInfo, framesetsElem, m_chain ); if ( !document.hasParser() ) return KoFilter::WrongFormat; if ( !document.parse() ) return KoFilter::ParsingError; document.processSubDocQueue(); document.finishDocument(); if ( !document.bodyFound() ) return KoFilter::WrongFormat; KoStoreDevice* out = m_chain->storageFile( "root", KoStore::Write ); if ( !out ) { kdError(30502) << "Unable to open output file!" << endl; return KoFilter::StorageCreationError; } QCString cstr = mainDocument.toCString(); // WARNING: we cannot use KoStore::write(const QByteArray&) because it gives an extra NULL character at the end. out->writeBlock( cstr, cstr.length() ); out->close(); out = m_chain->storageFile( "documentinfo.xml", KoStore::Write ); if ( !out ) { return KoFilter::StorageCreationError; } cstr = documentInfo.toCString(); out->writeBlock( cstr, cstr.length() ); out->close(); kdDebug(30513) << "######################## MSWordImport::convert done ####################" << endl; return KoFilter::OK; }
void PdfImport::treatInfoDocument() { QDomDocument infoDocument("document-info"); infoDocument.appendChild( infoDocument.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"")); QDomElement infoElement = infoDocument.createElement( "document-info" ); infoDocument.appendChild(infoElement); QDomElement aboutTag = infoDocument.createElement("about"); infoElement.appendChild(aboutTag); QDomElement authorTag = infoDocument.createElement("author"); infoElement.appendChild(authorTag); QDomElement fullNameTag = infoDocument.createElement("full-name"); authorTag.appendChild(fullNameTag); QDomText authorText = infoDocument.createTextNode( _doc.info("Author") ); fullNameTag.appendChild(authorText); QDomElement titleTag = infoDocument.createElement("title"); aboutTag.appendChild(titleTag); QDomText titleText = infoDocument.createTextNode( _doc.info("Title") ); titleTag.appendChild(titleText); // output KoStoreDevice *out = m_chain->storageFile("documentinfo.xml", KoStore::Write); if ( !out ) kdWarning(30516) << "unable to open doc info. continuing anyway\n"; else { QCString cstr = infoDocument.toCString(); out->writeBlock(cstr, cstr.length()); out->close(); } }
KoFilter::ConversionStatus PdfImport::convert(const QCString& from, const QCString& to) { // check for proper conversion if ( to!="application/x-kword" || from!="application/pdf" ) return KoFilter::NotImplemented; // read file KoFilter::ConversionStatus result = _doc.init(m_chain->inputFile(), QString::null, QString::null); if ( result!=KoFilter::OK ) return result; // options dialog { Dialog dialog(_doc.nbPages(), _doc.isEncrypted(), 0); dialog.exec(); if ( dialog.result()==QDialog::Rejected ) return KoFilter::UserCancelled; _options = dialog.options(); } // progress dialog KProgressDialog pd(0, "progress_dialog", i18n("PDF Import"), i18n("Initializing..."), true); pd.setMinimumDuration(0); pd.progressBar()->setTotalSteps( _options.range.nbPages()*2 ); pd.progressBar()->setValue(1); qApp->processEvents(); // if passwords : reread file if ( !_options.ownerPassword.isEmpty() || !_options.userPassword.isEmpty() ) { result = _doc.init(m_chain->inputFile(), _options.ownerPassword, _options.userPassword); if ( result!=KoFilter::OK ) return result; } // data KoPageLayout page; DRect rect = _doc.paperSize(page.format); kdDebug(30516) << "paper size: " << rect.toString() << endl; page.orientation = _doc.paperOrientation(); Data data(m_chain, rect, page, _options); _doc.initDevice(data); // treat pages QTime time; time.start(); SelectionRangeIterator it(_options.range); for (uint k=0; k<2; k++) { bool first = ( k==0 ); data.pageIndex = 0; if ( !first ) _doc.init(); for (it.toFirst(); it.current()!=it.end(); it.next()) { QString s = (first ? i18n("First pass: page #%1...") : i18n("Second pass: page #%1...")); pd.setLabel( s.arg(it.current()) ); qApp->processEvents(); if (pd.wasCancelled()) return KoFilter::UserCancelled; kdDebug(30516) << "-- " << "pass #" << k << " treat page: " << it.current() << "----------------" << endl; if (first) _doc.treatPage( it.current() ); else _doc.dumpPage(data.pageIndex); pd.progressBar()->advance(1); data.pageIndex++; } } data.endDump(); kdDebug(30516) << "treatement elapsed=" << time.elapsed() << endl; // output KoStoreDevice* out = m_chain->storageFile("root", KoStore::Write); if( !out ) { kdError(30516) << "Unable to open output file!" << endl; return KoFilter::StorageCreationError; } // kdDebug(30516) << data.document().toCString() << endl; QCString cstr = data.document().toCString(); out->writeBlock(cstr, cstr.length()); out->close(); treatInfoDocument(); return KoFilter::OK; }