Skip to content

Commit 18bd03b

Browse files
authored
Merge branch 'main' into fix_check_for_annotation_response_existence
2 parents 49efdb1 + c4ba81e commit 18bd03b

File tree

10 files changed

+394
-67
lines changed

10 files changed

+394
-67
lines changed

docs/document.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,9 +1294,10 @@ For details on **embedded files** refer to Appendix 3.
12941294
pair: links; Document.insert_pdf
12951295
pair: annots; Document.insert_pdf
12961296
pair: widgets; Document.insert_pdf
1297+
pair: join_duplicates; Document.insert_pdf
12971298
pair: show_progress; Document.insert_pdf
12981299

1299-
.. method:: insert_pdf(docsrc, from_page=-1, to_page=-1, start_at=-1, rotate=-1, links=True, annots=True, widgets=True, show_progress=0, final=1)
1300+
.. method:: insert_pdf(docsrc, from_page=-1, to_page=-1, start_at=-1, rotate=-1, links=True, annots=True, widgets=True, join_duplicates=False, show_progress=0, final=1)
13001301

13011302
PDF only: Copy the page range **[from_page, to_page]** (including both) of PDF document *docsrc* into the current one. Inserts will start with page number *start_at*. Value -1 indicates default values. All pages thus copied will be rotated as specified. Links, annotations and widgets can be excluded in the target, see below. All page numbers are 0-based.
13021303

@@ -1312,9 +1313,19 @@ For details on **embedded files** refer to Appendix 3.
13121313
:arg int rotate: All copied pages will be rotated by the provided value (degrees, integer multiple of 90).
13131314

13141315
:arg bool links: Choose whether (internal and external) links should be included in the copy. Default is `True`. *Named* links (:data:`LINK_NAMED`) and internal links to outside the copied page range are **always excluded**.
1316+
13151317
:arg bool annots: choose whether annotations should be included in the copy.
1318+
13161319
:arg bool widgets: choose whether annotations should be included in the copy. If `True` and at least one of the source pages contains form fields, the target PDF will be turned into a Form PDF (if not already being one).
1320+
1321+
:arg bool join_duplicates: *(New in version 1.25.5)* Choose how to handle duplicate root field names in the source pages. This parameter is ignored if `widgets=False`.
1322+
1323+
Default is ``False`` which will add unifying strings to the name of those source root fields which have a duplicate in the target. For instance, if "name" already occurs in the target, the source widget's name will be changed to "name [text]" with a suitably chosen string "text".
1324+
1325+
If ``True``, root fields with duplicate names in source and target will be converted to so-called "Kids" of a "Parent" object (which lists all kid widgets in a PDF array). This will effectively turn those kids into instances of the "same" widget: if e.g. one of the kids is changed, then all its instances will automatically inherit this change -- no matter on which page they happen to be displayed.
1326+
13171327
:arg int show_progress: *(new in v1.17.7)* specify an interval size greater zero to see progress messages on `sys.stdout`. After each interval, a message like `Inserted 30 of 47 pages.` will be printed.
1328+
13181329
:arg int final: *(new in v1.18.0)* controls whether the list of already copied objects should be **dropped** after this method, default *True*. Set it to 0 except for the last one of multiple insertions from the same source PDF. This saves target file size and speeds up execution considerably.
13191330

13201331
.. note::

setup.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@
152152
153153
PYMUPDF_SETUP_PY_LIMITED_API
154154
If not '0', we build for current Python's stable ABI.
155+
156+
However if unset and we are on Python-3.13 or later, we do
157+
not build for the stable ABI because as of 2025-03-04 SWIG
158+
generates incorrect stable ABI code with Python-3.13 - see:
159+
https://github.com/swig/swig/issues/3059
155160
156161
PYMUPDF_SETUP_URL_WHEEL
157162
If set, we use an existing wheel instead of building a new wheel.
@@ -242,10 +247,16 @@ def run(command, check=1):
242247
# Name of file that identifies that we are in a PyMuPDF sdist.
243248
g_pymupdfb_sdist_marker = 'pymupdfb_sdist'
244249

250+
python_version_tuple = tuple(int(x) for x in platform.python_version_tuple()[:2])
251+
245252
PYMUPDF_SETUP_PY_LIMITED_API = os.environ.get('PYMUPDF_SETUP_PY_LIMITED_API')
246253
assert PYMUPDF_SETUP_PY_LIMITED_API in (None, '', '0', '1'), \
247254
f'Should be "", "0", "1" or undefined: {PYMUPDF_SETUP_PY_LIMITED_API=}.'
248-
g_py_limited_api = (PYMUPDF_SETUP_PY_LIMITED_API != '0')
255+
if PYMUPDF_SETUP_PY_LIMITED_API is None and python_version_tuple >= (3, 13):
256+
log(f'Not defaulting to Python limited api because {platform.python_version_tuple()=}.')
257+
g_py_limited_api = False
258+
else:
259+
g_py_limited_api = (PYMUPDF_SETUP_PY_LIMITED_API != '0')
249260

250261
PYMUPDF_SETUP_URL_WHEEL = os.environ.get('PYMUPDF_SETUP_URL_WHEEL')
251262
log(f'{PYMUPDF_SETUP_URL_WHEEL=}')

src/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4562,6 +4562,7 @@ def insert_pdf(
45624562
links=1,
45634563
annots=1,
45644564
widgets=1,
4565+
join_duplicates=0,
45654566
show_progress=0,
45664567
final=1,
45674568
_gmap=None,
@@ -4577,6 +4578,7 @@ def insert_pdf(
45774578
links: (int/bool) whether to also copy links.
45784579
annots: (int/bool) whether to also copy annotations.
45794580
widgets: (int/bool) whether to also copy form fields.
4581+
join_duplicates: (int/bool) join or rename duplicate widget names.
45804582
show_progress: (int) progress message interval, 0 is no messages.
45814583
final: (bool) indicates last insertion from this source PDF.
45824584
_gmap: internal use only
@@ -4663,7 +4665,7 @@ def insert_pdf(
46634665
#log( 'insert_pdf(): calling self._do_links()')
46644666
self._do_links(docsrc, from_page=fp, to_page=tp, start_at=sa)
46654667
if widgets:
4666-
self._do_widgets(docsrc, _gmap, from_page=fp, to_page=tp, start_at=sa)
4668+
self._do_widgets(docsrc, _gmap, from_page=fp, to_page=tp, start_at=sa, join_duplicates=join_duplicates)
46674669
if final == 1:
46684670
self.Graftmaps[isrt] = None
46694671
#log( 'insert_pdf(): returning')

0 commit comments

Comments
 (0)