Debian Codegraph @

qt6/src/poppler-converter.h

raw
1 /* poppler-converter.h: qt interface to poppler
2 * Copyright (C) 2005, Net Integration Technologies, Inc.
3 * Copyright (C) 2005, 2007, Brad Hards <[email protected]>
4 * Copyright (C) 2005-2015, 2017-2022, Albert Astals Cid <[email protected]>
5 * Copyright (C) 2005, Stefan Kebekus <[email protected]>
6 * Copyright (C) 2006-2011, Pino Toscano <[email protected]>
7 * Copyright (C) 2009 Shawn Rutledge <[email protected]>
8 * Copyright (C) 2010 Suzuki Toshiya <[email protected]>
9 * Copyright (C) 2010 Matthias Fauconneau <[email protected]>
10 * Copyright (C) 2011 Andreas Hartmetz <[email protected]>
11 * Copyright (C) 2011 Glad Deschrijver <[email protected]>
12 * Copyright (C) 2012, Guillermo A. Amaral B. <[email protected]>
13 * Copyright (C) 2012, Fabio D'Urso <[email protected]>
14 * Copyright (C) 2012, Tobias Koenig <[email protected]>
15 * Copyright (C) 2012, 2014, 2015, 2018, 2019 Adam Reichold <[email protected]>
16 * Copyright (C) 2012, 2013 Thomas Freitag <[email protected]>
17 * Copyright (C) 2013 Anthony Granger <[email protected]>
18 * Copyright (C) 2016 Jakub Alba <[email protected]>
19 * Copyright (C) 2017, 2020, 2021 Oliver Sander <[email protected]>
20 * Copyright (C) 2017, 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by the LiMux project of the city of Munich
21 * Copyright (C) 2018, 2021 Nelson Benítez León <[email protected]>
22 * Copyright (C) 2019 Jan Grulich <[email protected]>
23 * Copyright (C) 2019 Alexander Volkov <[email protected]>
24 * Copyright (C) 2020 Philipp Knechtges <[email protected]>
25 * Copyright (C) 2020 Katarina Behrens <[email protected]>
26 * Copyright (C) 2020 Thorsten Behrens <[email protected]>
27 * Copyright (C) 2020, 2024 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>. Work sponsored by Technische Universität Dresden
28 * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]>.
29 * Copyright (C) 2021 Mahmoud Khalil <[email protected]>
30 * Copyright (C) 2021 Georgiy Sgibnev <[email protected]>. Work sponsored by lab50.net.
31 * Copyright (C) 2022 Martin <[email protected]>
32 * Copyright (C) 2023 Kevin Ottens <[email protected]>. Work sponsored by De Bortoli Wines
33 * Copyright (C) 2025, g10 Code GmbH, Author: Sune Stolborg Vuorela <[email protected]>
34 *
35 * This program is free software; you can redistribute it and/or modify
36 * it under the terms of the GNU General Public License as published by
37 * the Free Software Foundation; either version 2, or (at your option)
38 * any later version.
39 *
40 * This program is distributed in the hope that it will be useful,
41 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 * GNU General Public License for more details.
44 *
45 * You should have received a copy of the GNU General Public License
46 * along with this program; if not, write to the Free Software
47 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
48 */
49
50 #ifndef __POPPLER_CONVERTER_H__
51 #define __POPPLER_CONVERTER_H__
52
53 #include <QtCore/QByteArray>
54 #include <QtCore/QIODevice>
55 #include <QtCore/QVariant>
56
57 #include "poppler-export.h"
58
59 namespace Poppler {
60
61 /**
62 * The various types of error strings.
63 *
64 * \since 25.07
65 */
66 enum class ErrorStringType
67 {
68 /**The string should be treated like a error cod. It could be a hex code, a position in the poppler sources or something similar*/
69 ErrorCodeString,
70 /**The string should be treated as an advanced error message that can be shown to user */
71 UserString
72 };
73
74 /**
75 * Combination of an error data and type of error string
76 *
77 * \since 25.07
78 */
79 struct ErrorString
80 {
81 QVariant data;
82 ErrorStringType type;
83 };
84
85 class DocumentData;
86
87 class BaseConverterPrivate;
88 class PSConverterPrivate;
89 class PDFConverterPrivate;
90
91 /**
92 \brief Base converter.
93
94 This is the base class for the converters.
95 */
96 class POPPLER_QT6_EXPORT BaseConverter
97 {
98 friend class Document;
99
100 public:
101 /**
102 Destructor.
103 */
104 virtual ~BaseConverter();
105
106 /** Sets the output file name. You must set this or the output device. */
107 void setOutputFileName(const QString &outputFileName);
108
109 /**
110 * Sets the output device. You must set this or the output file name.
111 */
112 void setOutputDevice(QIODevice *device);
113
114 /**
115 Does the conversion.
116
117 \return whether the conversion succeeded
118 */
119 virtual bool convert() = 0;
120
121 enum Error
122 {
123 NoError,
124 FileLockedError,
125 OpenOutputError,
126 NotSupportedInputFileError
127 };
128
129 /**
130 Returns the last error
131 */
132 Error lastError() const;
133
134 protected:
135 /// \cond PRIVATE
136 explicit BaseConverter(BaseConverterPrivate &dd);
137 Q_DECLARE_PRIVATE(BaseConverter)
138 BaseConverterPrivate *d_ptr;
139 /// \endcond
140
141 private:
142 Q_DISABLE_COPY(BaseConverter)
143 };
144
145 /**
146 Converts a PDF to PS
147
148 Sizes have to be in Points (1/72 inch)
149
150 If you are using QPrinter you can get paper size by doing:
151 \code
152 QPrinter dummy(QPrinter::PrinterResolution);
153 dummy.setFullPage(true);
154 dummy.setPageSize(myPageSize);
155 width = dummy.width();
156 height = dummy.height();
157 \endcode
158 */
159 class POPPLER_QT6_EXPORT PSConverter : public BaseConverter
160 {
161 friend class Document;
162
163 public:
164 /**
165 Options for the PS export.
166 */
167 enum PSOption
168 {
169 Printing = 0x00000001, ///< The PS is generated for printing purposes
170 StrictMargins = 0x00000002,
171 ForceRasterization = 0x00000004,
172 PrintToEPS = 0x00000008, ///< Output EPS instead of PS
173 HideAnnotations = 0x00000010, ///< Don't print annotations
174 ForceOverprintPreview = 0x00000020 ///< Force rasterized overprint preview during conversion \since 23.09
175 };
176 Q_DECLARE_FLAGS(PSOptions, PSOption)
177
178 /**
179 Destructor.
180 */
181 ~PSConverter() override;
182
183 /** Sets the list of pages to print. Mandatory. */
184 void setPageList(const QList<int> &pageList);
185
186 /**
187 Sets the title of the PS Document. Optional
188 */
189 void setTitle(const QString &title);
190
191 /**
192 Sets the horizontal DPI. Defaults to 72.0
193 */
194 void setHDPI(double hDPI);
195
196 /**
197 Sets the vertical DPI. Defaults to 72.0
198 */
199 void setVDPI(double vDPI);
200
201 /**
202 Sets the rotate. Defaults to not rotated
203 */
204 void setRotate(int rotate);
205
206 /**
207 Sets the output paper width. Has to be set.
208 */
209 void setPaperWidth(int paperWidth);
210
211 /**
212 Sets the output paper height. Has to be set.
213 */
214 void setPaperHeight(int paperHeight);
215
216 /**
217 Sets the output right margin. Defaults to 0
218 */
219 void setRightMargin(int marginRight);
220
221 /**
222 Sets the output bottom margin. Defaults to 0
223 */
224 void setBottomMargin(int marginBottom);
225
226 /**
227 Sets the output left margin. Defaults to 0
228 */
229 void setLeftMargin(int marginLeft);
230
231 /**
232 Sets the output top margin. Defaults to 0
233 */
234 void setTopMargin(int marginTop);
235
236 /**
237 Defines if margins have to be strictly followed (even if that
238 means changing aspect ratio), or if the margins can be adapted
239 to keep aspect ratio.
240
241 Defaults to false.
242 */
243 void setStrictMargins(bool strictMargins);
244
245 /**
246 Defines if the page will be rasterized to an image with overprint
247 preview enabled before printing.
248
249 Defaults to false
250
251 \since 23.09
252 */
253 void setForceOverprintPreview(bool forceOverprintPreview);
254
255 /** Defines if the page will be rasterized to an image before printing. Defaults to false */
256 void setForceRasterize(bool forceRasterize);
257
258 /**
259 Sets the options for the PS export.
260 */
261 void setPSOptions(PSOptions options);
262
263 /**
264 The currently set options for the PS export.
265
266 The default flags are: Printing.
267 */
268 PSOptions psOptions() const;
269
270 /**
271 Sets a function that will be called each time a page is converted.
272
273 The payload belongs to the caller.
274 */
275 void setPageConvertedCallback(void (*callback)(int page, void *payload), void *payload);
276
277 bool convert() override;
278
279 private:
280 Q_DECLARE_PRIVATE(PSConverter)
281 Q_DISABLE_COPY(PSConverter)
282
283 explicit PSConverter(DocumentData *document);
284 };
285
286 /**
287 Converts a PDF to PDF (thus saves a copy of the document).
288 */
289 class POPPLER_QT6_EXPORT PDFConverter : public BaseConverter
290 {
291 friend class Document;
292
293 public:
294 /**
295 Options for the PDF export.
296 */
297 enum PDFOption
298 {
299 WithChanges = 0x00000001 ///< The changes done to the document are saved as well
300 };
301 Q_DECLARE_FLAGS(PDFOptions, PDFOption)
302
303 /**
304 Destructor.
305 */
306 ~PDFConverter() override;
307
308 /**
309 Sets the options for the PDF export.
310 */
311 void setPDFOptions(PDFOptions options);
312 /**
313 The currently set options for the PDF export.
314 */
315 PDFOptions pdfOptions() const;
316
317 /**
318 * Holds data for a new signature
319 * - Common Name of cert to sign (aka nickname)
320 * - password for the cert
321 * - page where to add the signature
322 * - rect for the signature annotation
323 * - text that will be shown inside the rect
324 * - font size and color
325 * - border width and color
326 * - background color
327 * \since 21.01
328 */
329 class POPPLER_QT6_EXPORT NewSignatureData
330 {
331 public:
332 NewSignatureData();
333 ~NewSignatureData();
334 NewSignatureData(const NewSignatureData &) = delete;
335 NewSignatureData &operator=(const NewSignatureData &) = delete;
336
337 QString certNickname() const;
338 void setCertNickname(const QString &certNickname);
339
340 QString password() const;
341 void setPassword(const QString &password);
342
343 int page() const;
344 void setPage(int page);
345
346 QRectF boundingRectangle() const;
347 void setBoundingRectangle(const QRectF &rect);
348
349 QString signatureText() const;
350 void setSignatureText(const QString &text);
351
352 /**
353 * If this text is not empty, the signature representation
354 * will split in two, with this text on the left and signatureText
355 * on the right
356 *
357 * \since 21.06
358 */
359 QString signatureLeftText() const;
360 void setSignatureLeftText(const QString &text);
361
362 /**
363 * Signature's property Reason.
364 *
365 * Default: an empty string.
366 *
367 * \since 21.10
368 */
369 QString reason() const;
370 void setReason(const QString &reason);
371
372 /**
373 * Signature's property Location.
374 *
375 * Default: an empty string.
376 *
377 * \since 21.10
378 */
379 QString location() const;
380 void setLocation(const QString &location);
381
382 /**
383 * Default: 10
384 */
385 double fontSize() const;
386 void setFontSize(double fontSize);
387
388 /**
389 * Default: 20
390 *
391 * \since 21.06
392 */
393 double leftFontSize() const;
394 void setLeftFontSize(double fontSize);
395
396 /**
397 * Default: red
398 */
399 QColor fontColor() const;
400 void setFontColor(const QColor &color);
401
402 /**
403 * Default: red
404 */
405 QColor borderColor() const;
406 void setBorderColor(const QColor &color);
407
408 /**
409 * border width in points
410 *
411 * Default: 1.5
412 *
413 * \since 21.05
414 */
415 double borderWidth() const;
416 void setBorderWidth(double width);
417
418 /**
419 * Default: QColor(240, 240, 240)
420 */
421 QColor backgroundColor() const;
422 void setBackgroundColor(const QColor &color);
423
424 /**
425 * Default: QUuid::createUuid().toString()
426 */
427 QString fieldPartialName() const;
428 void setFieldPartialName(const QString &name);
429
430 /**
431 * Document owner password (needed if the document that is being signed is password protected)
432 *
433 * Default: no password
434 *
435 * \since 22.02
436 */
437 QByteArray documentOwnerPassword() const;
438 void setDocumentOwnerPassword(const QByteArray &password);
439
440 /**
441 * Document user password (needed if the document that is being signed is password protected)
442 *
443 * Default: no password
444 *
445 * \since 22.02
446 */
447 QByteArray documentUserPassword() const;
448 void setDocumentUserPassword(const QByteArray &password);
449
450 /**
451 * Filesystem path to an image file to be used as background
452 * image for the signature annotation widget.
453 *
454 * Default: empty
455 *
456 * \since 22.02
457 */
458 QString imagePath() const;
459 void setImagePath(const QString &path);
460
461 private:
462 struct NewSignatureDataPrivate;
463 NewSignatureDataPrivate *const d;
464 };
465
466 /**
467 Sign PDF at given Annotation / signature form
468
469 \param data new signature data
470
471 \return whether the signing succeeded
472
473 \since 21.01
474 */
475 bool sign(const NewSignatureData &data);
476 /**
477 * \since 25.07
478 *
479 * BIC/SIC: Merge with SigningResult in poppler-converter and in poppler-annotation and poppler-form
480 */
481 enum SigningResult
482 {
483 SigningSuccess, ///< No error
484 FieldAlreadySigned, ///< Trying to sign a field that is already signed
485 GenericSigningError, ///< Unclassified error
486 InternalError, ///< Unexpected error, likely a bug in poppler
487 KeyMissing, ///< Key not found (Either the input key is not from the list or the available keys has changed underneath)
488 WriteFailed, ///< Write failed (permissions, faulty disk, ...)
489 UserCancelled, ///< User cancelled the process
490 BadPassphrase, ///< User entered bad passphrase
491 };
492
493 /**
494 * The last signing result, mostly relevant if \ref sign returns false
495 * \since 25.07
496 */
497 SigningResult lastSigningResult() const;
498
499 /**
500 * A string with a string that might offer more details of the signing result failure
501 * \note the string here is likely not super useful for end users, but might give more details to a trained supporter / bug triager
502 * \since 25.07
503 */
504 ErrorString lastSigningErrorDetails() const;
505
506 bool convert() override;
507
508 private:
509 Q_DECLARE_PRIVATE(PDFConverter)
510 Q_DISABLE_COPY(PDFConverter)
511
512 explicit PDFConverter(DocumentData *document);
513 };
514
515 }
516
517 Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::PDFConverter::PDFOptions)
518 Q_DECLARE_OPERATORS_FOR_FLAGS(Poppler::PSConverter::PSOptions)
519
520 #endif