Skip to content

Commit 6bc58c8

Browse files
authored
Merge pull request DhanushNehru#210 from ruchit-t/feat-convert-emoji-to-pdf
Add Emoji to PDF script
2 parents 6d6a173 + 783475a commit 6bc58c8

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ More information on contributing and the general code of conduct for discussion
4848
| Digital Clock | [Digital Clock](https://github.com/DhanushNehru/Python-Scripts/tree/master/Digital%20Clock) | A Python script to preview a digital clock in the terminal. |
4949
| Duplicate Finder | [Duplicate Finder](https://github.com/DhanushNehru/Python-Scripts/tree/master/Duplicate%Fnder) | The script identifies duplicate files by MD5 hash and allows deletion or relocation. |
5050
| Display Popup Window | [Display Popup Window](https://github.com/DhanushNehru/Python-Scripts/tree/master/Display%20Popup%20Window) | A Python script to preview a GUI interface to user. |
51+
| Emoji in PDF | [Emoji in PDF](https://github.com/DhanushNehru/Python-Scripts/tree/master/Expense%20Tracker) | A Python Script to view Emoji in PDF.
5152
| Expense Tracker | [Expense Tracker](https://github.com/DhanushNehru/Python-Scripts/tree/master/Expense%20Tracker) | A Python script which can track expenses. |
5253
| Face Reaction | [Face Reaction](https://github.com/DhanushNehru/Python-Scripts/tree/master/Face%20Reaction) | A script which attempts to detect facial expressions. |
5354
| Fake Profiles | [Fake Profiles](https://github.com/DhanushNehru/Python-Scripts/tree/master/Fake%20Profile) | Create fake profiles. |

emoji_to_pdf/Symbola_hint.ttf

3.55 MB
Binary file not shown.

emoji_to_pdf/emoji.pdf

65.8 KB
Binary file not shown.

emoji_to_pdf/emoji_to_pdf.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from reportlab.platypus import Paragraph
2+
from reportlab.lib.styles import getSampleStyleSheet
3+
from reportlab.pdfgen import canvas
4+
from reportlab.rl_config import defaultPageSize
5+
from reportlab.pdfbase import pdfmetrics
6+
from reportlab.pdfbase.ttfonts import TTFont
7+
from emojipy import Emoji
8+
import re
9+
10+
Emoji.unicode_alt = False
11+
12+
def create_emoji_pdf(txt, size):
13+
txt = Emoji.to_image(txt)
14+
txt = txt.replace('class="emojione " style="" ', 'height=%s width=%s' %(size, size))
15+
return re.sub('alt="'+Emoji.shortcode_regexp+'"', '', txt)
16+
17+
txt_file = "Hello World 😂👍😂🙌😉🤳🤷‍♀️🙌😁🎂🐱‍👤🤳✔💋🐱‍👓🐱‍👓😃🎁"
18+
symbola_font = TTFont('Symbola', 'Symbola_hint.ttf')
19+
pdfmetrics.registerFont(symbola_font)
20+
width, height = defaultPageSize
21+
styles = getSampleStyleSheet()
22+
styles["Title"].fontName = 'Symbola'
23+
style = styles["Title"]
24+
content = create_emoji_pdf(Emoji.to_image(txt_file), style.fontSize)
25+
para = Paragraph(content, style)
26+
canv = canvas.Canvas('emoji.pdf')
27+
para.wrap(width, height)
28+
para.drawOn(canv, 0, height/2)
29+
canv.save()

emoji_to_pdf/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
emojipy == 3.0.5
2+
reportlab ==4.0.7
3+
six == 1.16.0

0 commit comments

Comments
 (0)