File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments