Skip to content

Commit d3784f5

Browse files
Script to view an emoji in pdf #43 (#172)
* Add files via upload * Script to view an emoji in pdf #43
1 parent 11e68e4 commit d3784f5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

emoji/emoji.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from reportlab.pdfgen import canvas
2+
from reportlab.lib.pagesizes import letter
3+
from reportlab.pdfbase import pdfmetrics
4+
from reportlab.pdfbase.ttfonts import TTFont
5+
6+
def create_pdf_with_emoji(output_filename, emoji, font_path):
7+
# Create a canvas for the PDF
8+
c = canvas.Canvas(output_filename, pagesize=letter)
9+
10+
# Register a custom emoji font
11+
pdfmetrics.registerFont(TTFont('EmojiFont', font_path))
12+
13+
# Set the font for the emoji
14+
c.setFont('EmojiFont', 36)
15+
16+
# Add the emoji to the PDF
17+
c.drawString(100, 400, emoji)
18+
19+
# Save the PDF
20+
c.save()
21+
22+
if __name__ == "__main__":
23+
output_filename = "emoji.pdf"
24+
emoji = "😊" # Replace with the emoji you want to display
25+
font_path ="emoji.tiff" # Replace with the path to your emoji font
26+
27+
create_pdf_with_emoji(output_filename, emoji, font_path)

emoji/emoji.tiff

55.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)