How to : create a ink annotation from a string #1983
Replies: 4 comments 2 replies
-
Interesting idea! |
Beta Was this translation helpful? Give feedback.
-
I am not sure where to look at the moment, but all fonts in the end compose their characters (glyphs actually) from Bézier curves. Another idea:
doc=fitz.open()
page=doc.new_page()
page.insert_text((0,20),"Hello")
1
svg_string=page.get_svg_image()
print(svg_string)
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="595pt" height="842pt" viewBox="0 0 595 842">
<defs>
<path id="font_1_41" d="M.5509949 .33198548V0H.6439972V.72898867H.5509949V.4139862H.17599488V.72898867H.08299255V0H.17599488V.33198548H.5509949Z"/>
<path id="font_1_70" d="M.5130005 .23399353C.5130005 .31399537 .5069885 .3619995 .49198915 .40098573 .45799256 .4869995 .37799073 .5389862 .27999879 .5389862 .13398743 .5389862 .039993287 .42799378 .039993287 .25498963 .039993287 .08198547 .12998963-.023010254 .27799989-.023010254 .397995-.023010254 .48098756 .04499817 .5019989 .15899658H.41799928C.394989 .08999634 .34799195 .053985597 .2809906 .053985597 .22799683 .053985597 .18299866 .07798767 .15499878 .12199402 .1349945 .1519928 .12799073 .18199158 .1269989 .23399353H.5130005M.1289978 .3019867C.13598633 .39898683 .19499207 .46199037 .2789917 .46199037 .3639984 .46199037 .4229889 .3959961 .4229889 .3019867H.1289978Z"/>
<path id="font_1_77" d="M.1519928 .72898867H.067993167V0H.1519928V.72898867Z"/>
<path id="font_1_80" d="M.27198792 .5389862C.12399292 .5389862 .035995485 .43399049 .035995485 .2579956 .035995485 .08099365 .12399292-.023010254 .272995-.023010254 .42099-.023010254 .5099945 .08198547 .5099945 .2539978 .5099945 .43598939 .42399598 .5389862 .27198792 .5389862M.272995 .46199037C.36698915 .46199037 .4229889 .3849945 .4229889 .25498963 .4229889 .1309967 .36499024 .053985597 .272995 .053985597 .17999268 .053985597 .12298584 .1309967 .12298584 .2579956 .12298584 .3849945 .17999268 .46199037 .272995 .46199037Z"/>
</defs>
<use data-text="H" xlink:href="#font_1_41" transform="matrix(11,0,0,-11,0,20)"/>
<use data-text="e" xlink:href="#font_1_70" transform="matrix(11,0,0,-11,7.942001,20)"/>
<use data-text="l" xlink:href="#font_1_77" transform="matrix(11,0,0,-11,14.0580019,20)"/>
<use data-text="l" xlink:href="#font_1_77" transform="matrix(11,0,0,-11,16.500002,20)"/>
<use data-text="o" xlink:href="#font_1_80" transform="matrix(11,0,0,-11,18.942002,20)"/>
</svg> |
Beta Was this translation helpful? Give feedback.
-
Hi @JorjMcKie Thank you for your reply and your detailed messages. I tried the second idea. I get the same results than with my Cairo solution, except that I am not using one more dependencies. I did not tried the first one because I did not understand :D completely how to do it :/. Do you know if it will be possible to add stamp annotation by providing a picture or any kind of annotation where I can have as input : string + font or image ? Because I can create an image with a text + font. |
Beta Was this translation helpful? Give feedback.
-
it is possible to have a stamp type annotation where to put an image for us and not one of the predefined values for the stamp |
Beta Was this translation helpful? Give feedback.
-
Hello,
I am trying to convert a string to an ink annotation using a a font.
Why :
I created a SVG from text using Cairo :
Then I get the SVG path to create a list of list of points :D (as described here https://pymupdf.readthedocs.io/en/latest/recipes-annotations.html#how-to-use-ink-annotations) and I used
annot = page.add_ink_annot(all_pixels_svg)
.But at the end I have a stroke SVG.
Do you have any suggestion, others solutions ?
My goal is to write like an ink signature from a given string.
Beta Was this translation helpful? Give feedback.
All reactions