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 :
21 : #include "pdfexport.hxx"
22 : #include "impdialog.hxx"
23 :
24 : #include "pdf.hrc"
25 : #include "tools/urlobj.hxx"
26 : #include "tools/fract.hxx"
27 : #include "tools/poly.hxx"
28 : #include "vcl/mapmod.hxx"
29 : #include "vcl/virdev.hxx"
30 : #include "vcl/metaact.hxx"
31 : #include "vcl/gdimtf.hxx"
32 : #include "vcl/jobset.hxx"
33 : #include "vcl/bmpacc.hxx"
34 : #include "vcl/svapp.hxx"
35 : #include "toolkit/awt/vclxdevice.hxx"
36 : #include "unotools/localfilehelper.hxx"
37 : #include <vcl/FilterConfigItem.hxx>
38 : #include <vcl/graphicfilter.hxx>
39 : #include "svl/solar.hrc"
40 : #include "comphelper/string.hxx"
41 : #include "comphelper/storagehelper.hxx"
42 : #include "unotools/streamwrap.hxx"
43 : #include "com/sun/star/io/XSeekable.hpp"
44 :
45 : #include "basegfx/polygon/b2dpolygon.hxx"
46 : #include "basegfx/polygon/b2dpolypolygon.hxx"
47 : #include "basegfx/polygon/b2dpolygontools.hxx"
48 :
49 : #include "unotools/saveopt.hxx" // only for testing of relative saving options in PDF
50 :
51 : #include "vcl/graphictools.hxx"
52 : #include "com/sun/star/beans/XPropertySet.hpp"
53 : #include "com/sun/star/configuration/theDefaultProvider.hpp"
54 : #include "com/sun/star/awt/Rectangle.hpp"
55 : #include "com/sun/star/awt/XDevice.hpp"
56 : #include "com/sun/star/util/MeasureUnit.hpp"
57 : #include "com/sun/star/frame/XModel.hpp"
58 : #include "com/sun/star/frame/ModuleManager.hpp"
59 : #include "com/sun/star/frame/XStorable.hpp"
60 : #include "com/sun/star/frame/XController.hpp"
61 : #include "com/sun/star/document/XDocumentProperties.hpp"
62 : #include "com/sun/star/document/XDocumentPropertiesSupplier.hpp"
63 : #include "com/sun/star/container/XNameAccess.hpp"
64 : #include "com/sun/star/view/XViewSettingsSupplier.hpp"
65 : #include "com/sun/star/task/XInteractionRequest.hpp"
66 : #include "com/sun/star/task/PDFExportException.hpp"
67 :
68 : #include "unotools/configmgr.hxx"
69 : #include "cppuhelper/exc_hlp.hxx"
70 : #include "cppuhelper/compbase1.hxx"
71 : #include "cppuhelper/basemutex.hxx"
72 :
73 : #include "com/sun/star/lang/XServiceInfo.hpp"
74 : #include "com/sun/star/drawing/XShapes.hpp"
75 : #include "com/sun/star/graphic/XGraphicProvider.hpp"
76 :
77 : using namespace ::rtl;
78 : using namespace ::vcl;
79 : using namespace ::com::sun::star;
80 : using namespace ::com::sun::star::uno;
81 : using namespace ::com::sun::star::lang;
82 : using namespace ::com::sun::star::beans;
83 : using namespace ::com::sun::star::view;
84 : using namespace ::com::sun::star::graphic;
85 :
86 : // -------------
87 : // - PDFExport -
88 : // -------------
89 :
90 0 : PDFExport::PDFExport( const Reference< XComponent >& rxSrcDoc,
91 : const Reference< task::XStatusIndicator >& rxStatusIndicator,
92 : const Reference< task::XInteractionHandler >& rxIH,
93 : const Reference< XComponentContext >& xContext ) :
94 : mxSrcDoc ( rxSrcDoc ),
95 : mxContext ( xContext ),
96 : mxStatusIndicator ( rxStatusIndicator ),
97 : mxIH ( rxIH ),
98 : mbUseTaggedPDF ( sal_False ),
99 : mnPDFTypeSelection ( 0 ),
100 : mbExportNotes ( sal_True ),
101 : mbViewPDF ( sal_True ),
102 : mbExportNotesPages ( sal_False ),
103 : mbUseTransitionEffects ( sal_True ),
104 : mbExportBookmarks ( sal_True ),
105 : mbExportHiddenSlides ( sal_False ),
106 : mnOpenBookmarkLevels ( -1 ),
107 : mbUseLosslessCompression ( sal_False ),
108 : mbReduceImageResolution ( sal_False ),
109 : mbSkipEmptyPages ( sal_True ),
110 : mbAddStream ( sal_False ),
111 : mnMaxImageResolution ( 300 ),
112 : mnQuality ( 90 ),
113 : mnFormsFormat ( 0 ),
114 : mbExportFormFields ( sal_True ),
115 : mbAllowDuplicateFieldNames ( sal_False ),
116 : mnProgressValue ( 0 ),
117 : mbRemoveTransparencies ( sal_False ),
118 : mbWatermark ( sal_False ),
119 :
120 : mbHideViewerToolbar ( sal_False ),
121 : mbHideViewerMenubar ( sal_False ),
122 : mbHideViewerWindowControls ( sal_False ),
123 : mbFitWindow ( sal_False ),
124 : mbCenterWindow ( sal_False ),
125 : mbOpenInFullScreenMode ( sal_False ),
126 : mbDisplayPDFDocumentTitle ( sal_True ),
127 : mnPDFDocumentMode ( 0 ),
128 : mnPDFDocumentAction ( 0 ),
129 : mnZoom ( 100 ),
130 : mnInitialPage ( 1 ),
131 : mnPDFPageLayout ( 0 ),
132 : mbFirstPageLeft ( sal_False ),
133 :
134 : mbEncrypt ( sal_False ),
135 : mbRestrictPermissions ( sal_False ),
136 : mnPrintAllowed ( 2 ),
137 : mnChangesAllowed ( 4 ),
138 : mbCanCopyOrExtract ( sal_True ),
139 : mbCanExtractForAccessibility( sal_True ),
140 :
141 : //--->i56629
142 : mbExportRelativeFsysLinks ( sal_False ),
143 : mnDefaultLinkAction ( 0 ),
144 : mbConvertOOoTargetToPDFTarget( sal_False ),
145 : mbExportBmkToDest ( sal_False ),
146 0 : mbSignPDF ( false )
147 : {
148 0 : }
149 :
150 : // -----------------------------------------------------------------------------
151 :
152 0 : PDFExport::~PDFExport()
153 : {
154 0 : }
155 :
156 : // -----------------------------------------------------------------------------
157 :
158 0 : sal_Bool PDFExport::ExportSelection( vcl::PDFWriter& rPDFWriter,
159 : Reference< com::sun::star::view::XRenderable >& rRenderable,
160 : const Any& rSelection,
161 : const StringRangeEnumerator& rRangeEnum,
162 : Sequence< PropertyValue >& rRenderOptions,
163 : sal_Int32 nPageCount )
164 : {
165 0 : sal_Bool bRet = sal_False;
166 : try
167 : {
168 0 : Any* pFirstPage = NULL;
169 0 : Any* pLastPage = NULL;
170 :
171 0 : sal_Bool bExportNotesPages = sal_False;
172 :
173 0 : for( sal_Int32 nData = 0, nDataCount = rRenderOptions.getLength(); nData < nDataCount; ++nData )
174 : {
175 0 : if ( rRenderOptions[ nData ].Name == "IsFirstPage" )
176 0 : pFirstPage = &rRenderOptions[ nData ].Value;
177 0 : else if ( rRenderOptions[ nData ].Name == "IsLastPage" )
178 0 : pLastPage = &rRenderOptions[ nData ].Value;
179 0 : else if ( rRenderOptions[ nData ].Name == "ExportNotesPages" )
180 0 : rRenderOptions[ nData ].Value >>= bExportNotesPages;
181 : }
182 :
183 0 : OutputDevice* pOut = rPDFWriter.GetReferenceDevice();
184 :
185 0 : if( pOut )
186 : {
187 0 : vcl::PDFExtOutDevData* pPDFExtOutDevData = PTR_CAST( vcl::PDFExtOutDevData, pOut->GetExtOutDevData() );
188 0 : if ( nPageCount )
189 : {
190 0 : pPDFExtOutDevData->SetIsExportNotesPages( bExportNotesPages );
191 :
192 0 : sal_Int32 nCurrentPage(0);
193 0 : StringRangeEnumerator::Iterator aIter = rRangeEnum.begin();
194 0 : StringRangeEnumerator::Iterator aEnd = rRangeEnum.end();
195 0 : while ( aIter != aEnd )
196 : {
197 0 : Sequence< PropertyValue > aRenderer( rRenderable->getRenderer( *aIter, rSelection, rRenderOptions ) );
198 0 : awt::Size aPageSize;
199 :
200 0 : for( sal_Int32 nProperty = 0, nPropertyCount = aRenderer.getLength(); nProperty < nPropertyCount; ++nProperty )
201 : {
202 0 : if ( aRenderer[ nProperty ].Name == "PageSize" )
203 0 : aRenderer[ nProperty].Value >>= aPageSize;
204 : }
205 :
206 0 : pPDFExtOutDevData->SetCurrentPageNumber( nCurrentPage );
207 :
208 0 : GDIMetaFile aMtf;
209 0 : const MapMode aMapMode( MAP_100TH_MM );
210 0 : const Size aMtfSize( aPageSize.Width, aPageSize.Height );
211 :
212 0 : pOut->Push();
213 0 : pOut->EnableOutput( sal_False );
214 0 : pOut->SetMapMode( aMapMode );
215 :
216 0 : aMtf.SetPrefSize( aMtfSize );
217 0 : aMtf.SetPrefMapMode( aMapMode );
218 0 : aMtf.Record( pOut );
219 :
220 : // #i35176#
221 : // IsLastPage property.
222 0 : const sal_Int32 nCurrentRenderer = *aIter;
223 0 : ++aIter;
224 0 : if ( pLastPage && aIter == aEnd )
225 0 : *pLastPage <<= sal_True;
226 :
227 0 : rRenderable->render( nCurrentRenderer, rSelection, rRenderOptions );
228 :
229 0 : aMtf.Stop();
230 0 : aMtf.WindStart();
231 :
232 0 : if( aMtf.GetActionSize() &&
233 0 : ( !mbSkipEmptyPages || aPageSize.Width || aPageSize.Height ) )
234 0 : bRet = ImplExportPage( rPDFWriter, *pPDFExtOutDevData, aMtf ) || bRet;
235 :
236 0 : pOut->Pop();
237 :
238 0 : if ( mxStatusIndicator.is() )
239 0 : mxStatusIndicator->setValue( mnProgressValue );
240 0 : if ( pFirstPage )
241 0 : *pFirstPage <<= sal_False;
242 :
243 0 : ++mnProgressValue;
244 0 : ++nCurrentPage;
245 0 : }
246 : }
247 : else
248 : {
249 0 : bRet = sal_True; // #i18334# SJ: nPageCount == 0,
250 0 : rPDFWriter.NewPage( 10000, 10000 ); // creating dummy page
251 0 : rPDFWriter.SetMapMode( MAP_100TH_MM ); //
252 : }
253 : }
254 : }
255 0 : catch(const RuntimeException &)
256 : {
257 : }
258 0 : return bRet;
259 : }
260 :
261 : class PDFExportStreamDoc : public vcl::PDFOutputStream
262 : {
263 : Reference< XComponent > m_xSrcDoc;
264 : Sequence< beans::NamedValue > m_aPreparedPassword;
265 : public:
266 0 : PDFExportStreamDoc( const Reference< XComponent >& xDoc, const Sequence<beans::NamedValue>& rPwd )
267 : : m_xSrcDoc( xDoc ),
268 0 : m_aPreparedPassword( rPwd )
269 0 : {}
270 : virtual ~PDFExportStreamDoc();
271 :
272 : virtual void write( const Reference< XOutputStream >& xStream );
273 : };
274 :
275 0 : PDFExportStreamDoc::~PDFExportStreamDoc()
276 : {
277 0 : }
278 :
279 0 : void PDFExportStreamDoc::write( const Reference< XOutputStream >& xStream )
280 : {
281 0 : Reference< com::sun::star::frame::XStorable > xStore( m_xSrcDoc, UNO_QUERY );
282 0 : if( xStore.is() )
283 : {
284 0 : Sequence< beans::PropertyValue > aArgs( 2 + ((m_aPreparedPassword.getLength() > 0) ? 1 : 0) );
285 0 : aArgs.getArray()[0].Name = "FilterName";
286 0 : aArgs.getArray()[1].Name = "OutputStream";
287 0 : aArgs.getArray()[1].Value <<= xStream;
288 0 : if( m_aPreparedPassword.getLength() )
289 : {
290 0 : aArgs.getArray()[2].Name = "EncryptionData";
291 0 : aArgs.getArray()[2].Value <<= m_aPreparedPassword;
292 : }
293 :
294 : try
295 : {
296 0 : xStore->storeToURL( "private:stream", aArgs );
297 : }
298 0 : catch( const IOException& )
299 : {
300 0 : }
301 0 : }
302 0 : }
303 :
304 0 : static OUString getMimetypeForDocument( const Reference< XComponentContext >& xContext,
305 : const Reference< XComponent >& xDoc ) throw()
306 : {
307 0 : OUString aDocMimetype;
308 : // get document service name
309 0 : Reference< com::sun::star::frame::XStorable > xStore( xDoc, UNO_QUERY );
310 0 : Reference< frame::XModuleManager2 > xModuleManager = frame::ModuleManager::create(xContext);
311 0 : if( xStore.is() )
312 : {
313 0 : OUString aDocServiceName = xModuleManager->identify( Reference< XInterface >( xStore, uno::UNO_QUERY ) );
314 0 : if ( !aDocServiceName.isEmpty() )
315 : {
316 : // get the actual filter name
317 0 : OUString aFilterName;
318 : Reference< lang::XMultiServiceFactory > xConfigProvider =
319 0 : configuration::theDefaultProvider::get( xContext );
320 0 : uno::Sequence< uno::Any > aArgs( 1 );
321 0 : beans::NamedValue aPathProp;
322 0 : aPathProp.Name = "nodepath";
323 0 : aPathProp.Value <<= OUString( "/org.openoffice.Setup/Office/Factories/" );
324 0 : aArgs[0] <<= aPathProp;
325 :
326 : Reference< container::XNameAccess > xSOFConfig(
327 0 : xConfigProvider->createInstanceWithArguments(
328 0 : "com.sun.star.configuration.ConfigurationAccess", aArgs ),
329 0 : uno::UNO_QUERY );
330 :
331 0 : Reference< container::XNameAccess > xApplConfig;
332 0 : xSOFConfig->getByName( aDocServiceName ) >>= xApplConfig;
333 0 : if ( xApplConfig.is() )
334 : {
335 0 : xApplConfig->getByName( "ooSetupFactoryActualFilter" ) >>= aFilterName;
336 0 : if( !aFilterName.isEmpty() )
337 : {
338 : // find the related type name
339 0 : OUString aTypeName;
340 : Reference< container::XNameAccess > xFilterFactory(
341 0 : xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.FilterFactory", xContext),
342 0 : uno::UNO_QUERY );
343 :
344 0 : Sequence< beans::PropertyValue > aFilterData;
345 0 : xFilterFactory->getByName( aFilterName ) >>= aFilterData;
346 0 : for ( sal_Int32 nInd = 0; nInd < aFilterData.getLength(); nInd++ )
347 0 : if ( aFilterData[nInd].Name == "Type" )
348 0 : aFilterData[nInd].Value >>= aTypeName;
349 :
350 0 : if ( !aTypeName.isEmpty() )
351 : {
352 : // find the mediatype
353 : Reference< container::XNameAccess > xTypeDetection(
354 0 : xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.TypeDetection", xContext),
355 0 : UNO_QUERY );
356 :
357 0 : Sequence< beans::PropertyValue > aTypeData;
358 0 : xTypeDetection->getByName( aTypeName ) >>= aTypeData;
359 0 : for ( sal_Int32 nInd = 0; nInd < aTypeData.getLength(); nInd++ )
360 0 : if ( aTypeData[nInd].Name == "MediaType" )
361 0 : aTypeData[nInd].Value >>= aDocMimetype;
362 0 : }
363 : }
364 0 : }
365 0 : }
366 : }
367 0 : return aDocMimetype;
368 : }
369 :
370 0 : sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >& rFilterData )
371 : {
372 0 : INetURLObject aURL( rFile );
373 0 : sal_Bool bRet = sal_False;
374 :
375 0 : std::set< PDFWriter::ErrorCode > aErrors;
376 :
377 0 : if( aURL.GetProtocol() != INET_PROT_FILE )
378 : {
379 0 : OUString aTmp;
380 :
381 0 : if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( rFile, aTmp ) )
382 0 : aURL = INetURLObject(aTmp);
383 : }
384 :
385 0 : if( aURL.GetProtocol() == INET_PROT_FILE )
386 : {
387 0 : Reference< XRenderable > xRenderable( mxSrcDoc, UNO_QUERY );
388 :
389 0 : if( xRenderable.is() )
390 : {
391 0 : VCLXDevice* pXDevice = new VCLXDevice;
392 0 : OUString aPageRange;
393 0 : Any aSelection;
394 0 : PDFWriter::PDFWriterContext aContext;
395 0 : OUString aOpenPassword, aPermissionPassword;
396 0 : Reference< beans::XMaterialHolder > xEnc;
397 0 : Sequence< beans::NamedValue > aPreparedPermissionPassword;
398 :
399 :
400 : // getting the string for the creator
401 0 : OUString aCreator;
402 0 : Reference< XServiceInfo > xInfo( mxSrcDoc, UNO_QUERY );
403 0 : if ( xInfo.is() )
404 : {
405 0 : if ( xInfo->supportsService( "com.sun.star.presentation.PresentationDocument" ) )
406 0 : aCreator += "Impress";
407 0 : else if ( xInfo->supportsService( "com.sun.star.drawing.DrawingDocument" ) )
408 0 : aCreator += "Draw";
409 0 : else if ( xInfo->supportsService( "com.sun.star.text.TextDocument" ) )
410 0 : aCreator += "Writer";
411 0 : else if ( xInfo->supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) )
412 0 : aCreator += "Calc";
413 0 : else if ( xInfo->supportsService( "com.sun.star.formula.FormulaProperties" ) )
414 0 : aCreator += "Math";
415 : }
416 :
417 0 : Reference< document::XDocumentPropertiesSupplier > xDocumentPropsSupplier( mxSrcDoc, UNO_QUERY );
418 0 : if ( xDocumentPropsSupplier.is() )
419 : {
420 0 : Reference< document::XDocumentProperties > xDocumentProps( xDocumentPropsSupplier->getDocumentProperties() );
421 0 : if ( xDocumentProps.is() )
422 : {
423 0 : aContext.DocumentInfo.Title = xDocumentProps->getTitle();
424 0 : aContext.DocumentInfo.Author = xDocumentProps->getAuthor();
425 0 : aContext.DocumentInfo.Subject = xDocumentProps->getSubject();
426 0 : aContext.DocumentInfo.Keywords = ::comphelper::string::convertCommaSeparated(xDocumentProps->getKeywords());
427 0 : }
428 : }
429 : // getting the string for the producer
430 : aContext.DocumentInfo.Producer =
431 0 : utl::ConfigManager::getProductName() +
432 0 : " " +
433 0 : utl::ConfigManager::getProductVersion();
434 0 : aContext.DocumentInfo.Creator = aCreator;
435 :
436 0 : for( sal_Int32 nData = 0, nDataCount = rFilterData.getLength(); nData < nDataCount; ++nData )
437 : {
438 0 : if ( rFilterData[ nData ].Name == "PageRange" )
439 0 : rFilterData[ nData ].Value >>= aPageRange;
440 0 : else if ( rFilterData[ nData ].Name == "Selection" )
441 0 : rFilterData[ nData ].Value >>= aSelection;
442 0 : else if ( rFilterData[ nData ].Name == "UseLosslessCompression" )
443 0 : rFilterData[ nData ].Value >>= mbUseLosslessCompression;
444 0 : else if ( rFilterData[ nData ].Name == "Quality" )
445 0 : rFilterData[ nData ].Value >>= mnQuality;
446 0 : else if ( rFilterData[ nData ].Name == "ReduceImageResolution" )
447 0 : rFilterData[ nData ].Value >>= mbReduceImageResolution;
448 0 : else if ( rFilterData[ nData ].Name == "IsSkipEmptyPages" )
449 0 : rFilterData[ nData ].Value >>= mbSkipEmptyPages;
450 0 : else if ( rFilterData[ nData ].Name == "MaxImageResolution" )
451 0 : rFilterData[ nData ].Value >>= mnMaxImageResolution;
452 0 : else if ( rFilterData[ nData ].Name == "UseTaggedPDF" )
453 0 : rFilterData[ nData ].Value >>= mbUseTaggedPDF;
454 0 : else if ( rFilterData[ nData ].Name == "SelectPdfVersion" )
455 0 : rFilterData[ nData ].Value >>= mnPDFTypeSelection;
456 0 : else if ( rFilterData[ nData ].Name == "ExportNotes" )
457 0 : rFilterData[ nData ].Value >>= mbExportNotes;
458 0 : else if ( rFilterData[ nData ].Name == "ViewPDFAfterExport" )
459 0 : rFilterData[ nData ].Value >>= mbViewPDF;
460 0 : else if ( rFilterData[ nData ].Name == "ExportNotesPages" )
461 0 : rFilterData[ nData ].Value >>= mbExportNotesPages;
462 0 : else if ( rFilterData[ nData ].Name == "UseTransitionEffects" )
463 0 : rFilterData[ nData ].Value >>= mbUseTransitionEffects;
464 0 : else if ( rFilterData[ nData ].Name == "ExportFormFields" )
465 0 : rFilterData[ nData ].Value >>= mbExportFormFields;
466 0 : else if ( rFilterData[ nData ].Name == "FormsType" )
467 0 : rFilterData[ nData ].Value >>= mnFormsFormat;
468 0 : else if ( rFilterData[ nData ].Name == "AllowDuplicateFieldNames" )
469 0 : rFilterData[ nData ].Value >>= mbAllowDuplicateFieldNames;
470 : //viewer properties
471 0 : else if ( rFilterData[ nData ].Name == "HideViewerToolbar" )
472 0 : rFilterData[ nData ].Value >>= mbHideViewerToolbar;
473 0 : else if ( rFilterData[ nData ].Name == "HideViewerMenubar" )
474 0 : rFilterData[ nData ].Value >>= mbHideViewerMenubar;
475 0 : else if ( rFilterData[ nData ].Name == "HideViewerWindowControls" )
476 0 : rFilterData[ nData ].Value >>= mbHideViewerWindowControls;
477 0 : else if ( rFilterData[ nData ].Name == "ResizeWindowToInitialPage" )
478 0 : rFilterData[ nData ].Value >>= mbFitWindow;
479 0 : else if ( rFilterData[ nData ].Name == "CenterWindow" )
480 0 : rFilterData[ nData ].Value >>= mbCenterWindow;
481 0 : else if ( rFilterData[ nData ].Name == "OpenInFullScreenMode" )
482 0 : rFilterData[ nData ].Value >>= mbOpenInFullScreenMode;
483 0 : else if ( rFilterData[ nData ].Name == "DisplayPDFDocumentTitle" )
484 0 : rFilterData[ nData ].Value >>= mbDisplayPDFDocumentTitle;
485 0 : else if ( rFilterData[ nData ].Name == "InitialView" )
486 0 : rFilterData[ nData ].Value >>= mnPDFDocumentMode;
487 0 : else if ( rFilterData[ nData ].Name == "Magnification" )
488 0 : rFilterData[ nData ].Value >>= mnPDFDocumentAction;
489 0 : else if ( rFilterData[ nData ].Name == "Zoom" )
490 0 : rFilterData[ nData ].Value >>= mnZoom;
491 0 : else if ( rFilterData[ nData ].Name == "InitialPage" )
492 0 : rFilterData[ nData ].Value >>= mnInitialPage;
493 0 : else if ( rFilterData[ nData ].Name == "PageLayout" )
494 0 : rFilterData[ nData ].Value >>= mnPDFPageLayout;
495 0 : else if ( rFilterData[ nData ].Name == "FirstPageOnLeft" )
496 0 : rFilterData[ nData ].Value >>= aContext.FirstPageLeft;
497 0 : else if ( rFilterData[ nData ].Name == "IsAddStream" )
498 0 : rFilterData[ nData ].Value >>= mbAddStream;
499 0 : else if ( rFilterData[ nData ].Name == "Watermark" )
500 : {
501 0 : maWatermark = rFilterData[ nData ].Value;
502 0 : mbWatermark = sal_True;
503 : }
504 : //now all the security related properties...
505 0 : else if ( rFilterData[ nData ].Name == "EncryptFile" )
506 0 : rFilterData[ nData ].Value >>= mbEncrypt;
507 0 : else if ( rFilterData[ nData ].Name == "DocumentOpenPassword" )
508 0 : rFilterData[ nData ].Value >>= aOpenPassword;
509 0 : else if ( rFilterData[ nData ].Name == "RestrictPermissions" )
510 0 : rFilterData[ nData ].Value >>= mbRestrictPermissions;
511 0 : else if ( rFilterData[ nData ].Name == "PermissionPassword" )
512 0 : rFilterData[ nData ].Value >>= aPermissionPassword;
513 0 : else if ( rFilterData[ nData ].Name == "PreparedPasswords" )
514 0 : rFilterData[ nData ].Value >>= xEnc;
515 0 : else if ( rFilterData[ nData ].Name == "PreparedPermissionPassword" )
516 0 : rFilterData[ nData ].Value >>= aPreparedPermissionPassword;
517 0 : else if ( rFilterData[ nData ].Name == "Printing" )
518 0 : rFilterData[ nData ].Value >>= mnPrintAllowed;
519 0 : else if ( rFilterData[ nData ].Name == "Changes" )
520 0 : rFilterData[ nData ].Value >>= mnChangesAllowed;
521 0 : else if ( rFilterData[ nData ].Name == "EnableCopyingOfContent" )
522 0 : rFilterData[ nData ].Value >>= mbCanCopyOrExtract;
523 0 : else if ( rFilterData[ nData ].Name == "EnableTextAccessForAccessibilityTools" )
524 0 : rFilterData[ nData ].Value >>= mbCanExtractForAccessibility;
525 : //--->i56629 links extra (relative links and other related stuff)
526 0 : else if ( rFilterData[ nData ].Name == "ExportLinksRelativeFsys" )
527 0 : rFilterData[ nData ].Value >>= mbExportRelativeFsysLinks;
528 0 : else if ( rFilterData[ nData ].Name == "PDFViewSelection" )
529 0 : rFilterData[ nData ].Value >>= mnDefaultLinkAction;
530 0 : else if ( rFilterData[ nData ].Name == "ConvertOOoTargetToPDFTarget" )
531 0 : rFilterData[ nData ].Value >>= mbConvertOOoTargetToPDFTarget;
532 0 : else if ( rFilterData[ nData ].Name == "ExportBookmarksToPDFDestination" )
533 0 : rFilterData[ nData ].Value >>= mbExportBmkToDest;
534 0 : else if ( rFilterData[ nData ].Name == "ExportBookmarks" )
535 0 : rFilterData[ nData ].Value >>= mbExportBookmarks;
536 0 : else if ( rFilterData[ nData ].Name == "ExportHiddenSlides" )
537 0 : rFilterData[ nData ].Value >>= mbExportHiddenSlides;
538 0 : else if ( rFilterData[ nData ].Name == "OpenBookmarkLevels" )
539 0 : rFilterData[ nData ].Value >>= mnOpenBookmarkLevels;
540 0 : else if ( rFilterData[ nData ].Name == "SignPDF" )
541 0 : rFilterData[ nData ].Value >>= mbSignPDF;
542 0 : else if ( rFilterData[ nData ].Name == "SignatureLocation" )
543 0 : rFilterData[ nData ].Value >>= msSignLocation;
544 0 : else if ( rFilterData[ nData ].Name == "SignatureReason" )
545 0 : rFilterData[ nData ].Value >>= msSignReason;
546 0 : else if ( rFilterData[ nData ].Name == "SignatureContactInfo" )
547 0 : rFilterData[ nData ].Value >>= msSignContact;
548 0 : else if ( rFilterData[ nData ].Name == "SignaturePassword" )
549 0 : rFilterData[ nData ].Value >>= msSignPassword;
550 0 : else if ( rFilterData[ nData ].Name == "SignatureCertificate" )
551 0 : rFilterData[ nData ].Value >>= maSignCertificate;
552 : }
553 0 : aContext.URL = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
554 :
555 : //set the correct version, depending on user request
556 0 : switch( mnPDFTypeSelection )
557 : {
558 : default:
559 : case 0:
560 0 : aContext.Version = PDFWriter::PDF_1_4;
561 0 : break;
562 : case 1:
563 0 : aContext.Version = PDFWriter::PDF_A_1;
564 : //force the tagged PDF as well
565 0 : mbUseTaggedPDF = sal_True;
566 : //force disabling of form conversion
567 0 : mbExportFormFields = sal_False;
568 : // PDF/A does not allow transparencies
569 0 : mbRemoveTransparencies = sal_True;
570 : // no encryption
571 0 : mbEncrypt = sal_False;
572 0 : xEnc.clear();
573 0 : break;
574 : }
575 :
576 : //copy in context the values default in the contructor or set by the FilterData sequence of properties
577 0 : aContext.Tagged = mbUseTaggedPDF;
578 :
579 : //values used in viewer
580 0 : aContext.HideViewerToolbar = mbHideViewerToolbar;
581 0 : aContext.HideViewerMenubar = mbHideViewerMenubar;
582 0 : aContext.HideViewerWindowControls = mbHideViewerWindowControls;
583 0 : aContext.FitWindow = mbFitWindow;
584 0 : aContext.CenterWindow = mbCenterWindow;
585 0 : aContext.OpenInFullScreenMode = mbOpenInFullScreenMode;
586 0 : aContext.DisplayPDFDocumentTitle = mbDisplayPDFDocumentTitle;
587 0 : aContext.InitialPage = mnInitialPage-1;
588 0 : aContext.OpenBookmarkLevels = mnOpenBookmarkLevels;
589 :
590 0 : switch( mnPDFDocumentMode )
591 : {
592 : default:
593 : case 0:
594 0 : aContext.PDFDocumentMode = PDFWriter::ModeDefault;
595 0 : break;
596 : case 1:
597 0 : aContext.PDFDocumentMode = PDFWriter::UseOutlines;
598 0 : break;
599 : case 2:
600 0 : aContext.PDFDocumentMode = PDFWriter::UseThumbs;
601 0 : break;
602 : }
603 0 : switch( mnPDFDocumentAction )
604 : {
605 : default:
606 : case 0:
607 0 : aContext.PDFDocumentAction = PDFWriter::ActionDefault;
608 0 : break;
609 : case 1:
610 0 : aContext.PDFDocumentAction = PDFWriter::FitInWindow;
611 0 : break;
612 : case 2:
613 0 : aContext.PDFDocumentAction = PDFWriter::FitWidth;
614 0 : break;
615 : case 3:
616 0 : aContext.PDFDocumentAction = PDFWriter::FitVisible;
617 0 : break;
618 : case 4:
619 0 : aContext.PDFDocumentAction = PDFWriter::ActionZoom;
620 0 : aContext.Zoom = mnZoom;
621 0 : break;
622 : }
623 :
624 0 : switch( mnPDFPageLayout )
625 : {
626 : default:
627 : case 0:
628 0 : aContext.PageLayout = PDFWriter::DefaultLayout;
629 0 : break;
630 : case 1:
631 0 : aContext.PageLayout = PDFWriter::SinglePage;
632 0 : break;
633 : case 2:
634 0 : aContext.PageLayout = PDFWriter::Continuous;
635 0 : break;
636 : case 3:
637 0 : aContext.PageLayout = PDFWriter::ContinuousFacing;
638 0 : break;
639 : }
640 :
641 0 : aContext.FirstPageLeft = mbFirstPageLeft;
642 :
643 : //check if PDF/A, which does not allow encryption
644 0 : if( aContext.Version != PDFWriter::PDF_A_1 )
645 : {
646 : //set values needed in encryption
647 : //set encryption level, fixed, but here it can set by the UI if needed.
648 : // true is 128 bit, false 40
649 : //note that in 40 bit mode the UI needs reworking, since the current UI is meaningfull only for
650 : //128bit security mode
651 0 : aContext.Encryption.Security128bit = sal_True;
652 :
653 : //set check for permission change password
654 : // if not enabled and no permission password, force permissions to default as if PDF where without encryption
655 0 : if( mbRestrictPermissions && (xEnc.is() || !aPermissionPassword.isEmpty()) )
656 : {
657 0 : mbEncrypt = sal_True;
658 : //permission set as desired, done after
659 : }
660 : else
661 : {
662 : //force permission to default
663 0 : mnPrintAllowed = 2 ;
664 0 : mnChangesAllowed = 4 ;
665 0 : mbCanCopyOrExtract = sal_True;
666 0 : mbCanExtractForAccessibility = sal_True ;
667 : }
668 :
669 0 : switch( mnPrintAllowed )
670 : {
671 : case 0: //initialized when aContext is build, means no printing
672 0 : break;
673 : default:
674 : case 2:
675 0 : aContext.Encryption.CanPrintFull = sal_True;
676 : case 1:
677 0 : aContext.Encryption.CanPrintTheDocument = sal_True;
678 0 : break;
679 : }
680 :
681 0 : switch( mnChangesAllowed )
682 : {
683 : case 0: //already in struct PDFSecPermissions CTOR
684 0 : break;
685 : case 1:
686 0 : aContext.Encryption.CanAssemble = sal_True;
687 0 : break;
688 : case 2:
689 0 : aContext.Encryption.CanFillInteractive = sal_True;
690 0 : break;
691 : case 3:
692 0 : aContext.Encryption.CanAddOrModify = sal_True;
693 0 : break;
694 : default:
695 : case 4:
696 : aContext.Encryption.CanModifyTheContent =
697 : aContext.Encryption.CanCopyOrExtract =
698 : aContext.Encryption.CanAddOrModify =
699 0 : aContext.Encryption.CanFillInteractive = sal_True;
700 0 : break;
701 : }
702 :
703 0 : aContext.Encryption.CanCopyOrExtract = mbCanCopyOrExtract;
704 0 : aContext.Encryption.CanExtractForAccessibility = mbCanExtractForAccessibility;
705 0 : if( mbEncrypt && ! xEnc.is() )
706 0 : xEnc = PDFWriter::InitEncryption( aPermissionPassword, aOpenPassword, aContext.Encryption.Security128bit );
707 0 : if( mbEncrypt && !aPermissionPassword.isEmpty() && ! aPreparedPermissionPassword.getLength() )
708 0 : aPreparedPermissionPassword = comphelper::OStorageHelper::CreatePackageEncryptionData( aPermissionPassword );
709 : }
710 : // after this point we don't need the legacy clear passwords anymore
711 : // however they are still inside the passed filter data sequence
712 : // which is sadly out out our control
713 0 : aPermissionPassword = OUString();
714 0 : aOpenPassword = OUString();
715 :
716 : /*
717 : * FIXME: the entries are only implicitly defined by the resource file. Should there
718 : * ever be an additional form submit format this could get invalid.
719 : */
720 0 : switch( mnFormsFormat )
721 : {
722 : case 1:
723 0 : aContext.SubmitFormat = PDFWriter::PDF;
724 0 : break;
725 : case 2:
726 0 : aContext.SubmitFormat = PDFWriter::HTML;
727 0 : break;
728 : case 3:
729 0 : aContext.SubmitFormat = PDFWriter::XML;
730 0 : break;
731 : default:
732 : case 0:
733 0 : aContext.SubmitFormat = PDFWriter::FDF;
734 0 : break;
735 : }
736 0 : aContext.AllowDuplicateFieldNames = mbAllowDuplicateFieldNames;
737 :
738 : //get model
739 0 : Reference< frame::XModel > xModel( mxSrcDoc, UNO_QUERY );
740 : {
741 : //---> i56629 Relative link stuff
742 : //set the base URL of the file:
743 : //then base URL
744 0 : aContext.BaseURL = xModel->getURL();
745 : //relative link option is private to PDF Export filter and limited to local filesystem only
746 0 : aContext.RelFsys = mbExportRelativeFsysLinks;
747 : //determine the default acton for PDF links
748 0 : switch( mnDefaultLinkAction )
749 : {
750 : default:
751 : //default: URI, without fragment conversion (the bookmark in PDF may not work)
752 : case 0:
753 0 : aContext.DefaultLinkAction = PDFWriter::URIAction;
754 0 : break;
755 : //view PDF through the reader application
756 : case 1:
757 0 : aContext.ForcePDFAction = sal_True;
758 0 : aContext.DefaultLinkAction = PDFWriter::LaunchAction;
759 0 : break;
760 : //view PDF through an Internet browser
761 : case 2:
762 0 : aContext.DefaultLinkAction = PDFWriter::URIActionDestination;
763 0 : break;
764 : }
765 0 : aContext.ConvertOOoTargetToPDFTarget = mbConvertOOoTargetToPDFTarget;
766 : // check for Link Launch action, not allowed on PDF/A-1
767 : // this code chunk checks when the filter is called from scripting
768 0 : if( aContext.Version == PDFWriter::PDF_A_1 &&
769 0 : aContext.DefaultLinkAction == PDFWriter::LaunchAction )
770 : { //force the similar allowed URI action
771 0 : aContext.DefaultLinkAction = PDFWriter::URIActionDestination;
772 : //and remove the remote goto action forced on PDF file
773 0 : aContext.ForcePDFAction = sal_False;
774 : }
775 : }
776 :
777 0 : aContext.SignPDF = mbSignPDF;
778 0 : aContext.SignLocation = msSignLocation;
779 0 : aContext.SignContact = msSignContact;
780 0 : aContext.SignReason = msSignReason;
781 0 : aContext.SignPassword = msSignPassword;
782 0 : aContext.SignCertificate = maSignCertificate;
783 :
784 : // all context data set, time to create the printing device
785 0 : PDFWriter* pPDFWriter = new PDFWriter( aContext, xEnc );
786 0 : OutputDevice* pOut = pPDFWriter->GetReferenceDevice();
787 0 : vcl::PDFExtOutDevData* pPDFExtOutDevData = NULL;
788 :
789 : DBG_ASSERT( pOut, "PDFExport::Export: no reference device" );
790 0 : pXDevice->SetOutputDevice( pOut );
791 :
792 0 : if( mbAddStream )
793 : {
794 : // export stream
795 : // get mimetype
796 0 : OUString aSrcMimetype = getMimetypeForDocument( mxContext, mxSrcDoc );
797 : pPDFWriter->AddStream( aSrcMimetype,
798 0 : new PDFExportStreamDoc( mxSrcDoc, aPreparedPermissionPassword ),
799 : false
800 0 : );
801 : }
802 :
803 0 : if ( pOut )
804 : {
805 : DBG_ASSERT( pOut->GetExtOutDevData() == NULL, "PDFExport: ExtOutDevData already set!!!" );
806 0 : pPDFExtOutDevData = new vcl::PDFExtOutDevData( *pOut );
807 0 : pOut->SetExtOutDevData( pPDFExtOutDevData );
808 0 : pPDFExtOutDevData->SetIsExportNotes( mbExportNotes );
809 0 : pPDFExtOutDevData->SetIsExportTaggedPDF( mbUseTaggedPDF );
810 0 : pPDFExtOutDevData->SetIsExportTransitionEffects( mbUseTransitionEffects );
811 0 : pPDFExtOutDevData->SetFormsFormat( mnFormsFormat );
812 0 : pPDFExtOutDevData->SetIsExportFormFields( mbExportFormFields );
813 0 : pPDFExtOutDevData->SetIsExportBookmarks( mbExportBookmarks );
814 0 : pPDFExtOutDevData->SetIsExportHiddenSlides( mbExportHiddenSlides );
815 0 : pPDFExtOutDevData->SetIsLosslessCompression( mbUseLosslessCompression );
816 0 : pPDFExtOutDevData->SetIsReduceImageResolution( mbReduceImageResolution );
817 0 : pPDFExtOutDevData->SetIsExportNamedDestinations( mbExportBmkToDest );
818 :
819 0 : Sequence< PropertyValue > aRenderOptions( 6 );
820 0 : aRenderOptions[ 0 ].Name = "RenderDevice";
821 0 : aRenderOptions[ 0 ].Value <<= Reference< awt::XDevice >( pXDevice );
822 0 : aRenderOptions[ 1 ].Name = "ExportNotesPages";
823 0 : aRenderOptions[ 1 ].Value <<= sal_False;
824 0 : Any& rExportNotesValue = aRenderOptions[ 1 ].Value;
825 0 : aRenderOptions[ 2 ].Name = "IsFirstPage";
826 0 : aRenderOptions[ 2 ].Value <<= sal_True;
827 0 : aRenderOptions[ 3 ].Name = "IsLastPage";
828 0 : aRenderOptions[ 3 ].Value <<= sal_False;
829 0 : aRenderOptions[ 4 ].Name = "IsSkipEmptyPages";
830 0 : aRenderOptions[ 4 ].Value <<= mbSkipEmptyPages;
831 0 : aRenderOptions[ 5 ].Name = "PageRange";
832 0 : aRenderOptions[ 5 ].Value <<= aPageRange;
833 :
834 0 : if( !aPageRange.isEmpty() || !aSelection.hasValue() )
835 : {
836 0 : aSelection = Any();
837 0 : aSelection <<= mxSrcDoc;
838 : }
839 0 : sal_Bool bSecondPassForImpressNotes = sal_False;
840 0 : bool bReChangeToNormalView = false;
841 0 : OUString sShowOnlineLayout( "ShowOnlineLayout" );
842 0 : uno::Reference< beans::XPropertySet > xViewProperties;
843 :
844 0 : if ( aCreator.equalsAscii( "Writer" ) )
845 : {
846 : //i92835 if Writer is in web layout mode this has to be switched to normal view and back to web view in the end
847 : try
848 : {
849 0 : Reference< view::XViewSettingsSupplier > xVSettingsSupplier( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
850 0 : xViewProperties = xVSettingsSupplier->getViewSettings();
851 0 : xViewProperties->getPropertyValue( sShowOnlineLayout ) >>= bReChangeToNormalView;
852 0 : if( bReChangeToNormalView )
853 : {
854 0 : xViewProperties->setPropertyValue( sShowOnlineLayout, uno::makeAny( false ) );
855 0 : }
856 : }
857 0 : catch( const uno::Exception& )
858 : {
859 : }
860 :
861 : }
862 :
863 0 : const sal_Int32 nPageCount = xRenderable->getRendererCount( aSelection, aRenderOptions );
864 :
865 0 : if ( mbExportNotesPages && aCreator.equalsAscii( "Impress" ) )
866 : {
867 0 : uno::Reference< drawing::XShapes > xShapes; // sj: do not allow to export notes when
868 0 : if ( ! ( aSelection >>= xShapes ) ) // exporting a selection -> todo: in the dialog
869 0 : bSecondPassForImpressNotes = sal_True; // the export notes checkbox needs to be disabled
870 : }
871 :
872 0 : if( aPageRange.isEmpty() )
873 : {
874 0 : aPageRange = OUString::number( 1 ) + "-" + OUString::number(nPageCount );
875 : }
876 0 : StringRangeEnumerator aRangeEnum( aPageRange, 0, nPageCount-1 );
877 :
878 0 : if ( mxStatusIndicator.is() )
879 : {
880 0 : ResMgr* pResMgr = ResMgr::CreateResMgr( "pdffilter", Application::GetSettings().GetUILanguageTag() );
881 0 : if ( pResMgr )
882 : {
883 0 : sal_Int32 nTotalPageCount = aRangeEnum.size();
884 0 : if ( bSecondPassForImpressNotes )
885 0 : nTotalPageCount *= 2;
886 0 : mxStatusIndicator->start( String( ResId( PDF_PROGRESS_BAR, *pResMgr ) ), nTotalPageCount );
887 0 : delete pResMgr;
888 : }
889 : }
890 :
891 0 : if( nPageCount > 0 )
892 0 : bRet = ExportSelection( *pPDFWriter, xRenderable, aSelection, aRangeEnum, aRenderOptions, nPageCount );
893 : else
894 0 : bRet = sal_False;
895 :
896 0 : if ( bRet && bSecondPassForImpressNotes )
897 : {
898 0 : rExportNotesValue <<= sal_True;
899 0 : bRet = ExportSelection( *pPDFWriter, xRenderable, aSelection, aRangeEnum, aRenderOptions, nPageCount );
900 : }
901 0 : if ( mxStatusIndicator.is() )
902 0 : mxStatusIndicator->end();
903 :
904 : // if during the export the doc locale was set copy it to PDF writer
905 0 : const com::sun::star::lang::Locale& rLoc( pPDFExtOutDevData->GetDocumentLocale() );
906 0 : if( !rLoc.Language.isEmpty() )
907 0 : pPDFWriter->SetDocumentLocale( rLoc );
908 :
909 0 : if( bRet )
910 : {
911 0 : pPDFExtOutDevData->PlayGlobalActions( *pPDFWriter );
912 0 : pPDFWriter->Emit();
913 0 : aErrors = pPDFWriter->GetErrors();
914 : }
915 0 : pOut->SetExtOutDevData( NULL );
916 0 : if( bReChangeToNormalView )
917 : {
918 : try
919 : {
920 0 : xViewProperties->setPropertyValue( sShowOnlineLayout, uno::makeAny( true ) );
921 : }
922 0 : catch( const uno::Exception& )
923 : {
924 : }
925 0 : }
926 : }
927 :
928 0 : delete pPDFExtOutDevData;
929 0 : delete pPDFWriter;
930 0 : }
931 : }
932 :
933 : // show eventual errors during export
934 0 : showErrors( aErrors );
935 :
936 0 : return bRet;
937 : }
938 :
939 : namespace
940 : {
941 :
942 : typedef cppu::WeakComponentImplHelper1< task::XInteractionRequest > PDFErrorRequestBase;
943 :
944 0 : class PDFErrorRequest : private cppu::BaseMutex,
945 : public PDFErrorRequestBase
946 : {
947 : task::PDFExportException maExc;
948 : public:
949 : PDFErrorRequest( const task::PDFExportException& i_rExc );
950 :
951 : // XInteractionRequest
952 : virtual uno::Any SAL_CALL getRequest() throw (uno::RuntimeException);
953 : virtual uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL getContinuations() throw (uno::RuntimeException);
954 : };
955 :
956 0 : PDFErrorRequest::PDFErrorRequest( const task::PDFExportException& i_rExc ) :
957 : PDFErrorRequestBase( m_aMutex ),
958 0 : maExc( i_rExc )
959 : {
960 0 : }
961 :
962 0 : uno::Any SAL_CALL PDFErrorRequest::getRequest() throw (uno::RuntimeException)
963 : {
964 0 : osl::MutexGuard const guard( m_aMutex );
965 :
966 0 : uno::Any aRet;
967 0 : aRet <<= maExc;
968 0 : return aRet;
969 : }
970 :
971 0 : uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL PDFErrorRequest::getContinuations() throw (uno::RuntimeException)
972 : {
973 0 : return uno::Sequence< uno::Reference< task::XInteractionContinuation > >();
974 : }
975 :
976 : } // namespace
977 :
978 0 : void PDFExport::showErrors( const std::set< PDFWriter::ErrorCode >& rErrors )
979 : {
980 0 : if( ! rErrors.empty() && mxIH.is() )
981 : {
982 0 : task::PDFExportException aExc;
983 0 : aExc.ErrorCodes.realloc( sal_Int32(rErrors.size()) );
984 0 : sal_Int32 i = 0;
985 0 : for( std::set< PDFWriter::ErrorCode >::const_iterator it = rErrors.begin();
986 0 : it != rErrors.end(); ++it, i++ )
987 : {
988 0 : aExc.ErrorCodes.getArray()[i] = (sal_Int32)*it;
989 : }
990 0 : Reference< task::XInteractionRequest > xReq( new PDFErrorRequest( aExc ) );
991 0 : mxIH->handle( xReq );
992 : }
993 0 : }
994 :
995 : // -----------------------------------------------------------------------------
996 :
997 0 : sal_Bool PDFExport::ImplExportPage( PDFWriter& rWriter, PDFExtOutDevData& rPDFExtOutDevData, const GDIMetaFile& rMtf )
998 : {
999 0 : const Size aSizePDF( OutputDevice::LogicToLogic( rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), MAP_POINT ) );
1000 0 : Point aOrigin;
1001 0 : Rectangle aPageRect( aOrigin, rMtf.GetPrefSize() );
1002 0 : sal_Bool bRet = sal_True;
1003 :
1004 0 : rWriter.NewPage( aSizePDF.Width(), aSizePDF.Height() );
1005 0 : rWriter.SetMapMode( rMtf.GetPrefMapMode() );
1006 :
1007 0 : vcl::PDFWriter::PlayMetafileContext aCtx;
1008 0 : GDIMetaFile aMtf;
1009 0 : if( mbRemoveTransparencies )
1010 : {
1011 : aCtx.m_bTransparenciesWereRemoved = rWriter.GetReferenceDevice()->
1012 : RemoveTransparenciesFromMetaFile( rMtf, aMtf, mnMaxImageResolution, mnMaxImageResolution,
1013 0 : false, true, mbReduceImageResolution );
1014 : }
1015 : else
1016 : {
1017 0 : aMtf = rMtf;
1018 : }
1019 0 : aCtx.m_nMaxImageResolution = mbReduceImageResolution ? mnMaxImageResolution : 0;
1020 0 : aCtx.m_bOnlyLosslessCompression = mbUseLosslessCompression;
1021 0 : aCtx.m_nJPEGQuality = mnQuality;
1022 :
1023 :
1024 0 : basegfx::B2DRectangle aB2DRect( aPageRect.Left(), aPageRect.Top(), aPageRect.Right(), aPageRect.Bottom() );
1025 0 : rWriter.SetClipRegion( basegfx::B2DPolyPolygon( basegfx::tools::createPolygonFromRect( aB2DRect ) ) );
1026 :
1027 0 : rWriter.PlayMetafile( aMtf, aCtx, &rPDFExtOutDevData );
1028 :
1029 0 : rPDFExtOutDevData.ResetSyncData();
1030 :
1031 0 : if( mbWatermark )
1032 0 : ImplWriteWatermark( rWriter, aSizePDF );
1033 :
1034 0 : return bRet;
1035 : }
1036 :
1037 : // -----------------------------------------------------------------------------
1038 :
1039 0 : void PDFExport::ImplWriteWatermark( PDFWriter& rWriter, const Size& rPageSize )
1040 : {
1041 0 : OUString aText( "Watermark" );
1042 0 : Font aFont( OUString( "Helvetica" ), Size( 0, 3*rPageSize.Height()/4 ) );
1043 0 : aFont.SetItalic( ITALIC_NONE );
1044 0 : aFont.SetWidthType( WIDTH_NORMAL );
1045 0 : aFont.SetWeight( WEIGHT_NORMAL );
1046 0 : aFont.SetAlign( ALIGN_BOTTOM );
1047 0 : long nTextWidth = rPageSize.Width();
1048 0 : if( rPageSize.Width() < rPageSize.Height() )
1049 : {
1050 0 : nTextWidth = rPageSize.Height();
1051 0 : aFont.SetOrientation( 2700 );
1052 : }
1053 :
1054 0 : if( ! ( maWatermark >>= aText ) )
1055 : {
1056 : // more complicated watermark ?
1057 : }
1058 :
1059 : // adjust font height for text to fit
1060 0 : OutputDevice* pDev = rWriter.GetReferenceDevice();
1061 0 : pDev->Push( PUSH_ALL );
1062 0 : pDev->SetFont( aFont );
1063 0 : pDev->SetMapMode( MapMode( MAP_POINT ) );
1064 0 : int w = 0;
1065 0 : while( ( w = pDev->GetTextWidth( aText ) ) > nTextWidth )
1066 : {
1067 0 : long nNewHeight = aFont.GetHeight() * nTextWidth / w;
1068 0 : if( nNewHeight == aFont.GetHeight() )
1069 : {
1070 0 : nNewHeight--;
1071 0 : if( nNewHeight <= 0 )
1072 0 : break;
1073 : }
1074 0 : aFont.SetHeight( nNewHeight );
1075 0 : pDev->SetFont( aFont );
1076 : }
1077 0 : long nTextHeight = pDev->GetTextHeight();
1078 : // leave some maneuvering room for rounding issues, also
1079 : // some fonts go a little outside ascent/descent
1080 0 : nTextHeight += nTextHeight/20;
1081 0 : pDev->Pop();
1082 :
1083 0 : rWriter.Push( PUSH_ALL );
1084 0 : rWriter.SetMapMode( MapMode( MAP_POINT ) );
1085 0 : rWriter.SetFont( aFont );
1086 0 : rWriter.SetTextColor( COL_LIGHTGREEN );
1087 0 : Point aTextPoint;
1088 0 : Rectangle aTextRect;
1089 0 : if( rPageSize.Width() > rPageSize.Height() )
1090 : {
1091 0 : aTextPoint = Point( (rPageSize.Width()-w)/2,
1092 0 : rPageSize.Height()-(rPageSize.Height()-nTextHeight)/2 );
1093 0 : aTextRect = Rectangle( Point( (rPageSize.Width()-w)/2,
1094 0 : (rPageSize.Height()-nTextHeight)/2 ),
1095 0 : Size( w, nTextHeight ) );
1096 : }
1097 : else
1098 : {
1099 0 : aTextPoint = Point( (rPageSize.Width()-nTextHeight)/2,
1100 0 : (rPageSize.Height()-w)/2 );
1101 0 : aTextRect = Rectangle( aTextPoint, Size( nTextHeight, w ) );
1102 : }
1103 0 : rWriter.SetClipRegion();
1104 0 : rWriter.BeginTransparencyGroup();
1105 0 : rWriter.DrawText( aTextPoint, aText );
1106 0 : rWriter.EndTransparencyGroup( aTextRect, 50 );
1107 0 : rWriter.Pop();
1108 0 : }
1109 :
1110 :
1111 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|