Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "pdffilter.hxx"
21 : #include "pdfexport.hxx"
22 : #include <cppuhelper/supportsservice.hxx>
23 : #include <vcl/svapp.hxx>
24 : #include <vcl/window.hxx>
25 : #include <svl/outstrm.hxx>
26 : #include <vcl/FilterConfigItem.hxx>
27 : #include <boost/scoped_ptr.hpp>
28 :
29 : // - PDFFilter -
30 0 : PDFFilter::PDFFilter( const Reference< XComponentContext > &rxContext ) :
31 0 : mxContext( rxContext )
32 : {
33 0 : }
34 :
35 0 : PDFFilter::~PDFFilter()
36 : {
37 0 : }
38 :
39 0 : bool PDFFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
40 : {
41 0 : Reference< XOutputStream > xOStm;
42 0 : Sequence< PropertyValue > aFilterData;
43 0 : sal_Int32 nLength = rDescriptor.getLength();
44 0 : const PropertyValue* pValue = rDescriptor.getConstArray();
45 0 : bool bRet = false;
46 0 : Reference< task::XStatusIndicator > xStatusIndicator;
47 0 : Reference< task::XInteractionHandler > xIH;
48 :
49 0 : for ( sal_Int32 i = 0 ; ( i < nLength ) && !xOStm.is(); ++i)
50 : {
51 0 : if ( pValue[ i ].Name == "OutputStream" )
52 0 : pValue[ i ].Value >>= xOStm;
53 0 : else if ( pValue[ i ].Name == "FilterData" )
54 0 : pValue[ i ].Value >>= aFilterData;
55 0 : else if ( pValue[ i ].Name == "StatusIndicator" )
56 0 : pValue[ i ].Value >>= xStatusIndicator;
57 0 : else if ( pValue[i].Name == "InteractionHandler" )
58 0 : pValue[i].Value >>= xIH;
59 : }
60 :
61 : /* we don't get FilterData if we are exporting directly
62 : to pdf, but we have to use the last user settings (especially for the CompressMode) */
63 0 : if ( !aFilterData.getLength() )
64 : {
65 0 : FilterConfigItem aCfgItem( "Office.Common/Filter/PDF/Export/" );
66 0 : aCfgItem.ReadBool( "UseLosslessCompression", false );
67 0 : aCfgItem.ReadInt32( "Quality", 90 );
68 0 : aCfgItem.ReadBool( "ReduceImageResolution", false );
69 0 : aCfgItem.ReadInt32( "MaxImageResolution", 300 );
70 0 : aCfgItem.ReadBool( "UseTaggedPDF", false );
71 0 : aCfgItem.ReadInt32( "SelectPdfVersion", 0 );
72 0 : aCfgItem.ReadBool( "ExportNotes", false );
73 0 : aCfgItem.ReadBool( "ExportNotesPages", false );
74 0 : aCfgItem.ReadBool( "UseTransitionEffects", true );
75 0 : aCfgItem.ReadBool( "IsSkipEmptyPages", false );
76 0 : aCfgItem.ReadBool( "ExportFormFields", true );
77 0 : aCfgItem.ReadInt32( "FormsType", 0 );
78 0 : aCfgItem.ReadBool( "HideViewerToolbar", false );
79 0 : aCfgItem.ReadBool( "HideViewerMenubar", false );
80 0 : aCfgItem.ReadBool( "HideViewerWindowControls", false );
81 0 : aCfgItem.ReadBool( "ResizeWindowToInitialPage", false );
82 0 : aCfgItem.ReadBool( "CenterWindow", false );
83 0 : aCfgItem.ReadBool( "OpenInFullScreenMode", false );
84 0 : aCfgItem.ReadBool( "DisplayPDFDocumentTitle", true );
85 0 : aCfgItem.ReadInt32( "InitialView", 0 );
86 0 : aCfgItem.ReadInt32( "Magnification", 0 );
87 0 : aCfgItem.ReadInt32( "PageLayout", 0 );
88 0 : aCfgItem.ReadBool( "FirstPageOnLeft", false );
89 0 : aCfgItem.ReadBool( "IsAddStream", false );
90 : //
91 : // the encryption is not available when exporting directly, since the encryption is off by default and the selection
92 : // (encrypt or not) is not persistent; it's available through macro though,
93 : // provided the correct property values are set, see help
94 : //
95 : // now, the relative link stuff
96 0 : aCfgItem.ReadBool( "ExportLinksRelativeFsys", false );
97 0 : aCfgItem.ReadInt32("PDFViewSelection", 0 );
98 0 : aCfgItem.ReadBool( "ConvertOOoTargetToPDFTarget", false );
99 0 : aCfgItem.ReadBool( "ExportBookmarksToPDFDestination", false );
100 :
101 0 : aCfgItem.ReadBool( "ExportBookmarks", true );
102 0 : aCfgItem.ReadBool( "ExportHiddenSlides", false );
103 0 : aCfgItem.ReadInt32( "OpenBookmarkLevels", -1 );
104 0 : aFilterData = aCfgItem.GetFilterData();
105 : }
106 0 : if( mxSrcDoc.is() && xOStm.is() )
107 : {
108 0 : PDFExport aExport( mxSrcDoc, xStatusIndicator, xIH, mxContext );
109 0 : ::utl::TempFile aTempFile;
110 :
111 0 : aTempFile.EnableKillingFile();
112 0 : bRet = aExport.Export( aTempFile.GetURL(), aFilterData );
113 :
114 0 : if( bRet )
115 : {
116 0 : boost::scoped_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ ));
117 :
118 0 : if( pIStm )
119 : {
120 0 : SvOutputStream aOStm( xOStm );
121 :
122 0 : aOStm.WriteStream( *pIStm );
123 0 : bRet = ( aOStm.Tell() && ( aOStm.GetError() == ERRCODE_NONE ) );
124 0 : }
125 0 : }
126 : }
127 :
128 0 : return bRet;
129 : }
130 :
131 :
132 : class FocusWindowWaitCursor
133 : {
134 : vcl::Window* m_pFocusWindow;
135 : public:
136 0 : FocusWindowWaitCursor() :
137 0 : m_pFocusWindow( Application::GetFocusWindow() )
138 : {
139 0 : if( m_pFocusWindow )
140 : {
141 0 : m_pFocusWindow->AddEventListener( LINK( this, FocusWindowWaitCursor, DestroyedLink ) );
142 0 : m_pFocusWindow->EnterWait();
143 : }
144 0 : }
145 0 : ~FocusWindowWaitCursor()
146 : {
147 0 : if( m_pFocusWindow )
148 : {
149 0 : m_pFocusWindow->LeaveWait();
150 0 : m_pFocusWindow->RemoveEventListener( LINK( this, FocusWindowWaitCursor, DestroyedLink ) );
151 : }
152 0 : }
153 :
154 : DECL_LINK( DestroyedLink, VclWindowEvent* );
155 : };
156 :
157 0 : IMPL_LINK( FocusWindowWaitCursor, DestroyedLink, VclWindowEvent*, pEvent )
158 : {
159 0 : if( pEvent->GetId() == VCLEVENT_OBJECT_DYING )
160 0 : m_pFocusWindow = NULL;
161 0 : return 0;
162 : }
163 :
164 0 : sal_Bool SAL_CALL PDFFilter::filter( const Sequence< PropertyValue >& rDescriptor )
165 : throw (RuntimeException, std::exception)
166 : {
167 0 : FocusWindowWaitCursor aCur;
168 :
169 0 : const bool bRet = implExport( rDescriptor );
170 :
171 0 : return bRet;
172 : }
173 :
174 :
175 :
176 0 : void SAL_CALL PDFFilter::cancel( ) throw (RuntimeException, std::exception)
177 : {
178 0 : }
179 :
180 :
181 :
182 0 : void SAL_CALL PDFFilter::setSourceDocument( const Reference< XComponent >& xDoc )
183 : throw (IllegalArgumentException, RuntimeException, std::exception)
184 : {
185 0 : mxSrcDoc = xDoc;
186 0 : }
187 :
188 :
189 :
190 0 : void SAL_CALL PDFFilter::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& )
191 : throw (Exception, RuntimeException, std::exception)
192 : {
193 0 : }
194 :
195 0 : OUString PDFFilter_getImplementationName ()
196 : throw (RuntimeException)
197 : {
198 0 : return OUString ( "com.sun.star.comp.PDF.PDFFilter" );
199 : }
200 :
201 0 : Sequence< OUString > SAL_CALL PDFFilter_getSupportedServiceNames( ) throw (RuntimeException)
202 : {
203 0 : Sequence < OUString > aRet(1);
204 0 : OUString* pArray = aRet.getArray();
205 0 : pArray[0] = "com.sun.star.document.PDFFilter";
206 0 : return aRet;
207 : }
208 :
209 0 : Reference< XInterface > SAL_CALL PDFFilter_createInstance( const Reference< XMultiServiceFactory > & rSMgr) throw( Exception )
210 : {
211 0 : return (cppu::OWeakObject*) new PDFFilter( comphelper::getComponentContext(rSMgr) );
212 : }
213 :
214 :
215 :
216 0 : OUString SAL_CALL PDFFilter::getImplementationName()
217 : throw (RuntimeException, std::exception)
218 : {
219 0 : return PDFFilter_getImplementationName();
220 : }
221 :
222 :
223 :
224 0 : sal_Bool SAL_CALL PDFFilter::supportsService( const OUString& rServiceName )
225 : throw (RuntimeException, std::exception)
226 : {
227 0 : return cppu::supportsService( this, rServiceName );
228 : }
229 :
230 :
231 :
232 0 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL PDFFilter::getSupportedServiceNames( ) throw (RuntimeException, std::exception)
233 : {
234 0 : return PDFFilter_getSupportedServiceNames();
235 0 : }
236 :
237 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|