xhtml2pdf 0.2.25__tar.gz → 0.2.27__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. {xhtml2pdf-0.2.25/xhtml2pdf.egg-info → xhtml2pdf-0.2.27}/PKG-INFO +2 -206
  2. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/pyproject.toml +3 -3
  3. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_document.py +33 -0
  4. xhtml2pdf-0.2.27/tests/test_generated_content.py +211 -0
  5. xhtml2pdf-0.2.27/tests/test_insert_pdf.py +160 -0
  6. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_page_numbering.py +33 -0
  7. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_reportlab_api.py +11 -0
  8. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_special_css.py +66 -0
  9. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_tables.py +71 -0
  10. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_tags.py +172 -2
  11. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/__init__.py +1 -1
  12. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/builders/block.py +8 -3
  13. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/builders/flex.py +9 -4
  14. xhtml2pdf-0.2.27/xhtml2pdf/builders/inserts.py +156 -0
  15. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/builders/watermarks.py +13 -1
  16. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/charts.py +118 -25
  17. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/context.py +33 -3
  18. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/default.py +1 -0
  19. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/document.py +5 -0
  20. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/parser.py +90 -5
  21. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/properties.py +29 -0
  22. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/reportlab_paragraph.py +108 -0
  23. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/tables.py +16 -6
  24. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/tags.py +45 -38
  25. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/util.py +16 -0
  26. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/w3c/css.py +73 -5
  27. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/w3c/cssDOMElementInterface.py +4 -0
  28. xhtml2pdf-0.2.27/xhtml2pdf/w3c/generated_content.py +284 -0
  29. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/xhtml2pdf_reportlab.py +120 -14
  30. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27/xhtml2pdf.egg-info}/PKG-INFO +2 -206
  31. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf.egg-info/SOURCES.txt +5 -2
  32. xhtml2pdf-0.2.25/AUTHORS.rst +0 -60
  33. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/LICENSE.txt +0 -0
  34. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/MANIFEST.in +0 -0
  35. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/README.rst +0 -0
  36. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/setup.cfg +0 -0
  37. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_asian_font_support.py +0 -0
  38. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_bidi.py +0 -0
  39. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_block_box.py +0 -0
  40. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_block_margins.py +0 -0
  41. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_block_width.py +0 -0
  42. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_cli.py +0 -0
  43. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_css_media_rule.py +0 -0
  44. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_css_parser.py +0 -0
  45. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_css_variables.py +0 -0
  46. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_files.py +0 -0
  47. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_flex.py +0 -0
  48. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_flex_flowable.py +0 -0
  49. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_flex_layout.py +0 -0
  50. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_font_isolation.py +0 -0
  51. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_fonts.py +0 -0
  52. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_frame_align.py +0 -0
  53. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_frame_pages.py +0 -0
  54. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_http.py +0 -0
  55. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_inline_block.py +0 -0
  56. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_inline_box.py +0 -0
  57. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_optional_dependencies.py +0 -0
  58. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_page_padding.py +0 -0
  59. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_paragraph.py +0 -0
  60. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_paragraph_height.py +0 -0
  61. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_parser.py +0 -0
  62. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_pdf.py +0 -0
  63. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_position.py +0 -0
  64. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_reportlab.py +0 -0
  65. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_reportlab_paragraph.py +0 -0
  66. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_resource_policy.py +0 -0
  67. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_right_to_left_font_support.py +0 -0
  68. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_security_limits.py +0 -0
  69. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_selectors.py +0 -0
  70. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_signatures.py +0 -0
  71. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_table_border_radius.py +0 -0
  72. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_table_css.py +0 -0
  73. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_update_face_name.py +0 -0
  74. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_utils.py +0 -0
  75. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_watermarks.py +0 -0
  76. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_word_breaking.py +0 -0
  77. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/tests/test_wsgi.py +0 -0
  78. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/__main__.py +0 -0
  79. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/_bidi_data.py +0 -0
  80. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/bidi.py +0 -0
  81. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/builders/__init__.py +0 -0
  82. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/builders/flex_layout.py +0 -0
  83. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/builders/position.py +0 -0
  84. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/builders/signs.py +0 -0
  85. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/config/__init__.py +0 -0
  86. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/config/httpconfig.py +0 -0
  87. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/config/resources.py +0 -0
  88. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/files.py +0 -0
  89. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/paragraph.py +0 -0
  90. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/pdf.py +0 -0
  91. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/pisa.py +0 -0
  92. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/w3c/__init__.py +0 -0
  93. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/w3c/cssParser.py +0 -0
  94. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/w3c/cssSpecial.py +0 -0
  95. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/w3c/css_variables.py +0 -0
  96. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf/wsgi.py +0 -0
  97. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf.egg-info/dependency_links.txt +0 -0
  98. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf.egg-info/entry_points.txt +0 -0
  99. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf.egg-info/requires.txt +0 -0
  100. {xhtml2pdf-0.2.25 → xhtml2pdf-0.2.27}/xhtml2pdf.egg-info/top_level.txt +0 -0
@@ -1,218 +1,15 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xhtml2pdf
3
- Version: 0.2.25
3
+ Version: 0.2.27
4
4
  Summary: PDF generator using HTML and CSS
5
5
  Author-email: Dirk Holtwick <dirk.holtwick@gmail.com>
6
6
  Maintainer-email: Luis Zarate <luisza14@gmail.com>, Timo Brembeck <opensource@timo.brembeck.email>
7
- License:
8
- Apache License
9
- Version 2.0, January 2004
10
- http://www.apache.org/licenses/
11
-
12
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
13
-
14
- 1. Definitions.
15
-
16
- "License" shall mean the terms and conditions for use, reproduction,
17
- and distribution as defined by Sections 1 through 9 of this document.
18
-
19
- "Licensor" shall mean the copyright owner or entity authorized by
20
- the copyright owner that is granting the License.
21
-
22
- "Legal Entity" shall mean the union of the acting entity and all
23
- other entities that control, are controlled by, or are under common
24
- control with that entity. For the purposes of this definition,
25
- "control" means (i) the power, direct or indirect, to cause the
26
- direction or management of such entity, whether by contract or
27
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
28
- outstanding shares, or (iii) beneficial ownership of such entity.
29
-
30
- "You" (or "Your") shall mean an individual or Legal Entity
31
- exercising permissions granted by this License.
32
-
33
- "Source" form shall mean the preferred form for making modifications,
34
- including but not limited to software source code, documentation
35
- source, and configuration files.
36
-
37
- "Object" form shall mean any form resulting from mechanical
38
- transformation or translation of a Source form, including but
39
- not limited to compiled object code, generated documentation,
40
- and conversions to other media types.
41
-
42
- "Work" shall mean the work of authorship, whether in Source or
43
- Object form, made available under the License, as indicated by a
44
- copyright notice that is included in or attached to the work
45
- (an example is provided in the Appendix below).
46
-
47
- "Derivative Works" shall mean any work, whether in Source or Object
48
- form, that is based on (or derived from) the Work and for which the
49
- editorial revisions, annotations, elaborations, or other modifications
50
- represent, as a whole, an original work of authorship. For the purposes
51
- of this License, Derivative Works shall not include works that remain
52
- separable from, or merely link (or bind by name) to the interfaces of,
53
- the Work and Derivative Works thereof.
54
-
55
- "Contribution" shall mean any work of authorship, including
56
- the original version of the Work and any modifications or additions
57
- to that Work or Derivative Works thereof, that is intentionally
58
- submitted to Licensor for inclusion in the Work by the copyright owner
59
- or by an individual or Legal Entity authorized to submit on behalf of
60
- the copyright owner. For the purposes of this definition, "submitted"
61
- means any form of electronic, verbal, or written communication sent
62
- to the Licensor or its representatives, including but not limited to
63
- communication on electronic mailing lists, source code control systems,
64
- and issue tracking systems that are managed by, or on behalf of, the
65
- Licensor for the purpose of discussing and improving the Work, but
66
- excluding communication that is conspicuously marked or otherwise
67
- designated in writing by the copyright owner as "Not a Contribution."
68
-
69
- "Contributor" shall mean Licensor and any individual or Legal Entity
70
- on behalf of whom a Contribution has been received by Licensor and
71
- subsequently incorporated within the Work.
72
-
73
- 2. Grant of Copyright License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- copyright license to reproduce, prepare Derivative Works of,
77
- publicly display, publicly perform, sublicense, and distribute the
78
- Work and such Derivative Works in Source or Object form.
79
-
80
- 3. Grant of Patent License. Subject to the terms and conditions of
81
- this License, each Contributor hereby grants to You a perpetual,
82
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
83
- (except as stated in this section) patent license to make, have made,
84
- use, offer to sell, sell, import, and otherwise transfer the Work,
85
- where such license applies only to those patent claims licensable
86
- by such Contributor that are necessarily infringed by their
87
- Contribution(s) alone or by combination of their Contribution(s)
88
- with the Work to which such Contribution(s) was submitted. If You
89
- institute patent litigation against any entity (including a
90
- cross-claim or counterclaim in a lawsuit) alleging that the Work
91
- or a Contribution incorporated within the Work constitutes direct
92
- or contributory patent infringement, then any patent licenses
93
- granted to You under this License for that Work shall terminate
94
- as of the date such litigation is filed.
95
-
96
- 4. Redistribution. You may reproduce and distribute copies of the
97
- Work or Derivative Works thereof in any medium, with or without
98
- modifications, and in Source or Object form, provided that You
99
- meet the following conditions:
100
-
101
- (a) You must give any other recipients of the Work or
102
- Derivative Works a copy of this License; and
103
-
104
- (b) You must cause any modified files to carry prominent notices
105
- stating that You changed the files; and
106
-
107
- (c) You must retain, in the Source form of any Derivative Works
108
- that You distribute, all copyright, patent, trademark, and
109
- attribution notices from the Source form of the Work,
110
- excluding those notices that do not pertain to any part of
111
- the Derivative Works; and
112
-
113
- (d) If the Work includes a "NOTICE" text file as part of its
114
- distribution, then any Derivative Works that You distribute must
115
- include a readable copy of the attribution notices contained
116
- within such NOTICE file, excluding those notices that do not
117
- pertain to any part of the Derivative Works, in at least one
118
- of the following places: within a NOTICE text file distributed
119
- as part of the Derivative Works; within the Source form or
120
- documentation, if provided along with the Derivative Works; or,
121
- within a display generated by the Derivative Works, if and
122
- wherever such third-party notices normally appear. The contents
123
- of the NOTICE file are for informational purposes only and
124
- do not modify the License. You may add Your own attribution
125
- notices within Derivative Works that You distribute, alongside
126
- or as an addendum to the NOTICE text from the Work, provided
127
- that such additional attribution notices cannot be construed
128
- as modifying the License.
129
-
130
- You may add Your own copyright statement to Your modifications and
131
- may provide additional or different license terms and conditions
132
- for use, reproduction, or distribution of Your modifications, or
133
- for any such Derivative Works as a whole, provided Your use,
134
- reproduction, and distribution of the Work otherwise complies with
135
- the conditions stated in this License.
136
-
137
- 5. Submission of Contributions. Unless You explicitly state otherwise,
138
- any Contribution intentionally submitted for inclusion in the Work
139
- by You to the Licensor shall be under the terms and conditions of
140
- this License, without any additional terms or conditions.
141
- Notwithstanding the above, nothing herein shall supersede or modify
142
- the terms of any separate license agreement you may have executed
143
- with Licensor regarding such Contributions.
144
-
145
- 6. Trademarks. This License does not grant permission to use the trade
146
- names, trademarks, service marks, or product names of the Licensor,
147
- except as required for reasonable and customary use in describing the
148
- origin of the Work and reproducing the content of the NOTICE file.
149
-
150
- 7. Disclaimer of Warranty. Unless required by applicable law or
151
- agreed to in writing, Licensor provides the Work (and each
152
- Contributor provides its Contributions) on an "AS IS" BASIS,
153
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
154
- implied, including, without limitation, any warranties or conditions
155
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
156
- PARTICULAR PURPOSE. You are solely responsible for determining the
157
- appropriateness of using or redistributing the Work and assume any
158
- risks associated with Your exercise of permissions under this License.
159
-
160
- 8. Limitation of Liability. In no event and under no legal theory,
161
- whether in tort (including negligence), contract, or otherwise,
162
- unless required by applicable law (such as deliberate and grossly
163
- negligent acts) or agreed to in writing, shall any Contributor be
164
- liable to You for damages, including any direct, indirect, special,
165
- incidental, or consequential damages of any character arising as a
166
- result of this License or out of the use or inability to use the
167
- Work (including but not limited to damages for loss of goodwill,
168
- work stoppage, computer failure or malfunction, or any and all
169
- other commercial damages or losses), even if such Contributor
170
- has been advised of the possibility of such damages.
171
-
172
- 9. Accepting Warranty or Additional Liability. While redistributing
173
- the Work or Derivative Works thereof, You may choose to offer,
174
- and charge a fee for, acceptance of support, warranty, indemnity,
175
- or other liability obligations and/or rights consistent with this
176
- License. However, in accepting such obligations, You may act only
177
- on Your own behalf and on Your sole responsibility, not on behalf
178
- of any other Contributor, and only if You agree to indemnify,
179
- defend, and hold each Contributor harmless for any liability
180
- incurred by, or claims asserted against, such Contributor by reason
181
- of your accepting any such warranty or additional liability.
182
-
183
- END OF TERMS AND CONDITIONS
184
-
185
- APPENDIX: How to apply the Apache License to your work.
186
-
187
- To apply the Apache License to your work, attach the following
188
- boilerplate notice, with the fields enclosed by brackets "[]"
189
- replaced with your own identifying information. (Don't include
190
- the brackets!) The text should be enclosed in the appropriate
191
- comment syntax for the file format. We also recommend that a
192
- file or class name and description of purpose be included on the
193
- same "printed page" as the copyright notice for easier
194
- identification within third-party archives.
195
-
196
- Copyright [yyyy] [name of copyright owner]
197
-
198
- Licensed under the Apache License, Version 2.0 (the "License");
199
- you may not use this file except in compliance with the License.
200
- You may obtain a copy of the License at
201
-
202
- http://www.apache.org/licenses/LICENSE-2.0
203
-
204
- Unless required by applicable law or agreed to in writing, software
205
- distributed under the License is distributed on an "AS IS" BASIS,
206
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
207
- See the License for the specific language governing permissions and
208
- limitations under the License.
209
-
7
+ License-Expression: Apache-2.0
210
8
  Project-URL: Repository, https://github.com/xhtml2pdf/xhtml2pdf
211
9
  Project-URL: Bug tracker, https://github.com/xhtml2pdf/xhtml2pdf/issues
212
10
  Project-URL: Documentation, https://xhtml2pdf.readthedocs.io/
213
11
  Project-URL: Changelog, https://xhtml2pdf.readthedocs.io/en/latest/release-notes.html
214
12
  Keywords: PDF,HTML,HTML,XML,CSS
215
- Classifier: License :: OSI Approved :: Apache Software License
216
13
  Classifier: Development Status :: 4 - Beta
217
14
  Classifier: Environment :: Console
218
15
  Classifier: Environment :: Other Environment
@@ -242,7 +39,6 @@ Classifier: Topic :: Utilities
242
39
  Requires-Python: >=3.10
243
40
  Description-Content-Type: text/x-rst
244
41
  License-File: LICENSE.txt
245
- License-File: AUTHORS.rst
246
42
  Requires-Dist: arabic-reshaper>=3.0.0
247
43
  Requires-Dist: html5lib>=1.1
248
44
  Requires-Dist: Pillow>=8.1.1
@@ -1,5 +1,5 @@
1
1
  [build-system]
2
- requires = ["setuptools"]
2
+ requires = ["setuptools>=77"]
3
3
  build-backend = "setuptools.build_meta"
4
4
 
5
5
 
@@ -15,9 +15,9 @@ maintainers = [
15
15
  description = "PDF generator using HTML and CSS"
16
16
  keywords = ["PDF", "HTML", "HTML", "XML", "CSS"]
17
17
  readme = "README.rst"
18
- license = {file = "LICENSE.txt"}
18
+ license = "Apache-2.0"
19
+ license-files = ["LICENSE.txt"]
19
20
  classifiers = [
20
- "License :: OSI Approved :: Apache Software License",
21
21
  "Development Status :: 4 - Beta",
22
22
  "Environment :: Console",
23
23
  "Environment :: Other Environment",
@@ -468,6 +468,39 @@ class EncryptAndSignTest(TestCase):
468
468
 
469
469
  self.assertIn("cannot be merged", str(raised.exception))
470
470
 
471
+ def test_a_background_drops_an_owner_password_and_says_so(self) -> None:
472
+ """
473
+ With an owner password only the document can be read back, and the
474
+ background is merged in; but it is written again unencrypted.
475
+ """
476
+ from reportlab.lib.pdfencrypt import StandardEncryption
477
+
478
+ html = (
479
+ "<html><head><style>@page { background-image:"
480
+ ' url("tests/samples/img/tree.jpg"); }</style></head>'
481
+ "<body><p>x</p></body></html>"
482
+ )
483
+ dest = io.BytesIO()
484
+ encrypt = StandardEncryption("", ownerPassword="owner", canPrint=0)
485
+
486
+ with self.assertLogs("xhtml2pdf", level="WARNING") as logs:
487
+ pisaDocument(io.StringIO(html), dest, encrypt=encrypt, path=".")
488
+
489
+ self.assertFalse(PdfReader(io.BytesIO(dest.getvalue())).is_encrypted)
490
+ self.assertTrue(
491
+ any("WITHOUT encryption" in line for line in logs.output), logs.output
492
+ )
493
+
494
+ def test_no_warning_without_a_background(self) -> None:
495
+ from reportlab.lib.pdfencrypt import StandardEncryption
496
+
497
+ dest = io.BytesIO()
498
+ encrypt = StandardEncryption("", ownerPassword="owner")
499
+ with self.assertNoLogs("xhtml2pdf", level="WARNING"):
500
+ pisaDocument(io.StringIO(self.HTML), dest, encrypt=encrypt)
501
+
502
+ self.assertTrue(PdfReader(io.BytesIO(dest.getvalue())).is_encrypted)
503
+
471
504
 
472
505
  class ArgumentsThatDoSomethingTest(TestCase):
473
506
  """
@@ -0,0 +1,211 @@
1
+ """CSS counters and ::before / ::after content (#112)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import io
6
+ from unittest import TestCase
7
+
8
+ from pypdf import PdfReader
9
+
10
+ from xhtml2pdf import pisa
11
+ from xhtml2pdf.w3c.css import CSSString, CSSTerminalFunction
12
+ from xhtml2pdf.w3c.generated_content import (
13
+ AttrItem,
14
+ CounterItem,
15
+ Counters,
16
+ format_counter,
17
+ parse_content,
18
+ parse_counter_list,
19
+ )
20
+
21
+ HEADINGS = """
22
+ body { counter-reset: h2 }
23
+ h2 { counter-increment: h2; counter-reset: h3 }
24
+ h3 { counter-increment: h3 }
25
+ h2::before { content: counter(h2) ". " }
26
+ h3::before { content: counter(h2) "." counter(h3) " " }
27
+ """
28
+
29
+
30
+ def render(body: str, css: str = HEADINGS) -> PdfReader:
31
+ html = f"<html><head><style>{css}</style></head><body>{body}</body></html>"
32
+ output = io.BytesIO()
33
+ pisa.CreatePDF(html, dest=output, raise_exception=True)
34
+ return PdfReader(output)
35
+
36
+
37
+ def lines(body: str, css: str = HEADINGS) -> list[str]:
38
+ text = "".join(page.extract_text() for page in render(body, css).pages)
39
+ return [line.strip() for line in text.split("\n") if line.strip()]
40
+
41
+
42
+ def outline_titles(items) -> list[str]:
43
+ titles: list[str] = []
44
+ for item in items:
45
+ if isinstance(item, list):
46
+ titles += outline_titles(item)
47
+ else:
48
+ titles.append(item["/Title"])
49
+ return titles
50
+
51
+
52
+ class NumberedHeadingsTest(TestCase):
53
+ BODY = "<h2>Intro</h2><h3>Scope</h3><h3>Terms</h3><h2>Design</h2><h3>Parts</h3>"
54
+
55
+ def test_the_headings_are_numbered(self) -> None:
56
+ self.assertEqual(
57
+ ["1. Intro", "1.1 Scope", "1.2 Terms", "2. Design", "2.1 Parts"],
58
+ lines(self.BODY),
59
+ )
60
+
61
+ def test_the_table_of_contents_shows_the_numbers(self) -> None:
62
+ text = lines("<pdf:toc/>" + self.BODY)
63
+
64
+ # Once in the table of contents and once as the heading itself.
65
+ for heading in ("1. Intro", "1.1 Scope", "2.1 Parts"):
66
+ self.assertEqual(2, text.count(heading), (heading, text))
67
+
68
+ def test_the_outline_shows_the_numbers(self) -> None:
69
+ titles = outline_titles(render(self.BODY).outline)
70
+
71
+ self.assertIn("1.2 Terms", titles)
72
+ self.assertIn("2. Design", titles)
73
+
74
+ def test_a_hidden_heading_is_not_counted(self) -> None:
75
+ body = '<h2>A</h2><h2 style="display: none">Hidden</h2><h2>B</h2>'
76
+
77
+ self.assertEqual(["1. A", "2. B"], lines(body))
78
+
79
+ def test_without_a_before_rule_nothing_changes(self) -> None:
80
+ self.assertEqual(["Intro"], lines("<h2>Intro</h2>", css="h2 { color: red }"))
81
+
82
+
83
+ class ContentTest(TestCase):
84
+ def test_after_and_attr(self) -> None:
85
+ css = 'p::after { content: " [" attr(data-ref) "]" }'
86
+
87
+ self.assertEqual(["Text [r1]"], lines('<p data-ref="r1">Text</p>', css))
88
+
89
+ def test_a_counter_style(self) -> None:
90
+ css = (
91
+ "ol { counter-reset: item; list-style: none }"
92
+ " li { counter-increment: item }"
93
+ ' li::before { content: counter(item, upper-roman) ") " }'
94
+ )
95
+
96
+ self.assertEqual(
97
+ ["I) a", "II) b", "III) c"],
98
+ lines("<ol><li>a</li><li>b</li><li>c</li></ol>", css),
99
+ )
100
+
101
+ def test_counters_joins_the_nested_instances(self) -> None:
102
+ css = (
103
+ "ol { counter-reset: item; list-style: none } li { counter-increment: item }"
104
+ ' li::before { content: counters(item, ".") " " }'
105
+ )
106
+ body = "<ol><li>a<ol><li>b</li><li>c</li></ol></li><li>d</li></ol>"
107
+
108
+ self.assertEqual(["1 a", "1.1 b", "1.2 c", "2 d"], lines(body, css))
109
+
110
+ def test_the_css2_single_colon_form(self) -> None:
111
+ css = 'h2:before { content: "> " }'
112
+
113
+ self.assertEqual(["> Intro"], lines("<h2>Intro</h2>", css))
114
+
115
+ def test_a_before_rule_does_not_style_the_element_itself(self) -> None:
116
+ css = 'h2::before { content: "x "; color: red }'
117
+ reader = render("<h2>Intro</h2>", css)
118
+ content = reader.pages[0].get_contents().get_data().decode("latin-1")
119
+
120
+ # The number is red, the heading after it is not.
121
+ self.assertIn("1 0 0 rg", content)
122
+ self.assertIn("0 0 0 rg", content)
123
+
124
+ def test_the_more_specific_rule_wins(self) -> None:
125
+ css = 'h2::before { content: "a " } h2.x::before { content: "b " }'
126
+
127
+ self.assertEqual(["b Intro"], lines('<h2 class="x">Intro</h2>', css))
128
+
129
+ def test_none_and_an_empty_string_generate_nothing(self) -> None:
130
+ for content in ("none", '""'):
131
+ with self.subTest(content=content):
132
+ css = f"h2::before {{ content: {content} }}"
133
+ self.assertEqual(["Intro"], lines("<h2>Intro</h2>", css))
134
+
135
+
136
+ class FormatCounterTest(TestCase):
137
+ def test_styles(self) -> None:
138
+ cases = {
139
+ "decimal": "4",
140
+ "decimal-leading-zero": "04",
141
+ "lower-roman": "iv",
142
+ "upper-roman": "IV",
143
+ "lower-alpha": "d",
144
+ "upper-latin": "D",
145
+ "lower-greek": "δ",
146
+ "none": "",
147
+ "unknown": "4",
148
+ }
149
+ for style, expected in cases.items():
150
+ with self.subTest(style=style):
151
+ self.assertEqual(expected, format_counter(4, style))
152
+
153
+ def test_letters_go_on_past_z(self) -> None:
154
+ self.assertEqual(
155
+ ["z", "aa", "ab"], [format_counter(n, "lower-alpha") for n in (26, 27, 28)]
156
+ )
157
+
158
+ def test_out_of_range_falls_back_to_decimal(self) -> None:
159
+ self.assertEqual("0", format_counter(0, "upper-roman"))
160
+ self.assertEqual("-1", format_counter(-1, "lower-alpha"))
161
+
162
+
163
+ class ParseTest(TestCase):
164
+ def test_content_items(self) -> None:
165
+ value = [
166
+ CSSTerminalFunction("counter", ["h2", "upper-roman"]),
167
+ CSSString(". "),
168
+ CSSTerminalFunction("counters", ["item", CSSString(".")]),
169
+ CSSTerminalFunction("attr", ["title"]),
170
+ ]
171
+
172
+ self.assertEqual(
173
+ [
174
+ CounterItem("h2", "upper-roman"),
175
+ ". ",
176
+ CounterItem("item", "decimal", "."),
177
+ AttrItem("title"),
178
+ ],
179
+ parse_content(value),
180
+ )
181
+
182
+ def test_a_css_escape_in_a_string(self) -> None:
183
+ self.assertEqual(["—"], parse_content(CSSString("\\2014")))
184
+
185
+ def test_none_is_nothing_and_the_string_none_is_text(self) -> None:
186
+ self.assertIsNone(parse_content("none"))
187
+ self.assertEqual(["none"], parse_content(CSSString("none")))
188
+
189
+ def test_counter_lists(self) -> None:
190
+ self.assertEqual(
191
+ [("h2", 0), ("h3", 5)], parse_counter_list(["h2", "h3", "5"], 0)
192
+ )
193
+ self.assertEqual([], parse_counter_list("none", 1))
194
+
195
+
196
+ class CountersTest(TestCase):
197
+ def test_a_sibling_reset_takes_over_and_leaving_the_parent_ends_it(self) -> None:
198
+ from xml.dom.minidom import parseString
199
+
200
+ root = parseString("<r><a/><b/></r>").documentElement
201
+ assert root is not None
202
+ a, b = root.childNodes
203
+ assert a.parentNode is not None and b.parentNode is not None
204
+ counters = Counters()
205
+ counters.reset(root, "n", 1)
206
+ counters.reset(a.parentNode, "n", 5)
207
+ counters.increment(b.parentNode, "n", 1)
208
+
209
+ self.assertEqual([6], counters.values("n"))
210
+ counters.leave(root)
211
+ self.assertEqual([], counters.values("n"))
@@ -0,0 +1,160 @@
1
+ """<pdf:insertpdf>: the pages of another PDF inside the document (#551)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import base64
6
+ import io
7
+ import tempfile
8
+ from pathlib import Path
9
+ from unittest import TestCase
10
+
11
+ from pypdf import PdfReader
12
+ from reportlab.lib.pagesizes import A5, landscape
13
+ from reportlab.pdfgen.canvas import Canvas
14
+
15
+ from xhtml2pdf import pisa
16
+ from xhtml2pdf.builders.inserts import parse_pages
17
+ from xhtml2pdf.config.resources import ResourceAccessPolicy
18
+
19
+
20
+ def source_pdf(path: Path) -> None:
21
+ """Three pages saying "Source page N", the third one A5 landscape."""
22
+ canvas = Canvas(str(path))
23
+ for number in range(1, 4):
24
+ if number == 3:
25
+ canvas.setPageSize(landscape(A5))
26
+ canvas.drawString(72, 300, f"Source page {number}")
27
+ canvas.showPage()
28
+ canvas.save()
29
+
30
+
31
+ class InsertPdfTest(TestCase):
32
+ directory: tempfile.TemporaryDirectory
33
+ base: Path
34
+ policy: ResourceAccessPolicy
35
+
36
+ @classmethod
37
+ def setUpClass(cls) -> None:
38
+ cls.directory = tempfile.TemporaryDirectory()
39
+ cls.base = Path(cls.directory.name)
40
+ source_pdf(cls.base / "source.pdf")
41
+ cls.policy = ResourceAccessPolicy(base_dir=cls.base)
42
+
43
+ @classmethod
44
+ def tearDownClass(cls) -> None:
45
+ cls.directory.cleanup()
46
+
47
+ def render(self, body: str, head: str = "", policy=None) -> PdfReader:
48
+ html = f"<html><head>{head}</head><body>{body}</body></html>"
49
+ output = io.BytesIO()
50
+ pisa.CreatePDF(
51
+ html,
52
+ dest=output,
53
+ path=str(self.base / "doc.html"),
54
+ resource_policy=policy or self.policy,
55
+ raise_exception=True,
56
+ )
57
+ return PdfReader(output)
58
+
59
+ @staticmethod
60
+ def texts(reader: PdfReader) -> list[str]:
61
+ return [page.extract_text().strip() for page in reader.pages]
62
+
63
+ def test_the_pages_go_where_the_tag_is(self) -> None:
64
+ reader = self.render(
65
+ '<p>before</p><pdf:insertpdf src="source.pdf"/><p>after</p>'
66
+ )
67
+
68
+ self.assertEqual(
69
+ ["before", "Source page 1", "Source page 2", "Source page 3", "after"],
70
+ self.texts(reader),
71
+ )
72
+
73
+ def test_pages_picks_and_orders_them(self) -> None:
74
+ reader = self.render('<p>a</p><pdf:insertpdf src="source.pdf" pages="3,1"/>')
75
+
76
+ self.assertEqual(["a", "Source page 3", "Source page 1"], self.texts(reader))
77
+
78
+ def test_no_empty_page_at_either_end(self) -> None:
79
+ reader = self.render('<pdf:insertpdf src="source.pdf" pages="2"/>')
80
+
81
+ self.assertEqual(["Source page 2"], self.texts(reader))
82
+
83
+ def test_inserted_pages_are_numbered_and_counted(self) -> None:
84
+ reader = self.render(
85
+ '<p>first of <pdf:pagecount/></p><pdf:insertpdf src="source.pdf"/>'
86
+ "<p>page <pdf:pagenumber/></p>"
87
+ )
88
+
89
+ self.assertEqual("first of 5", self.texts(reader)[0])
90
+ self.assertEqual("page 5", self.texts(reader)[-1])
91
+
92
+ def test_a_page_keeps_its_own_size(self) -> None:
93
+ reader = self.render('<p>a</p><pdf:insertpdf src="source.pdf" pages="3"/>')
94
+ box = reader.pages[1].mediabox
95
+
96
+ self.assertEqual(
97
+ [round(v) for v in landscape(A5)], [round(box.width), round(box.height)]
98
+ )
99
+
100
+ def test_nothing_of_the_document_is_drawn_on_it(self) -> None:
101
+ head = (
102
+ "<style>@page { background-image: url(source.pdf);"
103
+ " @frame footer { -pdf-frame-content: foot; bottom: 1cm;"
104
+ " height: 1cm; left: 2cm; width: 10cm } }</style>"
105
+ )
106
+ reader = self.render(
107
+ '<div id="foot">footer</div><p>a</p>'
108
+ '<pdf:insertpdf src="source.pdf" pages="2"/>',
109
+ head,
110
+ )
111
+
112
+ self.assertIn("footer", self.texts(reader)[0])
113
+ self.assertEqual("Source page 2", self.texts(reader)[1])
114
+
115
+ def test_a_missing_file_inserts_nothing(self) -> None:
116
+ with self.assertLogs("xhtml2pdf", level="WARNING"):
117
+ reader = self.render('<p>a</p><pdf:insertpdf src="missing.pdf"/>')
118
+
119
+ self.assertEqual(["a"], self.texts(reader))
120
+
121
+ def test_an_inline_pdf_follows_the_pdf_background_policy(self) -> None:
122
+ data = base64.b64encode((self.base / "source.pdf").read_bytes()).decode()
123
+ body = f'<p>a</p><pdf:insertpdf src="data:application/pdf;base64,{data}"/>'
124
+ strict = ResourceAccessPolicy(
125
+ base_dir=self.base, allow_remote_pdf_backgrounds=False
126
+ )
127
+
128
+ self.assertEqual(4, len(self.render(body).pages))
129
+ with self.assertLogs("xhtml2pdf", level="WARNING") as logs:
130
+ self.assertEqual(1, len(self.render(body, policy=strict).pages))
131
+ self.assertTrue(any("PDF to insert" in line for line in logs.output))
132
+
133
+ def test_it_cannot_be_used_with_encryption(self) -> None:
134
+ """An owner password alone would be silently lost on the way."""
135
+ from reportlab.lib.pdfencrypt import StandardEncryption
136
+
137
+ for encrypt in ("user", StandardEncryption("", ownerPassword="owner")):
138
+ with self.subTest(encrypt=encrypt), self.assertRaises(ValueError):
139
+ pisa.CreatePDF(
140
+ '<p>a</p><pdf:insertpdf src="source.pdf"/>',
141
+ dest=io.BytesIO(),
142
+ path=str(self.base / "doc.html"),
143
+ resource_policy=self.policy,
144
+ encrypt=encrypt,
145
+ )
146
+
147
+
148
+ class ParsePagesTest(TestCase):
149
+ def test_every_page_by_default(self) -> None:
150
+ self.assertEqual([0, 1, 2], parse_pages("", 3))
151
+
152
+ def test_pages_and_ranges(self) -> None:
153
+ self.assertEqual([0, 2, 3, 4], parse_pages("1, 3-5", 5))
154
+
155
+ def test_open_ranges(self) -> None:
156
+ self.assertEqual([0, 1, 3, 4], parse_pages("-2,4-", 5))
157
+
158
+ def test_a_page_it_does_not_have_is_left_out(self) -> None:
159
+ with self.assertLogs("xhtml2pdf", level="WARNING"):
160
+ self.assertEqual([1], parse_pages("2, 7, x", 3))