update dev300-m58
[ooovba.git] / filter / source / pdf / pdffilter.cxx
blobc672545fc3d2daf72d1c14220e7a9e7af3476753
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pdffilter.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_filter.hxx"
34 #include "pdffilter.hxx"
35 #include "pdfexport.hxx"
36 #include <vcl/svapp.hxx>
37 #include <vcl/window.hxx>
38 #include <svtools/outstrm.hxx>
39 #include <svtools/FilterConfigItem.hxx>
41 // -------------
42 // - PDFFilter -
43 // -------------
45 PDFFilter::PDFFilter( const Reference< XMultiServiceFactory > &rxMSF ) :
46 mxMSF( rxMSF )
50 // -----------------------------------------------------------------------------
52 PDFFilter::~PDFFilter()
56 // -----------------------------------------------------------------------------
58 sal_Bool PDFFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
60 Reference< XOutputStream > xOStm;
61 Sequence< PropertyValue > aFilterData;
62 sal_Int32 nLength = rDescriptor.getLength();
63 const PropertyValue* pValue = rDescriptor.getConstArray();
64 sal_Bool bRet = sal_False;
65 Reference< task::XStatusIndicator > xStatusIndicator;
67 for ( sal_Int32 i = 0 ; ( i < nLength ) && !xOStm.is(); ++i)
69 if( pValue[ i ].Name.equalsAscii( "OutputStream" ) )
70 pValue[ i ].Value >>= xOStm;
71 else if( pValue[ i ].Name.equalsAscii( "FilterData" ) )
72 pValue[ i ].Value >>= aFilterData;
73 else if ( pValue[ i ].Name.equalsAscii( "StatusIndicator" ) )
74 pValue[ i ].Value >>= xStatusIndicator;
77 /* we don't get FilterData if we are exporting directly
78 to pdf, but we have to use the last user settings (especially for the CompressMode) */
79 if ( !aFilterData.getLength() )
81 FilterConfigItem aCfgItem( String( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/PDF/Export/" ) ) );
82 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "UseLosslessCompression" ) ), sal_False );
83 aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Quality" ) ), 90 );
84 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ReduceImageResolution" ) ), sal_False );
85 aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "MaxImageResolution" ) ), 300 );
86 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "UseTaggedPDF" ) ), sal_False );
87 aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "SelectPdfVersion" ) ), 0 );
88 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ExportNotes" ) ), sal_True );
89 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "UseTransitionEffects" ) ), sal_True );
90 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "IsSkipEmptyPages" ) ), sal_False );
91 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ExportFormFields" ) ), sal_True );
92 aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "FormsType" ) ), 0 );
93 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "HideViewerToolbar" ) ), sal_False );
94 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "HideViewerMenubar" ) ), sal_False );
95 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "HideViewerWindowControls" ) ), sal_False );
96 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ResizeWindowToInitialPage" ) ), sal_False );
97 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "CenterWindow" ) ), sal_False );
98 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "OpenInFullScreenMode" ) ), sal_False );
99 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "DisplayPDFDocumentTitle" ) ), sal_True );
100 aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "InitialView" ) ), 0 );
101 aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "Magnification" ) ), 0 );
102 aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "PageLayout" ) ), 0 );
103 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "FirstPageOnLeft" ) ), sal_False );
104 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "IsAddStream" ) ), sal_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( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportLinksRelativeFsys" ) ), sal_False );
112 aCfgItem.ReadInt32( OUString( RTL_CONSTASCII_USTRINGPARAM( "PDFViewSelection" ) ), 0 );
113 aCfgItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ConvertOOoTargetToPDFTarget" ) ), sal_False );
114 aCfgItem.ReadBool( OUString( RTL_CONSTASCII_USTRINGPARAM( "ExportBookmarksToPDFDestination" ) ), sal_False );
116 aCfgItem.ReadBool( String( RTL_CONSTASCII_USTRINGPARAM( "ExportBookmarks" ) ), sal_True );
117 aCfgItem.ReadInt32( String( RTL_CONSTASCII_USTRINGPARAM( "OpenBookmarkLevels" ) ), -1 );
118 aFilterData = aCfgItem.GetFilterData();
120 if( mxSrcDoc.is() && xOStm.is() )
122 PDFExport aExport( mxSrcDoc, xStatusIndicator, mxMSF );
123 ::utl::TempFile aTempFile;
125 aTempFile.EnableKillingFile();
126 bRet = aExport.Export( aTempFile.GetURL(), aFilterData );
128 if( bRet )
130 SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ );
132 if( pIStm )
134 SvOutputStream aOStm( xOStm );
136 aOStm << *pIStm;
137 bRet = ( aOStm.Tell() && ( aOStm.GetError() == ERRCODE_NONE ) );
139 delete pIStm;
144 return bRet;
147 // -----------------------------------------------------------------------------
148 class FocusWindowWaitCursor
150 Window* m_pFocusWindow;
151 public:
152 FocusWindowWaitCursor() :
153 m_pFocusWindow( Application::GetFocusWindow() )
155 if( m_pFocusWindow )
157 m_pFocusWindow->AddEventListener( LINK( this, FocusWindowWaitCursor, DestroyedLink ) );
158 m_pFocusWindow->EnterWait();
161 ~FocusWindowWaitCursor()
163 if( m_pFocusWindow )
165 m_pFocusWindow->LeaveWait();
166 m_pFocusWindow->RemoveEventListener( LINK( this, FocusWindowWaitCursor, DestroyedLink ) );
170 DECL_LINK( DestroyedLink, VclWindowEvent* );
173 IMPL_LINK( FocusWindowWaitCursor, DestroyedLink, VclWindowEvent*, pEvent )
175 if( pEvent->GetId() == VCLEVENT_OBJECT_DYING )
176 m_pFocusWindow = NULL;
177 return 0;
180 sal_Bool SAL_CALL PDFFilter::filter( const Sequence< PropertyValue >& rDescriptor )
181 throw (RuntimeException)
183 FocusWindowWaitCursor aCur;
185 const sal_Bool bRet = implExport( rDescriptor );
187 return bRet;
190 // -----------------------------------------------------------------------------
192 void SAL_CALL PDFFilter::cancel( ) throw (RuntimeException)
196 // -----------------------------------------------------------------------------
198 void SAL_CALL PDFFilter::setSourceDocument( const Reference< XComponent >& xDoc )
199 throw (IllegalArgumentException, RuntimeException)
201 mxSrcDoc = xDoc;
204 // -----------------------------------------------------------------------------
206 void SAL_CALL PDFFilter::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& )
207 throw (Exception, RuntimeException)
211 // -----------------------------------------------------------------------------
213 OUString PDFFilter_getImplementationName ()
214 throw (RuntimeException)
216 return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.PDF.PDFFilter" ) );
219 // -----------------------------------------------------------------------------
221 #define SERVICE_NAME "com.sun.star.document.PDFFilter"
223 sal_Bool SAL_CALL PDFFilter_supportsService( const OUString& ServiceName )
224 throw (RuntimeException)
226 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) );
229 // -----------------------------------------------------------------------------
231 Sequence< OUString > SAL_CALL PDFFilter_getSupportedServiceNames( ) throw (RuntimeException)
233 Sequence < OUString > aRet(1);
234 OUString* pArray = aRet.getArray();
235 pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) );
236 return aRet;
239 #undef SERVICE_NAME
241 // -----------------------------------------------------------------------------
243 Reference< XInterface > SAL_CALL PDFFilter_createInstance( const Reference< XMultiServiceFactory > & rSMgr) throw( Exception )
245 return (cppu::OWeakObject*) new PDFFilter( rSMgr );
248 // -----------------------------------------------------------------------------
250 OUString SAL_CALL PDFFilter::getImplementationName()
251 throw (RuntimeException)
253 return PDFFilter_getImplementationName();
256 // -----------------------------------------------------------------------------
258 sal_Bool SAL_CALL PDFFilter::supportsService( const OUString& rServiceName )
259 throw (RuntimeException)
261 return PDFFilter_supportsService( rServiceName );
264 // -----------------------------------------------------------------------------
266 ::com::sun::star::uno::Sequence< OUString > SAL_CALL PDFFilter::getSupportedServiceNames( ) throw (RuntimeException)
268 return PDFFilter_getSupportedServiceNames();