Add editable text box in a pdf file #514
Unanswered
gregorycottone
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, with the following Python code snippet I'm able to add a black boxes in a particular position and with a certain dimension in a pdf file:
`
from pikepdf import Pdf, Name, Dictionary, Array
highlight = Dictionary(
Type=Name.Annot,
Subtype=Name.Square,
QuadPoints=[boundingBox[0], boundingBox[3],
boundingBox[2], boundingBox[3],
boundingBox[0], boundingBox[1],
boundingBox[2], boundingBox[1]],
Rect=[boundingBox[0], boundingBox[1], boundingBox[2], boundingBox[3]],
C = [1, 1, 1], # 1, 1, 1 is white, while 0, 0, 0 is black
CA = 1,
IC = [0, 0, 0], # 1, 1, 1 is white, while 0, 0, 0 is black
T=analyzed_bounding_box["result"].entity_type, # string that specifies the entity type (for example LOCATION, DATE_TIME, etc)
)`
Obtaining this result:
Which is nice because I can edit the black boxes from Adobe reader, for example I can change position, dimension and color of the boxes once I open the redacted pdf file.
This is an example of the box object I have:
pikepdf.Dictionary(Type="/Annot")({ "/C": [ 1, 1, 1 ], "/CA": 1, "/IC": [ 0, 0, 0 ], "/QuadPoints": [ Decimal('346.53008'), Decimal('577.39'), Decimal('391.18688'), Decimal('577.39'), Decimal('346.53008'), Decimal('566.35'), Decimal('391.18688'), Decimal('566.35') ], "/Rect": [ Decimal('346.53008'), Decimal('566.35'), Decimal('391.18688'), Decimal('577.39') ], "/Subtype": "/Square", "/T": "LOCATION", "/Type": "/Annot" })
Now my question is: is it possible to add white text inside the box? If yes what should I change in the code snippet?
Beta Was this translation helpful? Give feedback.
All reactions