1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "pdffilter.hxx"
21 #include "pdfexport.hxx"
22 #include <comphelper/processfactory.hxx>
23 #include <cppuhelper/supportsservice.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/window.hxx>
26 #include <svl/outstrm.hxx>
27 #include <unotools/ucbstreamhelper.hxx>
28 #include <vcl/FilterConfigItem.hxx>
32 PDFFilter::PDFFilter( const Reference
< XComponentContext
> &rxContext
) :
33 mxContext( rxContext
)
38 PDFFilter::~PDFFilter()
43 bool PDFFilter::implExport( const Sequence
< PropertyValue
>& rDescriptor
)
45 Reference
< XOutputStream
> xOStm
;
46 Sequence
< PropertyValue
> aFilterData
;
47 sal_Int32 nLength
= rDescriptor
.getLength();
48 const PropertyValue
* pValue
= rDescriptor
.getConstArray();
49 bool bIsRedactMode
= false;
51 Reference
< task::XStatusIndicator
> xStatusIndicator
;
52 Reference
< task::XInteractionHandler
> xIH
;
54 for (sal_Int32 i
= 0 ; ( i
< nLength
) && !xOStm
.is(); ++i
)
56 if ( pValue
[ i
].Name
== "OutputStream" )
57 pValue
[ i
].Value
>>= xOStm
;
58 else if ( pValue
[ i
].Name
== "FilterData" )
59 pValue
[ i
].Value
>>= aFilterData
;
60 else if ( pValue
[ i
].Name
== "StatusIndicator" )
61 pValue
[ i
].Value
>>= xStatusIndicator
;
62 else if ( pValue
[i
].Name
== "InteractionHandler" )
63 pValue
[i
].Value
>>= xIH
;
66 for (sal_Int32 i
= 0 ; i
< nLength
; ++i
)
68 if ( pValue
[i
].Name
== "IsRedactMode")
69 pValue
[i
].Value
>>= bIsRedactMode
;
72 /* we don't get FilterData if we are exporting directly
73 to pdf, but we have to use the last user settings (especially for the CompressMode) */
74 if ( !aFilterData
.hasElements() )
76 FilterConfigItem
aCfgItem( "Office.Common/Filter/PDF/Export/" );
77 aCfgItem
.ReadBool( "UseLosslessCompression", false );
78 aCfgItem
.ReadInt32( "Quality", 90 );
79 aCfgItem
.ReadBool( "ReduceImageResolution", false );
80 aCfgItem
.ReadInt32( "MaxImageResolution", 300 );
81 aCfgItem
.ReadBool( "UseTaggedPDF", false );
82 aCfgItem
.ReadInt32( "SelectPdfVersion", 0 );
83 aCfgItem
.ReadBool( "ExportNotes", false );
84 aCfgItem
.ReadBool( "ExportPlaceholders", false );
85 aCfgItem
.ReadBool( "ExportNotesPages", false );
86 aCfgItem
.ReadBool( "ExportOnlyNotesPages", false );
87 aCfgItem
.ReadBool( "UseTransitionEffects", true );
88 aCfgItem
.ReadBool( "IsSkipEmptyPages", false );
89 aCfgItem
.ReadBool( "ExportFormFields", true );
90 aCfgItem
.ReadInt32( "FormsType", 0 );
91 aCfgItem
.ReadBool( "HideViewerToolbar", false );
92 aCfgItem
.ReadBool( "HideViewerMenubar", false );
93 aCfgItem
.ReadBool( "HideViewerWindowControls", false );
94 aCfgItem
.ReadBool( "ResizeWindowToInitialPage", false );
95 aCfgItem
.ReadBool( "CenterWindow", false );
96 aCfgItem
.ReadBool( "OpenInFullScreenMode", false );
97 aCfgItem
.ReadBool( "DisplayPDFDocumentTitle", true );
98 aCfgItem
.ReadInt32( "InitialView", 0 );
99 aCfgItem
.ReadInt32( "Magnification", 0 );
100 aCfgItem
.ReadInt32( "Zoom", 100 );
101 aCfgItem
.ReadInt32( "PageLayout", 0 );
102 aCfgItem
.ReadBool( "FirstPageOnLeft", false );
103 aCfgItem
.ReadInt32( "InitialPage", 1 );
104 aCfgItem
.ReadBool( "IsAddStream", false );
106 // the encryption is not available when exporting directly, since the encryption is off by default and the selection
107 // (encrypt or not) is not persistent; it's available through macro though,
108 // provided the correct property values are set, see help
110 // now, the relative link stuff
111 aCfgItem
.ReadBool( "ExportLinksRelativeFsys", false );
112 aCfgItem
.ReadInt32("PDFViewSelection", 0 );
113 aCfgItem
.ReadBool( "ConvertOOoTargetToPDFTarget", false );
114 aCfgItem
.ReadBool( "ExportBookmarksToPDFDestination", false );
116 aCfgItem
.ReadBool( "ExportBookmarks", true );
117 aCfgItem
.ReadBool( "ExportHiddenSlides", false );
118 aCfgItem
.ReadBool( "SinglePageSheets", false );
119 aCfgItem
.ReadInt32( "OpenBookmarkLevels", -1 );
121 aCfgItem
.ReadBool( "IsRedactMode", false);
123 aFilterData
= aCfgItem
.GetFilterData();
131 for (int i
= 0; i
< aFilterData
.getLength(); ++i
)
133 if (aFilterData
[i
].Name
== "IsRedactMode")
135 aFilterData
[i
].Value
<<= bIsRedactMode
;
143 sal_Int32 nNewSize
= aFilterData
.getLength() + 1;
144 aFilterData
.realloc( nNewSize
);
145 aFilterData
[nNewSize
- 1].Name
= "IsRedactMode";
146 aFilterData
[nNewSize
- 1].Value
<<= bIsRedactMode
;
150 if( mxSrcDoc
.is() && xOStm
.is() )
152 PDFExport
aExport( mxSrcDoc
, xStatusIndicator
, xIH
, mxContext
);
153 ::utl::TempFile aTempFile
;
155 aTempFile
.EnableKillingFile();
156 bRet
= aExport
.Export( aTempFile
.GetURL(), aFilterData
);
160 std::unique_ptr
<SvStream
> pIStm(::utl::UcbStreamHelper::CreateStream( aTempFile
.GetURL(), StreamMode::READ
));
164 SvOutputStream
aOStm( xOStm
);
166 aOStm
.WriteStream( *pIStm
);
167 bRet
= ( aOStm
.Tell() && ( aOStm
.GetError() == ERRCODE_NONE
) );
176 class FocusWindowWaitCursor
180 VclPtr
<vcl::Window
> m_pFocusWindow
;
183 FocusWindowWaitCursor() :
184 m_pFocusWindow( Application::GetFocusWindow() )
188 m_pFocusWindow
->AddEventListener( LINK( this, FocusWindowWaitCursor
, DestroyedLink
) );
189 m_pFocusWindow
->EnterWait();
193 ~FocusWindowWaitCursor()
197 m_pFocusWindow
->LeaveWait();
198 m_pFocusWindow
->RemoveEventListener( LINK( this, FocusWindowWaitCursor
, DestroyedLink
) );
202 DECL_LINK( DestroyedLink
, VclWindowEvent
&, void );
206 IMPL_LINK( FocusWindowWaitCursor
, DestroyedLink
, VclWindowEvent
&, rEvent
, void )
208 if( rEvent
.GetId() == VclEventId::ObjectDying
)
209 m_pFocusWindow
= nullptr;
213 sal_Bool SAL_CALL
PDFFilter::filter( const Sequence
< PropertyValue
>& rDescriptor
)
215 FocusWindowWaitCursor aCur
;
217 const bool bRet
= implExport( rDescriptor
);
223 void SAL_CALL
PDFFilter::cancel( )
228 void SAL_CALL
PDFFilter::setSourceDocument( const Reference
< XComponent
>& xDoc
)
234 void SAL_CALL
PDFFilter::initialize( const css::uno::Sequence
< css::uno::Any
>& )
239 OUString
PDFFilter_getImplementationName ()
241 return "com.sun.star.comp.PDF.PDFFilter";
245 Sequence
< OUString
> PDFFilter_getSupportedServiceNames( )
247 Sequence
<OUString
> aRet
{ "com.sun.star.document.PDFFilter" };
252 Reference
< XInterface
> PDFFilter_createInstance( const Reference
< XMultiServiceFactory
> & rSMgr
)
254 return static_cast<cppu::OWeakObject
*>(new PDFFilter( comphelper::getComponentContext(rSMgr
) ));
258 OUString SAL_CALL
PDFFilter::getImplementationName()
260 return PDFFilter_getImplementationName();
264 sal_Bool SAL_CALL
PDFFilter::supportsService( const OUString
& rServiceName
)
266 return cppu::supportsService( this, rServiceName
);
270 css::uno::Sequence
< OUString
> SAL_CALL
PDFFilter::getSupportedServiceNames( )
272 return PDFFilter_getSupportedServiceNames();
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */