33#include <com/sun/star/lang/IllegalArgumentException.hpp>
34#include <com/sun/star/lang/XMultiComponentFactory.hpp>
35#include <com/sun/star/io/XSeekable.hpp>
57 uno::Reference< io::XStream > xSubStream;
59 const beans::PropertyValue* pAttribs = rFilterData.getConstArray();
60 sal_Int32 nAttribs = rFilterData.getLength();
61 sal_Int32 nPwPos = -1;
62 for( sal_Int32
i = 0;
i < nAttribs;
i++ )
64 SAL_INFO(
"sdext.pdfimport",
"filter: Attrib: " << pAttribs[
i].
Name
65 <<
" = " << (pAttribs[
i].
Value.has<OUString>()
66 ? pAttribs[
i].Value.get<OUString>()
67 : OUString(
"<no string>"))
69 if ( pAttribs[
i].
Name ==
"EmbeddedSubstream" )
70 pAttribs[
i].Value >>= xSubStream;
71 else if ( pAttribs[
i].
Name ==
"Password" )
74 pAttribs[
i].Value >>= aPwd;
77 bool bAddPwdProp =
false;
78 if( ! xSubStream.is() )
80 uno::Reference< io::XInputStream > xInput;
81 auto pAttr = std::find_if(rFilterData.begin(), rFilterData.end(),
82 [](
const beans::PropertyValue& rAttr) { return rAttr.Name ==
"InputStream"; });
83 if (pAttr != rFilterData.end())
84 pAttr->Value >>= xInput;
88 uno::Reference< io::XSeekable > xSeek( xInput, uno::UNO_QUERY );
91 oslFileHandle aFile =
nullptr;
92 sal_uInt64 nWritten = 0;
94 if( osl_createTempFile(
nullptr, &aFile, &
aURL.pData ) == osl_File_E_None )
96 SAL_INFO(
"sdext.pdfimport",
"created temp file " <<
aURL);
97 const sal_Int32 nBufSize = 4096;
98 uno::Sequence<sal_Int8>
aBuf(nBufSize);
103 nBytes = xInput->readBytes(
aBuf, nBufSize );
106 osl_writeFile( aFile,
aBuf.getConstArray(), nBytes, &nWritten );
107 if(
static_cast<sal_Int32
>(nWritten) != nBytes )
113 }
while( nBytes == nBufSize );
114 osl_closeFile( aFile );
117 OUString aEmbedMimetype;
118 OUString aOrgPwd( aPwd );
120 if( aOrgPwd != aPwd )
123 osl_removeFile(
aURL.pData );
129 if( xSubStream.is() )
133 SAL_INFO(
"sdext.pdfimport",
"try to instantiate subfilter" );
134 uno::Reference< document::XFilter > xSubFilter;
137 m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
138 "com.sun.star.document.OwnSubFilter",
143 catch(
const uno::Exception&)
148 SAL_INFO(
"sdext.pdfimport",
"subfilter: " << xSubFilter.get() );
149 if( xSubFilter.is() )
153 uno::Sequence<beans::PropertyValue> aFilterData( rFilterData );
156 nPwPos = aFilterData.getLength();
157 aFilterData.realloc( nPwPos+1 );
158 aFilterData.getArray()[nPwPos].Name =
"Password";
160 aFilterData.getArray()[nPwPos].Value <<= aPwd;
161 bRet = xSubFilter->filter( aFilterData );
164 bRet = xSubFilter->filter( rFilterData );
168 SAL_INFO(
"sdext.pdfimport",
"PDFIAdaptor::filter: no embedded substream set" );
171 SAL_INFO(
"sdext.pdfimport",
"PDFIAdaptor::filter: no model set" );
183 SAL_INFO(
"sdext.pdfimport",
"PDFIAdaptor::setTargetDocument" );
184 m_xModel.set( xDocument, uno::UNO_QUERY );
185 if( xDocument.is() && !
m_xModel.is() )
186 throw lang::IllegalArgumentException();
191 return "org.libreoffice.comp.documents.HybridPDFImport";
201 return {
"com.sun.star.document.ImportFilter"};
216 const uno::Reference<task::XInteractionHandler>& xIHdl,
217 const OUString& rPwd,
218 const uno::Reference<task::XStatusIndicator>& xStatus,
220 const OUString& rURL,
221 const OUString& rFilterOptions )
224 auto pSink = std::make_shared<PDFIProcessor>(xStatus,
m_xContext);
242 const uno::Reference<io::XOutputStream>& xOutput,
243 const uno::Reference<task::XStatusIndicator>& xStatus )
246 const bool bSuccess =
parse(uno::Reference<io::XInputStream>(),
247 uno::Reference<task::XInteractionHandler>(),
249 xStatus,pEmitter,rURL,
"");
252 xOutput->closeOutput();
259 const uno::Reference< xml::sax::XDocumentHandler >& rHdl,
260 const uno::Sequence< OUString >& )
263 uno::Reference< io::XInputStream > xInput;
264 uno::Reference< task::XStatusIndicator > xStatus;
265 uno::Reference< task::XInteractionHandler > xInteractionHandler;
268 OUString aFilterOptions;
269 for(
const beans::PropertyValue& rAttrib : rSourceData )
271 SAL_INFO(
"sdext.pdfimport",
"importer Attrib: " << rAttrib.Name );
272 if ( rAttrib.Name ==
"InputStream" )
273 rAttrib.Value >>= xInput;
274 else if ( rAttrib.Name ==
"URL" )
275 rAttrib.Value >>=
aURL;
276 else if ( rAttrib.Name ==
"StatusIndicator" )
277 rAttrib.Value >>= xStatus;
278 else if ( rAttrib.Name ==
"InteractionHandler" )
279 rAttrib.Value >>= xInteractionHandler;
280 else if ( rAttrib.Name ==
"Password" )
281 rAttrib.Value >>= aPwd;
282 else if ( rAttrib.Name ==
"FilterOptions" )
283 rAttrib.Value >>= aFilterOptions;
289 const bool bSuccess =
parse(xInput, xInteractionHandler,
290 aPwd, xStatus, pEmitter,
aURL, aFilterOptions);
293 xInput->closeInput();
302 SAL_INFO(
"sdext.pdfimport",
"PDFIAdaptor::setTargetDocument" );
303 m_xModel.set( xDocument, uno::UNO_QUERY );
304 if( xDocument.is() && !
m_xModel.is() )
305 throw lang::IllegalArgumentException();
320 return {
"com.sun.star.document.ImportFilter"};
325extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
327 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any>
const&)
332 return getXWeak(pAdaptor.get());
335extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
337 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any>
const&)
342 return getXWeak(pAdaptor.get());
345extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
347 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any>
const&)
352 return getXWeak(pAdaptor.get());
355extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
357 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any>
const&)
virtual void SAL_CALL cancel() override
sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL filter(const css::uno::Sequence< css::beans::PropertyValue > &rFilterData) override
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &xDocument) override
OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::uno::XComponentContext > m_xContext
PDFIHybridAdaptor(const css::uno::Reference< css::uno::XComponentContext > &xContext)
css::uno::Reference< css::frame::XModel > m_xModel
Adapts raw pdf import to XImportFilter interface.
bool parse(const css::uno::Reference< css::io::XInputStream > &xInput, const css::uno::Reference< css::task::XInteractionHandler > &xIHdl, const OUString &rPwd, const css::uno::Reference< css::task::XStatusIndicator > &xStatus, const XmlEmitterSharedPtr &rEmitter, const OUString &rURL, const OUString &rFilterOptions)
bool odfConvert(const OUString &rURL, const css::uno::Reference< css::io::XOutputStream > &xOutput, const css::uno::Reference< css::task::XStatusIndicator > &xStatus)
Export pdf document to ODG.
css::uno::Reference< css::frame::XModel > m_xModel
virtual void SAL_CALL setTargetDocument(const css::uno::Reference< css::lang::XComponent > &xDocument) override
TreeVisitorFactorySharedPtr m_pVisitorFactory
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void setTreeVisitorFactory(const TreeVisitorFactorySharedPtr &rVisitorFactory)
Set factory object used to create the tree visitors.
PDFIRawAdaptor(OUString const &implementationName, const css::uno::Reference< css::uno::XComponentContext > &xContext)
css::uno::Reference< css::uno::XComponentContext > m_xContext
OUString SAL_CALL getImplementationName() override
sal_Bool SAL_CALL supportsService(OUString const &ServiceName) override
OUString const m_implementationName
virtual sal_Bool SAL_CALL importer(const css::uno::Sequence< css::beans::PropertyValue > &rSourceData, const css::uno::Reference< css::xml::sax::XDocumentHandler > &rHdl, const css::uno::Sequence< OUString > &rUserData) override
#define TOOLS_INFO_EXCEPTION(area, stream)
#define SAL_INFO(area, stream)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral implementationName
XmlEmitterSharedPtr createSaxEmitter(const css::uno::Reference< css::xml::sax::XDocumentHandler > &xDocHdl)
bool xpdf_ImportFromStream(const css::uno::Reference< css::io::XInputStream > &xInput, const ContentSinkSharedPtr &rSink, const css::uno::Reference< css::task::XInteractionHandler > &xIHdl, const OUString &rPwd, const css::uno::Reference< css::uno::XComponentContext > &xContext, const OUString &rFilterOptions)
bool xpdf_ImportFromFile(const OUString &rURL, const ContentSinkSharedPtr &rSink, const css::uno::Reference< css::task::XInteractionHandler > &xIHdl, const OUString &rPwd, const css::uno::Reference< css::uno::XComponentContext > &xContext, const OUString &rFilterOptions)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * sdext_PDFIRawAdaptor_Writer_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
uno::Reference< io::XStream > getAdditionalStream(const OUString &rInPDFFileURL, OUString &rOutMimetype, OUString &io_rPwd, const uno::Reference< uno::XComponentContext > &xContext, const uno::Sequence< beans::PropertyValue > &rFilterData, bool bMayUseUI)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * sdext_PDFIRawAdaptor_Draw_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
XmlEmitterSharedPtr createOdfEmitter(const css::uno::Reference< css::io::XOutputStream > &xOut)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * sdext_PDFIRawAdaptor_Impress_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
std::shared_ptr< TreeVisitorFactory > TreeVisitorFactorySharedPtr
TreeVisitorFactorySharedPtr createWriterTreeVisitorFactory()
TreeVisitorFactorySharedPtr createDrawTreeVisitorFactory()
std::shared_ptr< XmlEmitter > XmlEmitterSharedPtr
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * sdext_PDFIHybridAdaptor_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
TreeVisitorFactorySharedPtr createImpressTreeVisitorFactory()
const uno::Reference< uno::XComponentContext > m_xContext