-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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: Add add_free_text_annotation to PdfWriter #981
Conversation
e06e305
to
9283fc1
Compare
Full credit to the GitHub user snakemicro: #107 (comment) Co-authored-by: snakemicro
9283fc1
to
1ca7a9d
Compare
Codecov Report
@@ Coverage Diff @@
## main #981 +/- ##
==========================================
+ Coverage 91.97% 92.01% +0.03%
==========================================
Files 24 24
Lines 4661 4683 +22
Branches 962 968 +6
==========================================
+ Hits 4287 4309 +22
Misses 229 229
Partials 145 145
Continue to review full report at Codecov.
|
I'm uncertain if this function should be split into two:
Also, I was wondering about the italic/bold/font/font size parameters. Maybe that should also be a single I might also need to read up on "Rich Text Strings" |
Note for myself "DS" is "default string" |
I don't think splitting makes sense as this is one Annotation entry. I thought about moving all of the style parameters to their own class, e.g.: class TextStyle:
"""Specify the style in which a text is shown."""
# This class would be a good example for a dataclass. However, I don't
# want to add additional dependencies and dataclasses were introduced
# with PEP 557 for Python 3.7+
# Maybe a named tuple would be good?
def __init__(
self,
bold: bool = False,
italic: bool = False,
font_size: str = "14pt",
font_color: str = "ff0000",
font: str = "Helvetica",
):
self.bold = bold
self.italic = italic
self.font = font
self.font_color = font_color
self.font_size = font_size
@property
def css2_font(self):
"""See TABLE 8.74 CSS2 style attributes used in rich text strings"""
font_str = "font: "
if self.bold is True:
font_str = font_str + "bold "
if self.italic is True:
font_str = font_str + "italic "
font_str = f"{font_str}{self.font} {self.font_size}"
font_str = f"{font_str};text-align:left;color:#{self.font_color}"
return font_str This would reduce the number of parameters for I'm currently wondering if that makes it simpler for the user or more complicated. Although using the I will check how function signatures of other libraries look like and if there are other annotations that could use such a TextStyle class. Other Libraries
|
I like having an Annotation class. So we could have something like Also, me might re-use the same interface for multiple types of annotations. |
#1120 is better as it's more flexible / easier to extend. I close this one. |
…ionBuilder (#1120) * Add `page.annotations` (getter and setter) * Add `writer.add_annotation(page_number, annotation_dictionary)` * Add AnnotationBuilder to generate the `annotation_dictionary` for the different subtypes of annotations. Similarly, we could have an AnnotationsParser. See #107 Closes #981
Full credit to the GitHub user snakemicro:
#107 (comment)
Co-authored-by: snakemicro