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 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; }
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; }
KoFilter::ConversionStatus Odp2Kpr::convert( const QByteArray& from, const QByteArray& to ) { if ( to != "application/x-kpresenter" || from != "application/vnd.oasis.opendocument.presentation" ) return KoFilter::NotImplemented; KoStoreDevice* inpdev = m_chain->storageFile( "content.xml", KoStore::Read ); if ( !inpdev ) { kError(31000) << "Unable to open input stream"; return KoFilter::StorageCreationError; } // Parse presentation content.xml QXmlInputSource source( inpdev ); QXmlSimpleReader reader; KoOdfReadStore::setupXmlReader( reader, true /*namespaceProcessing*/ ); QString errorMsg; int errorLine, errorColumn; bool ok = doc.setContent( &source, &reader, &errorMsg, &errorLine, &errorColumn ); if ( !ok ) { kError(31000) << "Parsing error! Aborting!" << endl << " In line: " << errorLine << ", column: " << errorColumn << endl << " Error message: " << errorMsg; return KoFilter::ParsingError; } QDomElement docElem = doc.documentElement(); QDomElement realBody( KoDom::namedItemNS( docElem, KoXmlNS::office, "body" ) ); if ( realBody.isNull() ) { kError(31000) << "No office:body found!"; //setErrorMessage( i18n( "Invalid OASIS OpenDocument file. No office:body tag found." ) ); return KoFilter::WrongFormat; } QDomElement body = KoDom::namedItemNS( realBody, KoXmlNS::office, "presentation" ); if ( body.isNull() ) { kError(32001) << "No office:text found!"; return KoFilter::WrongFormat; } //now we can transform it. //Parse meta.xml directly inpdev = m_chain->storageFile( "meta.xml", KoStore::Read ); KoXmlDocument metaDoc; QString errorMessage; KoDocumentInfo info; if ( KoOdfReadStore::loadAndParse( inpdev, metaDoc, errorMessage, "meta.xml" /*just for debug message*/ ) ) { info.loadOasis( metaDoc ); } // Write output file KoStoreDevice* out = m_chain->storageFile( "root", KoStore::Write ); if(!out) { kError(30502) << "Unable to open output file!"; return KoFilter::StorageCreationError; } QByteArray cstring = outdoc.toByteArray(); // utf-8 already out->write( cstring.data(), cstring.length() ); out->close(); //Write documentinfo.xml out = m_chain->storageFile( "documentinfo.xml", KoStore::Write ); if(!out) { kError(30502) << "Unable to open output file!"; return KoFilter::StorageCreationError; } QDomDocument doc = info.save(); QByteArray s = doc.toByteArray(); // this is already Utf8! out->write( cstring.data(), cstring.length() ); out->close(); return KoFilter::OK; }