Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Usage of 'text' annot type #52

Open
cjhal1030 opened this issue Apr 16, 2020 · 2 comments
Open

Usage of 'text' annot type #52

cjhal1030 opened this issue Apr 16, 2020 · 2 comments

Comments

@cjhal1030
Copy link

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')

@richardbatstone
Copy link

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!

@michaeleekk
Copy link

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,
                ),
            )

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants