Fix typo
[LibreOffice.git] / include / vcl / pdfwriter.hxx
blobf4599154e46569bb5403fdbc75f20168a7ea1178
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifndef INCLUDED_VCL_PDFWRITER_HXX
20 #define INCLUDED_VCL_PDFWRITER_HXX
22 #include <sal/types.h>
24 #include <tools/gen.hxx>
25 #include <tools/color.hxx>
26 #include <rtl/strbuf.hxx>
28 #include <vcl/dllapi.h>
29 #include <vcl/font.hxx>
30 #include <vcl/outdev.hxx>
31 #include <vcl/graph.hxx>
33 #include <com/sun/star/lang/Locale.hpp>
34 #include <com/sun/star/util/DateTime.hpp>
36 #include <memory>
37 #include <vector>
38 #include <set>
40 namespace com::sun::star::beans { class XMaterialHolder; }
41 namespace com::sun::star::io { class XOutputStream; }
42 namespace com::sun::star::security { class XCertificate; }
44 class GDIMetaFile;
45 class MapMode;
46 class LineInfo;
47 namespace tools {
48 class Polygon;
49 class PolyPolygon;
51 class Bitmap;
52 class BitmapEx;
53 class Gradient;
54 class Hatch;
55 class Wallpaper;
57 namespace vcl
60 class PDFExtOutDevData;
61 class PDFWriterImpl;
63 struct PDFNote
65 OUString Title; // optional title for the popup containing the note
66 OUString Contents; // contents of the note
67 css::util::DateTime maModificationDate;
68 bool isFreeText = false;
69 std::vector<basegfx::B2DPolygon> maPolygons;
70 Color annotColor;
71 Color interiorColor;
74 class VCL_DLLPUBLIC PDFOutputStream
76 public:
77 virtual ~PDFOutputStream();
78 virtual void write( const css::uno::Reference< css::io::XOutputStream >& xStream ) = 0;
81 class PDFWriter
83 ScopedVclPtr<PDFWriterImpl> xImplementation;
85 PDFWriter(const PDFWriter&) = delete;
86 PDFWriter& operator=(const PDFWriter&) = delete;
88 public:
89 // extended line info
90 enum CapType { capButt, capRound, capSquare };
91 enum JoinType { joinMiter, joinRound, joinBevel };
92 struct ExtLineInfo
94 double m_fLineWidth;
95 double m_fTransparency;
96 CapType m_eCap;
97 JoinType m_eJoin;
98 double m_fMiterLimit;
99 std::vector< double > m_aDashArray;
101 ExtLineInfo() : m_fLineWidth( 0.0 ),
102 m_fTransparency( 0.0 ),
103 m_eCap( capButt ),
104 m_eJoin( joinMiter ),
105 m_fMiterLimit( 10.0 )
109 enum class Orientation { Portrait, Inherit };
111 // in case the below enum is added PDF_2_0, please add just after PDF_1_7
112 enum class PDFVersion { PDF_1_4, PDF_1_5, PDF_1_6, PDF_1_7, PDF_A_1, PDF_A_2, PDF_A_3 };//i59651, PDF/A-1b & -1a, only -1b implemented for now
113 // for the meaning of DestAreaType please look at PDF Reference Manual
114 // version 1.4 section 8.2.1, page 475
115 enum class DestAreaType { XYZ, FitRectangle };
117 // for a definition of structural element types please refer to
118 // PDF Reference, 3rd ed. section 9.7.4
119 enum StructElement
121 // special element to place outside the structure hierarchy
122 NonStructElement,
123 // Grouping elements
124 Document, Part, Article, Section, Division, BlockQuote,
125 Caption, TOC, TOCI, Index,
127 // block level elements
128 Paragraph, Heading, H1, H2, H3, H4, H5, H6,
129 List, ListItem, LILabel, LIBody,
130 Table, TableRow, TableHeader, TableData,
132 // inline level elements
133 Span, Quote, Note, Reference, BibEntry, Code, Link, Annot,
134 Ruby, RB, RT, RP, Warichu, WT, WP,
136 // illustration elements
137 Figure, Formula, Form
140 enum StructAttribute
142 // Artifacts
143 Type, Subtype,
145 Placement, WritingMode, SpaceBefore, SpaceAfter, StartIndent, EndIndent,
146 TextIndent, TextAlign, Width, Height, BlockAlign, InlineAlign,
147 LineHeight, BaselineShift, TextDecorationType, ListNumbering,
148 RowSpan, ColSpan, Scope, Role,
149 RubyAlign, RubyPosition,
151 // link destination is an artificial attribute that sets
152 // the link annotation ID of a Link element
153 // further note: since structure attributes can only be
154 // set during content creation, but links can be
155 // created after the fact, it is possible to set
156 // an arbitrary id as structure attribute here. In this
157 // case the arbitrary id has to be passed again when the
158 // actual link annotation is created via SetLinkPropertyID
159 LinkAnnotation,
160 // Language currently sets a LanguageType (see i18nlangtag/lang.h)
161 // which will be internally changed to a corresponding locale
162 Language
165 enum StructAttributeValue
167 Invalid,
168 NONE,
169 // Artifacts
170 Pagination, Layout, Page, Background,
171 Header, Footer, Watermark,
172 // Placement
173 Block, Inline, Before, After, Start, End,
174 // WritingMode
175 LrTb, RlTb, TbRl,
176 // TextAlign
177 Center, Justify,
178 // Width, Height,
179 Auto,
180 // BlockAlign
181 Middle,
182 // LineHeight
183 Normal,
184 // TextDecorationType
185 Underline, Overline, LineThrough,
186 // Scope
187 Row, Column, Both,
188 // Role
189 Rb, Cb, Pb, Tv,
190 // RubyAlign
191 RStart, RCenter, REnd, RJustify, RDistribute,
192 // RubyPosition
193 RBefore, RAfter, RWarichu, RInline,
194 // ListNumbering
195 Disc, Circle, Square, Decimal, UpperRoman, LowerRoman, UpperAlpha, LowerAlpha
198 enum class PageTransition
200 Regular,
201 SplitHorizontalInward, SplitHorizontalOutward,
202 SplitVerticalInward, SplitVerticalOutward,
203 BlindsHorizontal, BlindsVertical,
204 BoxInward, BoxOutward,
205 WipeLeftToRight, WipeBottomToTop, WipeRightToLeft, WipeTopToBottom,
206 Dissolve
209 enum WidgetType
211 PushButton, RadioButton, CheckBox, Edit, ListBox, ComboBox, Hierarchy,
212 Signature
215 enum FormatType
217 Text, Number, Time, Date
220 enum ErrorCode
222 // transparent object occurred and was draw opaque because
223 // PDF/A does not allow transparency
224 Warning_Transparency_Omitted_PDFA,
226 // transparent object occurred but is only supported since
227 // PDF 1.4
228 Warning_Transparency_Omitted_PDF13,
230 // a form action was exported that is not suitable for PDF/A
231 // the action was skipped
232 Warning_FormAction_Omitted_PDFA,
234 // transparent objects were converted to a bitmap in order
235 // to removetransparencies from the output
236 Warning_Transparency_Converted,
238 // signature generation failed
239 Error_Signature_Failed,
242 struct VCL_DLLPUBLIC AnyWidget
244 WidgetType Type; // primitive RTTI
245 public:
246 OUString Name; // a distinct name to identify the control
247 OUString Description;// descriptive text for the control (e.g. for tool tip)
248 OUString Text; // user text to appear on the control
249 DrawTextFlags TextStyle; // style flags
250 bool ReadOnly;
251 tools::Rectangle Location; // describes the area filled by the control
252 bool Border; // true: widget should have a border, false: no border
253 Color BorderColor;// COL_TRANSPARENT and Border=true means get color from application settings
254 bool Background; // true: widget shall draw its background, false: no background
255 Color BackgroundColor; // COL_TRANSPARENT and Background=true means get color from application settings
256 vcl::Font TextFont; // an empty font will be replaced by the
257 // appropriate font from the user settings
258 Color TextColor; // COL_TRANSPARENT will be replaced by the appropriate color from application settings
259 sal_Int32 TabOrder; // lowest number is first in tab order
261 /* style flags for text are those for OutputDevice::DrawText
262 allowed values are:
263 DrawTextFlags::Left, DrawTextFlags::Center, DrawTextFlags::Right, DrawTextFlags::Top,
264 DrawTextFlags::VCenter, DrawTextFlags::Bottom,
265 DrawTextFlags::MultiLine, DrawTextFlags::WordBreak
267 if TextStyle is 0, then each control will fill in default values
270 // note: the Name member comprises the field name of the resulting
271 // PDF field names need to be globally unique. Therefore if any
272 // Widget with an already used name is created, the name will be
273 // made unique by adding an underscore ('_') and an ascending number
274 // to the name.
276 AnyWidget( WidgetType eType ) :
277 Type( eType ),
278 TextStyle( DrawTextFlags::NONE ),
279 ReadOnly( false ),
280 Border( false ),
281 BorderColor( COL_TRANSPARENT ),
282 Background( false ),
283 BackgroundColor( COL_TRANSPARENT ),
284 TextColor( COL_TRANSPARENT ),
285 TabOrder( -1 )
287 virtual ~AnyWidget();
289 WidgetType getType() const { return Type; }
291 virtual std::shared_ptr<AnyWidget> Clone() const = 0;
293 protected:
294 // note that this equals the default compiler-generated copy-ctor, but we want to have it
295 // protected, to only allow sub classes to access it
296 AnyWidget( const AnyWidget& rSource )
297 :Type( rSource.Type )
298 ,Name( rSource.Name )
299 ,Description( rSource.Description )
300 ,Text( rSource.Text )
301 ,TextStyle( rSource.TextStyle )
302 ,ReadOnly( rSource.ReadOnly )
303 ,Location( rSource.Location )
304 ,Border( rSource.Border )
305 ,BorderColor( rSource.BorderColor )
306 ,Background( rSource.Background )
307 ,BackgroundColor( rSource.BackgroundColor )
308 ,TextFont( rSource.TextFont )
309 ,TextColor( rSource.TextColor )
310 ,TabOrder( rSource.TabOrder )
313 AnyWidget& operator=( const AnyWidget& ) = delete; // never implemented
316 struct PushButtonWidget final : public AnyWidget
318 /* If Dest is set to a valid link destination,
319 Then pressing the button will act as a goto
320 action within the document.
322 Else:
323 An empty URL means this button will reset the form.
325 If URL is not empty and Submit is set, then the URL
326 contained will be set as the URL to submit the
327 form to. In this case the submit method will be
328 either GET if SubmitGet is true or POST if
329 SubmitGet is false.
331 If URL is not empty and Submit is clear, then
332 the URL contained will be interpreted as a
333 hyperlink to be executed on pushing the button.
335 There will be no error checking or any kind of
336 conversion done to the URL parameter except this:
337 it will be output as 7bit Ascii. The URL
338 will appear literally in the PDF file produced
340 sal_Int32 Dest;
341 OUString URL;
342 bool Submit;
343 bool SubmitGet;
345 PushButtonWidget()
346 : AnyWidget( vcl::PDFWriter::PushButton ),
347 Dest( -1 ), Submit( false ), SubmitGet( false )
350 virtual std::shared_ptr<AnyWidget> Clone() const override
352 return std::make_shared<PushButtonWidget>( *this );
356 struct VCL_DLLPUBLIC CheckBoxWidget final : public AnyWidget
358 bool Checked;
359 OUString OnValue; // the value of the checkbox if it is selected
360 OUString OffValue; // the value of the checkbox if it is not selected
362 CheckBoxWidget()
363 : AnyWidget( vcl::PDFWriter::CheckBox ),
364 Checked( false )
367 virtual std::shared_ptr<AnyWidget> Clone() const override
369 return std::make_shared<CheckBoxWidget>( *this );
373 struct RadioButtonWidget final : public AnyWidget
375 bool Selected;
376 sal_Int32 RadioGroup;
377 OUString OnValue; // the value of the radio button if it is selected
378 OUString OffValue; // the value of the radio button if it is not selected
380 RadioButtonWidget()
381 : AnyWidget( vcl::PDFWriter::RadioButton ),
382 Selected( false ),
383 RadioGroup( 0 )
386 virtual std::shared_ptr<AnyWidget> Clone() const override
388 return std::make_shared<RadioButtonWidget>( *this );
390 // radio buttons having the same RadioGroup id comprise one
391 // logical radio button group, that is at most one of the RadioButtons
392 // in a group can be checked at any time
394 // note: a PDF radio button field consists of a named field
395 // containing unnamed checkbox child fields. The name of the
396 // radio button field is taken from the first RadioButtonWidget created
397 // in the group
400 struct VCL_DLLPUBLIC EditWidget final : public AnyWidget
402 bool MultiLine; // whether multiple lines are allowed
403 bool Password; // visible echo off
404 bool FileSelect; // field is a file selector
405 sal_Int32 MaxLen; // maximum field length in characters, 0 means unlimited
406 FormatType Format;
407 OUString CurrencySymbol;
408 sal_Int32 DecimalAccuracy;
409 bool PrependCurrencySymbol;
410 OUString TimeFormat;
411 OUString DateFormat;
413 EditWidget()
414 : AnyWidget( vcl::PDFWriter::Edit ),
415 MultiLine( false ),
416 Password( false ),
417 FileSelect( false ),
418 MaxLen( 0 ),
419 Format( FormatType::Text ),
420 DecimalAccuracy ( 0 ),
421 PrependCurrencySymbol( false )
424 virtual std::shared_ptr<AnyWidget> Clone() const override
426 return std::make_shared<EditWidget>( *this );
430 struct VCL_DLLPUBLIC ListBoxWidget final : public AnyWidget
432 bool DropDown;
433 bool MultiSelect;
434 std::vector<OUString> Entries;
435 std::vector<sal_Int32> SelectedEntries;
436 // if MultiSelect is false only the first entry of SelectedEntries
437 // will be taken into account. the same is implicit for PDF < 1.4
438 // since multiselect is a 1.4+ feature
440 ListBoxWidget()
441 : AnyWidget( vcl::PDFWriter::ListBox ),
442 DropDown( false ),
443 MultiSelect( false )
446 virtual std::shared_ptr<AnyWidget> Clone() const override
448 return std::make_shared<ListBoxWidget>( *this );
452 // note: PDF only supports dropdown comboboxes
453 struct ComboBoxWidget final : public AnyWidget
455 std::vector<OUString> Entries;
456 // set the current value in AnyWidget::Text
458 ComboBoxWidget()
459 : AnyWidget( vcl::PDFWriter::ComboBox )
462 virtual std::shared_ptr<AnyWidget> Clone() const override
464 return std::make_shared<ComboBoxWidget>( *this );
468 struct SignatureWidget final : public AnyWidget
470 SignatureWidget()
471 : AnyWidget( vcl::PDFWriter::Signature )
474 virtual std::shared_ptr<AnyWidget> Clone() const override
476 return std::make_shared<SignatureWidget>( *this );
480 enum ExportDataFormat { HTML, XML, FDF, PDF };
481 // see 3.6.1 of PDF 1.4 ref for details, used for 8.1 PDF v 1.4 ref also
482 // These emuns are treated as integer while reading/writing to configuration
483 enum PDFViewerPageMode
485 ModeDefault,
486 UseOutlines,
487 UseThumbs
489 // These emuns are treated as integer while reading/writing to configuration
490 enum PDFViewerAction
492 ActionDefault,
493 FitInWindow,
494 FitWidth,
495 FitVisible,
496 ActionZoom
498 // These enums are treated as integer while reading/writing to configuration
499 enum PDFPageLayout
501 DefaultLayout,
502 SinglePage,
503 Continuous,
504 ContinuousFacing
507 // These emuns are treated as integer while reading/writing to configuration
508 //what default action to generate in a PDF hyperlink to external document/site
509 enum PDFLinkDefaultAction
511 URIAction,
512 URIActionDestination,
513 LaunchAction
517 The following structure describes the permissions used in PDF security
519 struct PDFEncryptionProperties
522 //for both 40 and 128 bit security, see 3.5.2 PDF v 1.4 table 3.15, v 1.5 and v 1.6 table 3.20.
523 bool CanPrintTheDocument;
524 bool CanModifyTheContent;
525 bool CanCopyOrExtract;
526 bool CanAddOrModify;
527 //for revision 3 (bit 128 security) only
528 bool CanFillInteractive;
529 bool CanExtractForAccessibility;
530 bool CanAssemble;
531 bool CanPrintFull;
533 // encryption will only happen if EncryptionKey is not empty
534 // EncryptionKey is actually a construct out of OValue, UValue and DocumentIdentifier
535 // if these do not match, behavior is undefined, most likely an invalid PDF will be produced
536 // OValue, UValue, EncryptionKey and DocumentIdentifier can be computed from
537 // PDFDocInfo, Owner password and User password used the InitEncryption method which
538 // implements the algorithms described in the PDF reference chapter 3.5: Encryption
539 std::vector<sal_uInt8> OValue;
540 std::vector<sal_uInt8> UValue;
541 std::vector<sal_uInt8> EncryptionKey;
542 std::vector<sal_uInt8> DocumentIdentifier;
544 //permission default set for 128 bit, accessibility only
545 PDFEncryptionProperties() :
546 CanPrintTheDocument ( false ),
547 CanModifyTheContent ( false ),
548 CanCopyOrExtract ( false ),
549 CanAddOrModify ( false ),
550 CanFillInteractive ( false ),
551 CanExtractForAccessibility ( true ),
552 CanAssemble ( false ),
553 CanPrintFull ( false )
557 bool Encrypt() const
558 { return ! OValue.empty() && ! UValue.empty() && ! DocumentIdentifier.empty(); }
561 struct PDFDocInfo
563 OUString Title; // document title
564 OUString Author; // document author
565 OUString Subject; // subject
566 OUString Keywords; // keywords
567 css::util::DateTime ModificationDate;
568 css::uno::Sequence<OUString> Contributor; // http://purl.org/dc/elements/1.1/contributor
569 OUString Coverage; // http://purl.org/dc/elements/1.1/coverage
570 OUString Identifier; // http://purl.org/dc/elements/1.1/identifier
571 css::uno::Sequence<OUString> Publisher; // http://purl.org/dc/elements/1.1/publisher
572 css::uno::Sequence<OUString> Relation; // http://purl.org/dc/elements/1.1/relation
573 OUString Rights; // http://purl.org/dc/elements/1.1/rights
574 OUString Source; // http://purl.org/dc/elements/1.1/source
575 OUString Type; // http://purl.org/dc/elements/1.1/type
576 OUString Creator; // application that created the original document
577 OUString Producer; // OpenOffice
580 enum ColorMode
582 DrawColor, DrawGreyscale
585 struct PDFWriterContext
587 /* must be a valid file: URL usable by osl */
588 OUString URL;
589 /* the URL of the document being exported, used for relative links*/
590 OUString BaseURL;
591 /*if relative to file system should be formed*/
592 bool RelFsys;//i56629, i49415?, i64585?
593 /*the action to set the PDF hyperlink to*/
594 PDFWriter::PDFLinkDefaultAction DefaultLinkAction;
595 //convert the .od? target file type in a link to a .pdf type
596 //this is examined before doing anything else
597 bool ConvertOOoTargetToPDFTarget;
598 //when the file type is .pdf, force the GoToR action
599 bool ForcePDFAction;
601 /* decides the PDF language level to be produced */
602 PDFVersion Version;
604 /* PDF/UA compliance */
605 bool UniversalAccessibilityCompliance;
607 /* valid for PDF >= 1.4
608 causes the MarkInfo entry in the document catalog to be set
610 bool Tagged;
611 /* determines in which format a form
612 will be submitted.
614 PDFWriter::ExportDataFormat SubmitFormat;
615 bool AllowDuplicateFieldNames;
616 /* the following data members are used to customize the PDF viewer
617 preferences
619 /* see 3.6.1 PDF v 1.4 ref*/
620 PDFWriter::PDFViewerPageMode PDFDocumentMode;
621 PDFWriter::PDFViewerAction PDFDocumentAction;
622 // in percent, valid only if PDFDocumentAction == ActionZoom
623 sal_Int32 Zoom;
625 /* see 8.6 PDF v 1.4 ref
626 specifies whether to hide the viewer tool
627 bars when the document is active.
629 bool HideViewerToolbar;
630 bool HideViewerMenubar;
631 bool HideViewerWindowControls;
632 bool FitWindow;
633 bool OpenInFullScreenMode;
634 bool CenterWindow;
635 bool DisplayPDFDocumentTitle;
636 PDFPageLayout PageLayout;
637 bool FirstPageLeft;
638 // initially visible page in viewer (starting with 0 for first page)
639 sal_Int32 InitialPage;
640 sal_Int32 OpenBookmarkLevels; // -1 means all levels
642 PDFWriter::PDFEncryptionProperties Encryption;
643 PDFWriter::PDFDocInfo DocumentInfo;
645 bool SignPDF;
646 OUString SignLocation;
647 OUString SignPassword;
648 OUString SignReason;
649 OUString SignContact;
650 css::lang::Locale DocumentLocale; // defines the document default language
651 sal_uInt32 DPIx, DPIy; // how to handle MapMode( MapUnit::MapPixel )
652 // 0 here specifies a default handling
653 PDFWriter::ColorMode ColorMode;
654 css::uno::Reference< css::security::XCertificate> SignCertificate;
655 OUString SignTSA;
656 /// Use reference XObject markup for PDF images.
657 bool UseReferenceXObject;
659 PDFWriterContext() :
660 RelFsys( false ), //i56629, i49415?, i64585?
661 DefaultLinkAction( PDFWriter::URIAction ),
662 ConvertOOoTargetToPDFTarget( false ),
663 ForcePDFAction( false ),
664 Version(PDFWriter::PDFVersion::PDF_1_7),
665 UniversalAccessibilityCompliance( false ),
666 Tagged( false ),
667 SubmitFormat( PDFWriter::FDF ),
668 AllowDuplicateFieldNames( false ),
669 PDFDocumentMode( PDFWriter::ModeDefault ),
670 PDFDocumentAction( PDFWriter::ActionDefault ),
671 Zoom( 100 ),
672 HideViewerToolbar( false ),
673 HideViewerMenubar( false ),
674 HideViewerWindowControls( false ),
675 FitWindow( false ),
676 OpenInFullScreenMode( false ),
677 CenterWindow( false ),
678 DisplayPDFDocumentTitle( true ),
679 PageLayout( PDFWriter::DefaultLayout ),
680 FirstPageLeft( false ),
681 InitialPage( 1 ),
682 OpenBookmarkLevels( -1 ),
683 SignPDF( false ),
684 DPIx( 0 ),
685 DPIy( 0 ),
686 ColorMode( PDFWriter::DrawColor ),
687 UseReferenceXObject( false )
691 VCL_DLLPUBLIC PDFWriter( const PDFWriterContext& rContext, const css::uno::Reference< css::beans::XMaterialHolder >& );
692 VCL_DLLPUBLIC ~PDFWriter();
694 /** Returns an OutputDevice for formatting
695 This Output device is guaranteed to use the same
696 font metrics as the resulting PDF file.
698 @returns
699 the reference output device
701 VCL_DLLPUBLIC OutputDevice* GetReferenceDevice();
703 /** Creates a new page to fill
704 If width and height are not set the page size
705 is inherited from the page tree
706 other effects:
707 resets the graphics state: MapMode, Font
708 Colors and other state information MUST
709 be set again or are undefined.
711 VCL_DLLPUBLIC void NewPage( double nPageWidth, double nPageHeight, Orientation eOrientation = Orientation::Inherit );
712 /** Play a metafile like an outputdevice would do
714 struct PlayMetafileContext
716 int m_nMaxImageResolution;
717 bool m_bOnlyLosslessCompression;
718 int m_nJPEGQuality;
719 bool m_bTransparenciesWereRemoved;
721 PlayMetafileContext()
722 : m_nMaxImageResolution( 0 )
723 , m_bOnlyLosslessCompression( false )
724 , m_nJPEGQuality( 90 )
725 , m_bTransparenciesWereRemoved( false )
729 VCL_DLLPUBLIC void PlayMetafile( const GDIMetaFile&, const PlayMetafileContext&, vcl::PDFExtOutDevData* pDevDat = nullptr );
731 /* sets the document locale originally passed with the context to a new value
732 * only affects the output if used before calling Emit.
734 VCL_DLLPUBLIC void SetDocumentLocale( const css::lang::Locale& rDocLocale );
736 /* finishes the file */
737 VCL_DLLPUBLIC bool Emit();
740 * Get a list of errors that occurred during processing
741 * this should enable the producer to give feedback about
742 * any anomalies that might have occurred
744 VCL_DLLPUBLIC std::set< ErrorCode > const & GetErrors() const;
746 // uses 128bit encryption
747 VCL_DLLPUBLIC static css::uno::Reference< css::beans::XMaterialHolder >
748 InitEncryption( const OUString& i_rOwnerPassword,
749 const OUString& i_rUserPassword
752 /* functions for graphics state */
753 /* flag values: see vcl/outdev.hxx */
754 VCL_DLLPUBLIC void Push( PushFlags nFlags = PushFlags::ALL );
755 VCL_DLLPUBLIC void Pop();
757 VCL_DLLPUBLIC void SetClipRegion();
758 VCL_DLLPUBLIC void SetClipRegion( const basegfx::B2DPolyPolygon& rRegion );
759 void MoveClipRegion( tools::Long nHorzMove, tools::Long nVertMove );
760 void IntersectClipRegion( const tools::Rectangle& rRect );
761 void IntersectClipRegion( const basegfx::B2DPolyPolygon& rRegion );
763 void SetLayoutMode( vcl::text::ComplexTextLayoutFlags nMode );
764 void SetDigitLanguage( LanguageType eLang );
766 void SetLineColor( const Color& rColor );
767 void SetLineColor() { SetLineColor( COL_TRANSPARENT ); }
769 void SetFillColor( const Color& rColor );
770 void SetFillColor() { SetFillColor( COL_TRANSPARENT ); }
772 VCL_DLLPUBLIC void SetFont( const vcl::Font& rNewFont );
773 VCL_DLLPUBLIC void SetTextColor( const Color& rColor );
774 void SetTextFillColor();
775 void SetTextFillColor( const Color& rColor );
777 void SetTextLineColor();
778 void SetTextLineColor( const Color& rColor );
779 void SetOverlineColor();
780 void SetOverlineColor( const Color& rColor );
781 void SetTextAlign( ::TextAlign eAlign );
783 VCL_DLLPUBLIC void SetMapMode( const MapMode& rNewMapMode );
786 /* actual drawing functions */
787 VCL_DLLPUBLIC void DrawText( const Point& rPos, const OUString& rText );
789 void DrawTextLine( const Point& rPos, tools::Long nWidth,
790 FontStrikeout eStrikeout,
791 FontLineStyle eUnderline,
792 FontLineStyle eOverline );
793 void DrawTextArray( const Point& rStartPt, const OUString& rStr,
794 KernArraySpan aKernArray,
795 std::span<const sal_Bool> pKashidaAry,
796 sal_Int32 nIndex,
797 sal_Int32 nLen );
798 void DrawStretchText( const Point& rStartPt, sal_Int32 nWidth,
799 const OUString& rStr,
800 sal_Int32 nIndex, sal_Int32 nLen );
801 VCL_DLLPUBLIC void DrawText( const tools::Rectangle& rRect,
802 const OUString& rStr, DrawTextFlags nStyle );
804 void DrawPixel( const Point& rPt, const Color& rColor );
805 void DrawPixel( const Point& rPt )
806 { DrawPixel( rPt, COL_TRANSPARENT ); }
808 void DrawLine( const Point& rStartPt, const Point& rEndPt );
809 void DrawLine( const Point& rStartPt, const Point& rEndPt,
810 const LineInfo& rLineInfo );
811 VCL_DLLPUBLIC void DrawPolyLine( const tools::Polygon& rPoly );
812 void DrawPolyLine( const tools::Polygon& rPoly,
813 const LineInfo& rLineInfo );
814 void DrawPolyLine( const tools::Polygon& rPoly, const ExtLineInfo& rInfo );
815 void DrawPolygon( const tools::Polygon& rPoly );
816 void DrawPolyPolygon( const tools::PolyPolygon& rPolyPoly );
817 void DrawRect( const tools::Rectangle& rRect );
818 void DrawRect( const tools::Rectangle& rRect,
819 sal_uInt32 nHorzRount, sal_uInt32 nVertRound );
820 void DrawEllipse( const tools::Rectangle& rRect );
821 void DrawArc( const tools::Rectangle& rRect,
822 const Point& rStartPt, const Point& rEndPt );
823 void DrawPie( const tools::Rectangle& rRect,
824 const Point& rStartPt, const Point& rEndPt );
825 void DrawChord( const tools::Rectangle& rRect,
826 const Point& rStartPt, const Point& rEndPt );
828 void DrawBitmap( const Point& rDestPt, const Size& rDestSize,
829 const Bitmap& rBitmap, const Graphic& rGraphic );
831 void DrawBitmapEx( const Point& rDestPt, const Size& rDestSize,
832 const BitmapEx& rBitmapEx );
834 void DrawGradient( const tools::Rectangle& rRect, const Gradient& rGradient );
835 void DrawGradient( const tools::PolyPolygon& rPolyPoly, const Gradient& rGradient );
837 void DrawHatch( const tools::PolyPolygon& rPolyPoly, const Hatch& rHatch );
839 void DrawWallpaper( const tools::Rectangle& rRect, const Wallpaper& rWallpaper );
840 void DrawTransparent( const tools::PolyPolygon& rPolyPoly,
841 sal_uInt16 nTransparencePercent );
843 /** Start a transparency group
845 Drawing operations can be grouped together to acquire a common transparency
846 behaviour; after calling BeginTransparencyGroup all drawing
847 operations will be grouped together into a transparent object.
849 The transparency behaviour is set with one of the EndTransparencyGroup
850 calls and can be either a constant transparency factor or a transparent
851 soft mask in form of an 8 bit gray scale bitmap.
853 It is permissible to nest transparency group.
855 Transparency groups MUST NOT span multiple pages
857 Transparency is a feature introduced in PDF1.4, so transparency group
858 will be ignored if the produced PDF has a lower version. The drawing
859 operations will be emitted normally.
861 VCL_DLLPUBLIC void BeginTransparencyGroup();
863 /** End a transparency group with constant transparency factor
865 This ends a transparency group and inserts it on the current page. The
866 coordinates of the group result out of the grouped drawing operations.
868 @param rBoundRect
869 The bounding rectangle of the group
871 @param nTransparencePercent
872 The transparency factor
874 VCL_DLLPUBLIC void EndTransparencyGroup( const tools::Rectangle& rBoundRect, sal_uInt16 nTransparencePercent );
876 /** Insert a JPG encoded image (optionally with mask)
878 @param rJPGData
879 a Stream containing the encoded image
881 @param bIsTrueColor
882 true: jpeg is 24 bit true color, false: jpeg is 8 bit greyscale
884 @param rSrcSizePixel
885 size in pixel of the image
887 @param rTargetArea
888 where to put the image
890 @param rMask
891 optional mask; if not empty it must have
892 the same pixel size as the image and
893 be either 1 bit black&white or 8 bit grey
895 void DrawJPGBitmap( SvStream& rJPGData, bool bIsTrueColor, const Size& rSrcSizePixel, const tools::Rectangle& rTargetArea, const AlphaMask& rAlphaMask, const Graphic& rGraphic );
897 /** Create a new named destination to be used in a link from another PDF document
899 @param sDestName
900 the name (label) of the bookmark, to be used to jump to
902 @param rRect
903 target rectangle on page to be displayed if dest is jumped to
905 @param nPageNr
906 number of page the dest is on (as returned by NewPage)
907 or -1 in which case the current page is used
909 @param eType
910 what dest type to use
912 @returns
913 the destination id (to be used in SetLinkDest) or
914 -1 if page id does not exist
916 sal_Int32 CreateNamedDest( const OUString& sDestName, const tools::Rectangle& rRect, sal_Int32 nPageNr, DestAreaType eType );
917 /** Create a new destination to be used in a link
919 @param rRect
920 target rectangle on page to be displayed if dest is jumped to
922 @param nPageNr
923 number of page the dest is on (as returned by NewPage)
924 or -1 in which case the current page is used
926 @param eType
927 what dest type to use
929 @returns
930 the destination id (to be used in SetLinkDest) or
931 -1 if page id does not exist
933 sal_Int32 CreateDest( const tools::Rectangle& rRect, sal_Int32 nPageNr, DestAreaType eType );
934 /** Create a new link on a page
936 @param rRect
937 active rectangle of the link (that is the area that has to be
938 hit to activate the link)
940 @param nPageNr
941 number of page the link is on (as returned by NewPage)
942 or -1 in which case the current page is used
944 @returns
945 the link id (to be used in SetLinkDest, SetLinkURL) or
946 -1 if page id does not exist
948 sal_Int32 CreateLink(const tools::Rectangle& rRect, sal_Int32 nPageNr, OUString const& rAltText);
950 /// Creates a screen annotation.
951 sal_Int32 CreateScreen(const tools::Rectangle& rRect, sal_Int32 nPageNr, OUString const& rAltText, OUString const& rMimeType);
953 /** creates a destination which is not intended to be referred to by a link, but by a public destination Id.
955 Form widgets, for instance, might refer to a destination, without ever actually creating a source link to
956 point to this destination. In such cases, a public destination Id will be assigned to the form widget,
957 and later on, the concrete destination data for this public Id will be registered using RegisterDestReference.
959 @param nDestId
960 destination ID
962 @param rRect
963 target rectangle on page to be displayed if dest is jumped to
965 @param nPageNr
966 number of page the dest is on (as returned by NewPage)
967 or -1 in which case the current page is used
969 @param eType
970 what dest type to use
972 @returns
973 the internal destination Id.
975 sal_Int32 RegisterDestReference( sal_Int32 nDestId, const tools::Rectangle& rRect, sal_Int32 nPageNr, DestAreaType eType );
978 /** Set the destination for a link
979 will change a URL type link to a dest link if necessary
981 @param nLinkId
982 the link to be changed
984 @param nDestId
985 the dest the link shall point to
987 void SetLinkDest( sal_Int32 nLinkId, sal_Int32 nDestId );
988 /** Set the URL for a link
989 will change a dest type link to a URL type link if necessary
990 @param nLinkId
991 the link to be changed
993 @param rURL
994 the URL the link shall point to.
995 The URL will be parsed (and corrected) by the com.sun.star.util.URLTransformer
996 service; the result will then appear literally in the PDF file produced
998 void SetLinkURL( sal_Int32 nLinkId, const OUString& rURL );
1000 /// Sets the URL of a linked screen annotation.
1001 void SetScreenURL(sal_Int32 nScreenId, const OUString& rURL);
1002 /// Sets the URL of an embedded screen annotation.
1003 void SetScreenStream(sal_Int32 nScreenId, const OUString& rURL);
1005 /** Resolve link in logical structure
1007 If a link is created after the corresponding visual appearance was drawn
1008 it is not possible to set the link id as a property attribute to the
1009 link structure item that should be created in tagged PDF around the
1010 visual appearance of a link.
1012 For this reason an arbitrary id can be given to
1013 SetStructureAttributeNumerical at the time the text for
1014 the link is drawn. To resolve this arbitrary id again when the actual
1015 link annotation is created use SetLinkPropertyID. When Emit
1016 finally gets called all LinkAnnotation type structure attributes
1017 will be replaced with the correct link id.
1019 CAUTION: this technique must be used either for all or none of the links
1020 in a document since the link id space and arbitrary property id space
1021 could overlap and it would be impossible to resolve whether a Link
1022 structure attribute value was arbitrary or already a real id.
1024 @param nLinkId
1025 the link to be mapped
1027 @param nPropertyID
1028 the arbitrary id set in a Link structure element to address
1029 the link with real id nLinkId
1031 void SetLinkPropertyID( sal_Int32 nLinkId, sal_Int32 nPropertyID );
1032 /** Create a new outline item
1034 @param nParent
1035 declares the parent of the new item in the outline hierarchy.
1036 An invalid value will result in a new toplevel item.
1038 @param rText
1039 sets the title text of the item
1041 @param nDestID
1042 declares which Dest (created with CreateDest) the outline item
1043 will point to
1045 @returns
1046 the outline item id of the new item
1048 sal_Int32 CreateOutlineItem( sal_Int32 nParent, std::u16string_view rText, sal_Int32 nDestID );
1050 /** Create a new note on a page
1052 @param rRect
1053 active rectangle of the note (that is the area that has to be
1054 hit to popup the annotation)
1056 @param rNote
1057 specifies the contents of the note
1059 @param nPageNr
1060 number of page the note is on (as returned by NewPage)
1061 or -1 in which case the current page is used
1063 void CreateNote( const tools::Rectangle& rRect, const PDFNote& rNote, sal_Int32 nPageNr );
1065 /** begin a new logical structure element
1067 BeginStructureElement/EndStructureElement calls build the logical structure
1068 of the PDF - the basis for tagged PDF. Structural elements are implemented
1069 using marked content tags. Each structural element can contain sub elements
1070 (e.g. a section can contain a heading and a paragraph). The structure hierarchy
1071 is build automatically from the Begin/EndStructureElement calls.
1073 The easy way is to call WrapBeginStructureElement, but it's also possible
1074 to call EnsureStructureElement/InitStructureElement/BeginStructureElement
1075 (its 3 parts) manually for more control; this way a placeholder SE can be
1076 inserted and initialised later.
1078 A structural element need not be contained on one page; e.g. paragraphs often
1079 run from one page to the next. In this case the corresponding EndStructureElement
1080 must be called while drawing the next page.
1082 BeginStructureElement and EndStructureElement must be called only after
1083 PDFWriter::NewPage has been called and before PDFWriter::Emit gets called. The
1084 current page number is an implicit context parameter for Begin/EndStructureElement.
1086 For pagination artifacts that are not part of the logical structure
1087 of the document (like header, footer or page number) the special
1088 StructElement NonStructElement exists. To place content
1089 outside of the structure tree simply call
1090 BeginStructureElement( NonStructElement ) then draw your
1091 content and then call EndStructureElement(). All children
1092 of a NonStructElement will not be part of the structure.
1093 Nonetheless if you add a child structural element to a
1094 NonStructElement you will still have to call
1095 EndStructureElement for it. Best think of the structure
1096 tree as a stack.
1098 Note: there is always one structural element in existence without having
1099 called BeginStructureElement; this is the root of the structure
1100 tree (called StructTreeRoot). The StructTreeRoot has always the id 0.
1102 @param eType
1103 denotes what kind of element to begin (e.g. a heading or paragraph)
1105 @param rAlias
1106 the specified alias will be used as structure tag. Also an entry in the PDF's
1107 role map will be created mapping alias to regular structure type.
1109 @returns
1110 the new structure element's id for use in SetCurrentStructureElement
1112 VCL_DLLPUBLIC void BeginStructureElement(sal_Int32 id);
1113 VCL_DLLPUBLIC sal_Int32 EnsureStructureElement();
1114 VCL_DLLPUBLIC void InitStructureElement(sal_Int32 id, PDFWriter::StructElement eType, std::u16string_view rAlias);
1116 /** end the current logical structure element
1118 Close the current structure element. The current element's
1119 parent becomes the current structure element again.
1121 @see BeginStructureElement
1123 VCL_DLLPUBLIC void EndStructureElement();
1124 /** set the current structure element
1126 For different purposes it may be useful to paint a structure element's
1127 content discontinuously. In that case an already existing structure element
1128 can be appended to by using SetCurrentStructureElement. The
1129 referenced structure element becomes the current structure element with
1130 all consequences: all following structure elements are appended as children
1131 of the current element.
1133 @param nElement
1134 the id of the new current structure element
1136 void SetCurrentStructureElement( sal_Int32 nElement );
1138 /** set a structure attribute on the current structural element
1140 SetStructureAttribute sets an attribute of the current structural element to a
1141 new value. A consistency check is performed before actually setting the value;
1142 if the check fails, the function returns False and the attribute remains
1143 unchanged.
1145 @param eAttr
1146 denotes what attribute to change
1148 @param eVal
1149 the value to set the attribute to
1151 VCL_DLLPUBLIC void SetStructureAttribute( enum StructAttribute eAttr, enum StructAttributeValue eVal );
1152 /** set a structure attribute on the current structural element
1154 SetStructureAttributeNumerical sets an attribute of the current structural element
1155 to a new numerical value. A consistency check is performed before actually setting
1156 the value; if the check fails, the function returns False and the attribute
1157 remains unchanged.
1159 @param eAttr
1160 denotes what attribute to change
1162 @param nValue
1163 the value to set the attribute to
1165 void SetStructureAttributeNumerical( enum StructAttribute eAttr, sal_Int32 nValue );
1166 /** set the bounding box of a structural element
1168 SetStructureBoundingBox sets the BBox attribute to a new value. Since the BBox
1169 attribute can only be applied to Table, Figure,
1170 Form and Formula elements, a call of this function
1171 for other element types will be ignored and the BBox attribute not be set.
1173 @param rRect
1174 the new bounding box for the structural element
1176 void SetStructureBoundingBox( const tools::Rectangle& rRect );
1178 /** set the annotations that should be referenced as children of the
1179 current structural element.
1181 void SetStructureAnnotIds(::std::vector<sal_Int32> const& rAnnotIds);
1183 /** set the ActualText attribute of a structural element
1185 ActualText contains the Unicode text without layout artifacts that is shown by
1186 a structural element. For example if a line is ended prematurely with a break in
1187 a word and continued on the next line (e.g. "happen-<newline>stance") the
1188 corresponding ActualText would contain the unbroken line (e.g. "happenstance").
1190 @param rText
1191 contains the complete logical text the structural element displays.
1193 void SetActualText( const OUString& rText );
1195 /** set the Alt attribute of a structural element
1197 Alt is s replacement text describing the contents of a structural element. This
1198 is mainly used by accessibility applications; e.g. a screen reader would read
1199 the Alt replacement text for an image to a visually impaired user.
1201 @param rText
1202 contains the replacement text for the structural element
1204 void SetAlternateText( const OUString& rText );
1206 /** Sets the transitional effect to be applied when the current page gets shown.
1208 @param eType
1209 the kind of effect to be used; use Regular to disable transitional effects
1210 for this page
1212 @param nMilliSec
1213 the duration of the transitional effect in milliseconds;
1214 set 0 to disable transitional effects
1216 @param nPageNr
1217 the page number to apply the effect to; -1 denotes the current page
1219 void SetPageTransition( PageTransition eType, sal_uInt32 nMilliSec, sal_Int32 nPageNr );
1221 /** create a new form control
1223 This function creates a new form control in the PDF and sets its various
1224 properties. Do not pass an actual AnyWidget as rControlType
1225 will be cast to the type described by the type member.
1227 @param rControlType
1228 a descendant of AnyWidget determining the control's properties
1230 @returns
1231 the new control's id for reference purposes
1233 sal_Int32 CreateControl( const AnyWidget& rControlType );
1235 /** Attaches an additional file to the PDF file
1237 This function adds an arbitrary stream that represents an attached file
1238 in the PDF file.
1240 This also adds an additional stream array entry (with the mimetype) in
1241 the trailer dictionary for backwards compatibility.
1243 @param rFileName
1244 the filename of the additional file as presented in the stream
1246 @param rMimeType
1247 the mimetype of the stream
1249 @param pStream
1250 the interface to the additional stream
1252 VCL_DLLPUBLIC void AddAttachedFile(OUString const& rFileName, OUString const& rMimeType, OUString const& rDescription, std::unique_ptr<PDFOutputStream> pStream);
1254 /// Write rString as a PDF hex string into rBuffer.
1255 static void AppendUnicodeTextString(const OUString& rString, OStringBuffer& rBuffer);
1257 /// Get current date/time in PDF D:YYYYMMDDHHMMSS form.
1258 static OString GetDateTime();
1263 #endif // INCLUDED_VCL_PDFWRITER_HXX
1265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */