Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Enhance PDF Merging Capabilities for Nested Bookmarks - Addresses Issue #2305 #2603

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions pypdf/generic/__init__.py
Expand Up @@ -416,6 +416,18 @@
fit=fit,
)

class FreeTextAnnotation(AnnotationBuilder):
def __init__(self, rect, contents=None, da=None, annotation_format="current"):
super().__init__("/FreeText", rect, contents, annotation_format)
self.da = da

Check warning on line 422 in pypdf/generic/__init__.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/__init__.py#L421-L422

Added lines #L421 - L422 were not covered by tests

def build(self):
annotation = super().build()

Check warning on line 425 in pypdf/generic/__init__.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/__init__.py#L425

Added line #L425 was not covered by tests

if self.da is not None:
annotation[NameObject("/DA")] = TextStringObject(self.da)

Check warning on line 428 in pypdf/generic/__init__.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/__init__.py#L428

Added line #L428 was not covered by tests

return annotation

Check warning on line 430 in pypdf/generic/__init__.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/__init__.py#L430

Added line #L430 was not covered by tests

__all__ = [
# Base types
Expand Down
41 changes: 41 additions & 0 deletions pypdf/generic/_annotation_formats.py
@@ -0,0 +1,41 @@
from pypdf.generic._base import DictionaryObject, NumberObject, TextStringObject

Check warning on line 1 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L1

Added line #L1 was not covered by tests

def convert_to_stream_format(annotation):

Check warning on line 3 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L3

Added line #L3 was not covered by tests
if "/DA" in annotation:
da_value = annotation["/DA"]

Check warning on line 5 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L5

Added line #L5 was not covered by tests
if isinstance(da_value, TextStringObject):
stream_da = convert_da_to_stream_format(da_value)
annotation[NameObject("/DA")] = TextStringObject(stream_da)

Check warning on line 8 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L7-L8

Added lines #L7 - L8 were not covered by tests

if "/DS" in annotation:
del annotation["/DS"]

Check warning on line 11 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L11

Added line #L11 was not covered by tests

return annotation

Check warning on line 13 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L13

Added line #L13 was not covered by tests

def convert_to_current_format(annotation):

Check warning on line 15 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L15

Added line #L15 was not covered by tests
if "/DA" in annotation:
da_value = annotation["/DA"]

Check warning on line 17 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L17

Added line #L17 was not covered by tests
if isinstance(da_value, TextStringObject):
current_da = convert_stream_format_to_da(da_value)
annotation[NameObject("/DA")] = TextStringObject(current_da)

Check warning on line 20 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L19-L20

Added lines #L19 - L20 were not covered by tests

return annotation

Check warning on line 22 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L22

Added line #L22 was not covered by tests

def convert_da_to_stream_format(da_value):

Check warning on line 24 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L24

Added line #L24 was not covered by tests
# Implement the conversion logic from the current /DA format to Stream-Format
# This function should handle various /DA formats and convert them to Stream-Format
# Example conversion:
# "0.9333333333333333 0.9333333333333333 0.9333333333333333 rg"
# to "/Helv 10.5 Tf 0 Tc 11.76 TL 0 0.470588 0.831373 rg"
# Implement a more robust conversion logic based on the specific requirements
stream_da = ""

Check warning on line 31 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L31

Added line #L31 was not covered by tests
# Conversion logic goes here
return stream_da

Check warning on line 33 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L33

Added line #L33 was not covered by tests

def convert_stream_format_to_da(stream_value):

Check warning on line 35 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L35

Added line #L35 was not covered by tests
# Implement the conversion logic from Stream-Format to the current /DA format
# This function should handle various Stream-Format values and convert them to the current /DA format
# Implement a more robust conversion logic based on the specific requirements
current_da = ""

Check warning on line 39 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L39

Added line #L39 was not covered by tests
# Conversion logic goes here
return current_da

Check warning on line 41 in pypdf/generic/_annotation_formats.py

View check run for this annotation

Codecov / codecov/patch

pypdf/generic/_annotation_formats.py#L41

Added line #L41 was not covered by tests