|
| 1 | +// Copyright 2019-2026 Chris Mohan, Jaben Cargman |
| 2 | +// and GotenbergSharpApiClient Contributors |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | + |
| 16 | +using Gotenberg.Sharp.API.Client.Domain.ValueObjects; |
| 17 | + |
| 18 | +namespace Gotenberg.Sharp.API.Client.Domain.Builders.Faceted; |
| 19 | + |
| 20 | +/// <summary> |
| 21 | +/// Configures LibreOffice-specific conversion options for the /forms/libreoffice/convert route. |
| 22 | +/// </summary> |
| 23 | +public sealed class LibreOfficeOptionsBuilder |
| 24 | +{ |
| 25 | + private readonly LibreOfficeOptions _options; |
| 26 | + |
| 27 | + internal LibreOfficeOptionsBuilder(LibreOfficeOptions options) |
| 28 | + { |
| 29 | + _options = options; |
| 30 | + } |
| 31 | + |
| 32 | + // Layout |
| 33 | + |
| 34 | + public LibreOfficeOptionsBuilder SetSinglePageSheets(bool value = true) |
| 35 | + { |
| 36 | + _options.SinglePageSheets = value; |
| 37 | + return this; |
| 38 | + } |
| 39 | + |
| 40 | + public LibreOfficeOptionsBuilder SetSkipEmptyPages(bool value = true) |
| 41 | + { |
| 42 | + _options.SkipEmptyPages = value; |
| 43 | + return this; |
| 44 | + } |
| 45 | + |
| 46 | + public LibreOfficeOptionsBuilder SetExportPlaceholders(bool value = true) |
| 47 | + { |
| 48 | + _options.ExportPlaceholders = value; |
| 49 | + return this; |
| 50 | + } |
| 51 | + |
| 52 | + // Image compression |
| 53 | + |
| 54 | + public LibreOfficeOptionsBuilder SetLosslessImageCompression(bool value = true) |
| 55 | + { |
| 56 | + _options.LosslessImageCompression = value; |
| 57 | + return this; |
| 58 | + } |
| 59 | + |
| 60 | + public LibreOfficeOptionsBuilder SetQuality(ImageQuality quality) |
| 61 | + { |
| 62 | + _options.Quality = quality ?? throw new ArgumentNullException(nameof(quality)); |
| 63 | + return this; |
| 64 | + } |
| 65 | + |
| 66 | + public LibreOfficeOptionsBuilder SetQuality(int quality) |
| 67 | + { |
| 68 | + return SetQuality(ImageQuality.Create(quality)); |
| 69 | + } |
| 70 | + |
| 71 | + public LibreOfficeOptionsBuilder SetReduceImageResolution(bool value = true) |
| 72 | + { |
| 73 | + _options.ReduceImageResolution = value; |
| 74 | + return this; |
| 75 | + } |
| 76 | + |
| 77 | + public LibreOfficeOptionsBuilder SetMaxImageResolution(ImageResolution resolution) |
| 78 | + { |
| 79 | + _options.MaxImageResolution = resolution ?? throw new ArgumentNullException(nameof(resolution)); |
| 80 | + return this; |
| 81 | + } |
| 82 | + |
| 83 | + public LibreOfficeOptionsBuilder SetMaxImageResolution(int dpi) |
| 84 | + { |
| 85 | + return SetMaxImageResolution(ImageResolution.Create(dpi)); |
| 86 | + } |
| 87 | + |
| 88 | + // Notes & slides |
| 89 | + |
| 90 | + public LibreOfficeOptionsBuilder SetExportNotes(bool value = true) |
| 91 | + { |
| 92 | + _options.ExportNotes = value; |
| 93 | + return this; |
| 94 | + } |
| 95 | + |
| 96 | + public LibreOfficeOptionsBuilder SetExportNotesPages(bool value = true) |
| 97 | + { |
| 98 | + _options.ExportNotesPages = value; |
| 99 | + return this; |
| 100 | + } |
| 101 | + |
| 102 | + public LibreOfficeOptionsBuilder SetExportOnlyNotesPages(bool value = true) |
| 103 | + { |
| 104 | + _options.ExportOnlyNotesPages = value; |
| 105 | + return this; |
| 106 | + } |
| 107 | + |
| 108 | + public LibreOfficeOptionsBuilder SetExportNotesInMargin(bool value = true) |
| 109 | + { |
| 110 | + _options.ExportNotesInMargin = value; |
| 111 | + return this; |
| 112 | + } |
| 113 | + |
| 114 | + public LibreOfficeOptionsBuilder SetExportHiddenSlides(bool value = true) |
| 115 | + { |
| 116 | + _options.ExportHiddenSlides = value; |
| 117 | + return this; |
| 118 | + } |
| 119 | + |
| 120 | + // Links |
| 121 | + |
| 122 | + public LibreOfficeOptionsBuilder SetConvertOooTargetToPdfTarget(bool value = true) |
| 123 | + { |
| 124 | + _options.ConvertOooTargetToPdfTarget = value; |
| 125 | + return this; |
| 126 | + } |
| 127 | + |
| 128 | + public LibreOfficeOptionsBuilder SetExportLinksRelativeFsys(bool value = true) |
| 129 | + { |
| 130 | + _options.ExportLinksRelativeFsys = value; |
| 131 | + return this; |
| 132 | + } |
| 133 | + |
| 134 | + // Document outline |
| 135 | + |
| 136 | + public LibreOfficeOptionsBuilder SetUpdateIndexes(bool value = true) |
| 137 | + { |
| 138 | + _options.UpdateIndexes = value; |
| 139 | + return this; |
| 140 | + } |
| 141 | + |
| 142 | + public LibreOfficeOptionsBuilder SetExportBookmarks(bool value = true) |
| 143 | + { |
| 144 | + _options.ExportBookmarks = value; |
| 145 | + return this; |
| 146 | + } |
| 147 | + |
| 148 | + public LibreOfficeOptionsBuilder SetExportBookmarksToPdfDestination(bool value = true) |
| 149 | + { |
| 150 | + _options.ExportBookmarksToPdfDestination = value; |
| 151 | + return this; |
| 152 | + } |
| 153 | + |
| 154 | + public LibreOfficeOptionsBuilder SetAddOriginalDocumentAsStream(bool value = true) |
| 155 | + { |
| 156 | + _options.AddOriginalDocumentAsStream = value; |
| 157 | + return this; |
| 158 | + } |
| 159 | + |
| 160 | + // Form fields |
| 161 | + |
| 162 | + public LibreOfficeOptionsBuilder SetExportFormFields(bool value = true) |
| 163 | + { |
| 164 | + _options.ExportFormFields = value; |
| 165 | + return this; |
| 166 | + } |
| 167 | + |
| 168 | + public LibreOfficeOptionsBuilder SetAllowDuplicateFieldNames(bool value = true) |
| 169 | + { |
| 170 | + _options.AllowDuplicateFieldNames = value; |
| 171 | + return this; |
| 172 | + } |
| 173 | + |
| 174 | + // Native watermark |
| 175 | + |
| 176 | + public LibreOfficeOptionsBuilder SetNativeWatermarkText(string text) |
| 177 | + { |
| 178 | + if (string.IsNullOrWhiteSpace(text)) |
| 179 | + throw new ArgumentException("Watermark text must not be null or empty.", nameof(text)); |
| 180 | + |
| 181 | + _options.NativeWatermarkText = text; |
| 182 | + return this; |
| 183 | + } |
| 184 | + |
| 185 | + public LibreOfficeOptionsBuilder SetNativeWatermarkColor(int rgbDecimal) |
| 186 | + { |
| 187 | + _options.NativeWatermarkColor = rgbDecimal; |
| 188 | + return this; |
| 189 | + } |
| 190 | + |
| 191 | + public LibreOfficeOptionsBuilder SetNativeWatermarkFontHeight(int fontHeight) |
| 192 | + { |
| 193 | + if (fontHeight < 0) |
| 194 | + throw new ArgumentOutOfRangeException(nameof(fontHeight), "Font height must be non-negative."); |
| 195 | + |
| 196 | + _options.NativeWatermarkFontHeight = fontHeight; |
| 197 | + return this; |
| 198 | + } |
| 199 | + |
| 200 | + public LibreOfficeOptionsBuilder SetNativeWatermarkRotateAngle(int angle) |
| 201 | + { |
| 202 | + _options.NativeWatermarkRotateAngle = angle; |
| 203 | + return this; |
| 204 | + } |
| 205 | + |
| 206 | + public LibreOfficeOptionsBuilder SetNativeWatermarkFontName(string fontName) |
| 207 | + { |
| 208 | + if (string.IsNullOrWhiteSpace(fontName)) |
| 209 | + throw new ArgumentException("Font name must not be null or empty.", nameof(fontName)); |
| 210 | + |
| 211 | + _options.NativeWatermarkFontName = fontName; |
| 212 | + return this; |
| 213 | + } |
| 214 | + |
| 215 | + public LibreOfficeOptionsBuilder SetNativeTiledWatermarkText(string text) |
| 216 | + { |
| 217 | + if (string.IsNullOrWhiteSpace(text)) |
| 218 | + throw new ArgumentException("Tiled watermark text must not be null or empty.", nameof(text)); |
| 219 | + |
| 220 | + _options.NativeTiledWatermarkText = text; |
| 221 | + return this; |
| 222 | + } |
| 223 | + |
| 224 | + // Source file password |
| 225 | + |
| 226 | + public LibreOfficeOptionsBuilder SetPassword(string password) |
| 227 | + { |
| 228 | + if (string.IsNullOrWhiteSpace(password)) |
| 229 | + throw new ArgumentException("Password must not be null or empty.", nameof(password)); |
| 230 | + |
| 231 | + _options.Password = password; |
| 232 | + return this; |
| 233 | + } |
| 234 | +} |
0 commit comments