/src/qpdf/include/qpdf/QPDFPageDocumentHelper.hh
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2005-2024 Jay Berkenbilt |
2 | | // |
3 | | // This file is part of qpdf. |
4 | | // |
5 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
6 | | // in compliance with the License. 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 distributed under the License |
11 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
12 | | // or implied. See the License for the specific language governing permissions and limitations under |
13 | | // the License. |
14 | | // |
15 | | // Versions of qpdf prior to version 7 were released under the terms of version 2.0 of the Artistic |
16 | | // License. At your option, you may continue to consider qpdf to be licensed under those terms. |
17 | | // Please see the manual for additional information. |
18 | | |
19 | | #ifndef QPDFPAGEDOCUMENTHELPER_HH |
20 | | #define QPDFPAGEDOCUMENTHELPER_HH |
21 | | |
22 | | #include <qpdf/Constants.h> |
23 | | #include <qpdf/QPDFDocumentHelper.hh> |
24 | | #include <qpdf/QPDFPageObjectHelper.hh> |
25 | | |
26 | | #include <qpdf/DLL.h> |
27 | | |
28 | | #include <vector> |
29 | | |
30 | | #include <qpdf/QPDF.hh> |
31 | | |
32 | | class QPDFAcroFormDocumentHelper; |
33 | | |
34 | | class QPDFPageDocumentHelper: public QPDFDocumentHelper |
35 | | { |
36 | | public: |
37 | | QPDF_DLL |
38 | | QPDFPageDocumentHelper(QPDF&); |
39 | | QPDF_DLL |
40 | 0 | ~QPDFPageDocumentHelper() override = default; |
41 | | |
42 | | // Traverse page tree, and return all /Page objects wrapped in QPDFPageObjectHelper objects. |
43 | | // Unlike with QPDF::getAllPages, the vector of pages returned by this call is not affected by |
44 | | // additions or removals of pages. If you manipulate pages, you will have to call this again to |
45 | | // get a new copy. Please see comments in QPDF.hh for getAllPages() for additional details. |
46 | | QPDF_DLL |
47 | | std::vector<QPDFPageObjectHelper> getAllPages(); |
48 | | |
49 | | // The PDF /Pages tree allows inherited values. Working with the pages of a pdf is much easier |
50 | | // when the inheritance is resolved by explicitly setting the values in each /Page. |
51 | | QPDF_DLL |
52 | | void pushInheritedAttributesToPage(); |
53 | | |
54 | | // This calls QPDFPageObjectHelper::removeUnreferencedResources for every page in the document. |
55 | | // See comments in QPDFPageObjectHelper.hh for details. |
56 | | QPDF_DLL |
57 | | void removeUnreferencedResources(); |
58 | | |
59 | | // Add a new page at the beginning or the end of the current pdf. The newpage parameter may be |
60 | | // either a direct object, an indirect object from this QPDF, or an indirect object from another |
61 | | // QPDF. If it is a direct object, it will be made indirect. If it is an indirect object from |
62 | | // another QPDF, this method will call pushInheritedAttributesToPage on the other file and then |
63 | | // copy the page to this QPDF using the same underlying code as copyForeignObject. At this |
64 | | // stage, if the indirect object is already in the pages tree, a shallow copy is made to avoid |
65 | | // adding the same page more than once. In version 10.3.1 and earlier, adding a page that |
66 | | // already existed would throw an exception and could cause qpdf to crash on subsequent page |
67 | | // insertions in some cases. Note that this means that, in some cases, the page actually added |
68 | | // won't be exactly the same object as the one passed in. If you want to do subsequent |
69 | | // modification on the page, you should retrieve it again. |
70 | | // |
71 | | // Note that you can call copyForeignObject directly to copy a page from a different file, but |
72 | | // the resulting object will not be a page in the new file. You could do this, for example, to |
73 | | // convert a page into a form XObject, though for that, you're better off using |
74 | | // QPDFPageObjectHelper::getFormXObjectForPage. |
75 | | // |
76 | | // This method does not have any specific awareness of annotations or form fields, so if you |
77 | | // just add a page without thinking about it, you might end up with two pages that share form |
78 | | // fields or annotations. While the page may look fine, it will probably not function properly |
79 | | // with regard to interactive features. To work around this, you should call |
80 | | // QPDFAcroFormDocumentHelper::fixCopiedAnnotations. A future version of qpdf will likely |
81 | | // provide a higher-level interface for copying pages around that will handle document-level |
82 | | // constructs in a less error-prone fashion. |
83 | | |
84 | | QPDF_DLL |
85 | | void addPage(QPDFPageObjectHelper newpage, bool first); |
86 | | |
87 | | // Add new page before or after refpage. See comments for addPage for details about what newpage |
88 | | // should be. |
89 | | QPDF_DLL |
90 | | void addPageAt(QPDFPageObjectHelper newpage, bool before, QPDFPageObjectHelper refpage); |
91 | | |
92 | | // Remove page from the pdf. |
93 | | QPDF_DLL |
94 | | void removePage(QPDFPageObjectHelper page); |
95 | | |
96 | | // For every annotation, integrate the annotation's appearance stream into the containing page's |
97 | | // content streams, merge the annotation's resources with the page's resources, and remove the |
98 | | // annotation from the page. Handles widget annotations associated with interactive form fields |
99 | | // as a special case, including removing the /AcroForm key from the document catalog. The values |
100 | | // passed to required_flags and forbidden_flags are passed along to |
101 | | // QPDFAnnotationObjectHelper::getPageContentForAppearance. See comments there in |
102 | | // QPDFAnnotationObjectHelper.hh for meanings of those flags. |
103 | | QPDF_DLL |
104 | | void flattenAnnotations(int required_flags = 0, int forbidden_flags = an_invisible | an_hidden); |
105 | | |
106 | | private: |
107 | | void flattenAnnotationsForPage( |
108 | | QPDFPageObjectHelper& page, |
109 | | QPDFObjectHandle& resources, |
110 | | QPDFAcroFormDocumentHelper& afdh, |
111 | | int required_flags, |
112 | | int forbidden_flags); |
113 | | |
114 | | class Members |
115 | | { |
116 | | friend class QPDFPageDocumentHelper; |
117 | | |
118 | | public: |
119 | | QPDF_DLL |
120 | | ~Members() = default; |
121 | | |
122 | | private: |
123 | | Members() = default; |
124 | | Members(Members const&) = delete; |
125 | | }; |
126 | | |
127 | | std::shared_ptr<Members> m; |
128 | | }; |
129 | | |
130 | | #endif // QPDFPAGEDOCUMENTHELPER_HH |