Open cjhal1030 opened 4 years ago
I managed to add text amending the ReadMe example like this:
from pdf_annotate import PdfAnnotator, Location, Appearance
a = PdfAnnotator('a.pdf')
a.add_annotation(
'text',
Location(x1=50, y1=50, x2=100, y2=100, page=0),
Appearance(stroke_color=(1, 0, 0), stroke_width=5, content="hello world", fill=(0.705, 0.094, 0.125, 1))
)
a.write('b.pdf') # or use overwrite=True if you feel
'content' is the text you want to write and 'fill' is the colour. 'Fill' seems to accept RGB(A) normalised decimal colours. I used this colour picker to get the value:
http://doc.instantreality.org/tools/color_calculator/
Thanks to the developers for the nice project - a few more usage examples would be great!
I found the usage inside the test cases. This is the snippet from my script,
a.add_annotation(
'text',
Location(x1=x1+5, y1=y1, x2=x2, y2=y2, page=page),
Appearance(
fill=[0.4, 0, 0],
stroke_width=1,
font_size=10,
content=filename,
),
)
Can you tell me what is expected to put in the Appearance()? I tried to add content = 'test' but kept giving me the 'NoneType' object is not subscriptable error.
from pdf_annotate import PdfAnnotator, Location, Appearance a = PdfAnnotator('a.pdf') a.add_annotation( 'text', Location(x1=50, y1=50, x2=100, y2=100, page=0), Appearance(), ) a.write('b.pdf')