Which AnnotationBuilder design should we use? #1741
Replies: 2 comments 3 replies
-
How to improve:- Consider creating a separate class for each annotation type: This would help organize the code and make it easier to understand. Each class would be responsible for creating annotations of a specific type and could have its own set of required and optional attributes. Use inheritance to share common attributes: If there are optional attributes that are shared between multiple annotation types, consider using inheritance to avoid duplicating code. we could create a base Annotation class with the shared attributes, and then create subclasses for each annotation type that inherit from the base class. |
Beta Was this translation helpful? Give feedback.
-
Great, Using an abstract base class provides a common interface for different annotation types, which can make the code more modular and maintainable. In my opinion creating an abstract base class for annotations seems to be a good design choice... |
Beta Was this translation helpful? Give feedback.
-
The
AnnotationBuilder
class as multiple methods. Each method creates a different annotation type. Currently, the return value is simply a DictionaryObject.Annotations have a few required attributes and a lot of optional attributes. Some of the optional attributes are shared across the annotations, but most are not.
Possible paths forward
I see three ways to add the optional attributes:
set_XYZ
methods to the AnnotationDictionary. Those create a copy of the whole object, similar to theTransformation
class.XYZ
properties to the AnnotationDictionary.All three options could use more complex attributes, e.g.
AnnotationMeta
class which would have (1) the author of the annotation, (2) contents (3) modification dateAnnotationAppearance
class which would have (1) border_color (2) fill_colorShared parameter
According to "Table 164 – Entries common to all annotation dictionaries" the following properties are shared:
There is also "Table 171 – Annotation states" adding potentially a few more:
Pros / Cons
Plain Parameter vs Rest
AnnotationDictionary-base + Custom classes + properties
pypdf.annotations
to get rid of that issue.What do other libraries do?
PyMuPDF
A lot in plain parameters, but also some (non-fluid) parameters 🤔 😕
See https://pymupdf.readthedocs.io/en/latest/recipes-annotations.html
FPDF2
https://pyfpdf.github.io/fpdf2/Annotations.html
Looks like pure parameters:
Question / Discussion
What do you think about the three options? Which aspects are important to you? Where do you see pros / cons?
Beta Was this translation helpful? Give feedback.
All reactions