21#include "pdfimport.moc"
24#include <tqdatetime.h>
26#include <KoFilterChain.h>
27#include <kgenericfactory.h>
31#include <tdeapplication.h>
37using namespace PDFImport;
40class PdfImportFactory : KGenericFactory<PdfImport, KoFilter>
44 : KGenericFactory<PdfImport, KoFilter>(
"kwordpdfimport") {}
47 virtual void setupTranslations() {
48 TDEGlobal::locale()->insertCatalogue(
"kofficefilters");
52K_EXPORT_COMPONENT_FACTORY(libpdfimport, PdfImportFactory())
55PdfImport::PdfImport(KoFilter *, const
char *, const TQStringList&)
58KoFilter::ConversionStatus PdfImport::convert(
const TQCString& from,
62 if ( to!=
"application/x-kword" || from!=
"application/pdf" )
63 return KoFilter::NotImplemented;
66 KoFilter::ConversionStatus result
67 = _doc.init(m_chain->inputFile(), TQString(), TQString());
68 if ( result!=KoFilter::OK )
return result;
72 Dialog dialog(_doc.nbPages(), _doc.isEncrypted(), 0);
74 if ( dialog.result()==TQDialog::Rejected )
75 return KoFilter::UserCancelled;
76 _options = dialog.options();
80 KProgressDialog pd(0,
"progress_dialog", i18n(
"PDF Import"),
81 i18n(
"Initializing..."),
true);
82 pd.setMinimumDuration(0);
83 pd.progressBar()->setTotalSteps( _options.range.nbPages()*2 );
84 pd.progressBar()->setValue(1);
85 tqApp->processEvents();
88 if ( !_options.ownerPassword.isEmpty()
89 || !_options.userPassword.isEmpty() ) {
90 result = _doc.init(m_chain->inputFile(), _options.ownerPassword,
91 _options.userPassword);
92 if ( result!=KoFilter::OK )
return result;
97 DRect rect = _doc.paperSize(page.format);
98 kdDebug(30516) <<
"paper size: " << rect.toString() << endl;
99 page.orientation = _doc.paperOrientation();
100 Data data(m_chain, rect, page, _options);
101 _doc.initDevice(data);
106 SelectionRangeIterator it(_options.range);
107 for (uint k=0; k<2; k++) {
108 bool first = ( k==0 );
110 if ( !first ) _doc.init();
111 for (it.toFirst(); it.current()!=it.end(); it.next()) {
112 TQString s = (first ? i18n(
"First pass: page #%1...")
113 : i18n(
"Second pass: page #%1..."));
114 pd.setLabel( s.arg(it.current()) );
115 tqApp->processEvents();
116 if (pd.wasCancelled())
return KoFilter::UserCancelled;
117 kdDebug(30516) <<
"-- " <<
"pass #" << k
118 <<
" treat page: " << it.current()
119 <<
"----------------" << endl;
120 if (first) _doc.treatPage( it.current() );
121 else _doc.dumpPage(data.pageIndex);
122 pd.progressBar()->advance(1);
127 kdDebug(30516) <<
"treatement elapsed=" << time.elapsed() << endl;
130 KoStoreDevice* out = m_chain->storageFile(
"root", KoStore::Write);
132 kdError(30516) <<
"Unable to open output file!" << endl;
133 return KoFilter::StorageCreationError;
136 TQCString cstr = data.document().toCString();
137 out->writeBlock(cstr, cstr.length());
145void PdfImport::treatInfoDocument()
147 TQDomDocument infoDocument(
"document-info");
148 infoDocument.appendChild(
149 infoDocument.createProcessingInstruction(
150 "xml",
"version=\"1.0\" encoding=\"UTF-8\""));
151 TQDomElement infoElement = infoDocument.createElement(
"document-info" );
152 infoDocument.appendChild(infoElement);
154 TQDomElement aboutTag = infoDocument.createElement(
"about");
155 infoElement.appendChild(aboutTag);
157 TQDomElement authorTag = infoDocument.createElement(
"author");
158 infoElement.appendChild(authorTag);
159 TQDomElement fullNameTag = infoDocument.createElement(
"full-name");
160 authorTag.appendChild(fullNameTag);
161 TQDomText authorText = infoDocument.createTextNode( _doc.info(
"Author") );
162 fullNameTag.appendChild(authorText);
164 TQDomElement titleTag = infoDocument.createElement(
"title");
165 aboutTag.appendChild(titleTag);
166 TQDomText titleText = infoDocument.createTextNode( _doc.info(
"Title") );
167 titleTag.appendChild(titleText);
171 m_chain->storageFile(
"documentinfo.xml", KoStore::Write);
173 kdWarning(30516) <<
"unable to open doc info. continuing anyway\n";
175 TQCString cstr = infoDocument.toCString();
176 out->writeBlock(cstr, cstr.length());