@@ -86,6 +86,51 @@ with open(PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM, "rb+") as template:
86
86
87
87
Link to this example: https://github.com/chinapandaman/PyPDFForm/blob/master/examples/simple_fill_editable.py
88
88
89
+ ## Register font and set registered global font on filled text
90
+
91
+ This example registers a [ LiberationSerif-Regular] ( https://github.com/chinapandaman/PyPDFForm/blob/master/font_samples/LiberationSerif-Regular.ttf )
92
+ font and sets it as the global font on the filled PDF form.
93
+
94
+ ``` python
95
+ import os
96
+
97
+ from PyPDFForm import PyPDFForm
98
+
99
+ PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM = os.path.join(
100
+ os.path.expanduser(" ~/Downloads" ), " sample_template.pdf"
101
+ ) # Change this to where you downloaded the sample PDF form
102
+
103
+ PATH_TO_SAMPLE_TTF_FONT_FILE = os.path.join(
104
+ os.path.expanduser(" ~/Downloads" ), " LiberationSerif-Regular.ttf"
105
+ ) # Change this to where you downloaded the sample font file
106
+
107
+ PATH_TO_FILLED_PDF_FORM = os.path.join(
108
+ os.path.expanduser(" ~" ), " output.pdf"
109
+ ) # Change this to where you wish to put your filled PDF form
110
+
111
+ with open (PATH_TO_SAMPLE_TTF_FONT_FILE , " rb+" ) as font:
112
+ PyPDFForm.register_font(" LiberationSerif-Regular" , font.read())
113
+
114
+ with open (PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM , " rb+" ) as template:
115
+ filled_pdf = PyPDFForm(
116
+ template.read(), simple_mode = False , global_font = " LiberationSerif-Regular" ,
117
+ ).fill(
118
+ {
119
+ " test" : " test_1" ,
120
+ " check" : True ,
121
+ " test_2" : " test_2" ,
122
+ " check_2" : False ,
123
+ " test_3" : " test_3" ,
124
+ " check_3" : True ,
125
+ },
126
+ )
127
+
128
+ with open (PATH_TO_FILLED_PDF_FORM , " wb+" ) as output:
129
+ output.write(filled_pdf.stream)
130
+ ```
131
+
132
+ Link to this example: https://github.com/chinapandaman/PyPDFForm/blob/master/examples/fill_font.py
133
+
89
134
## Set global font size and font color on filled text
90
135
91
136
This example sets a global font size of 20, and a global font color of red
@@ -354,10 +399,17 @@ PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM = os.path.join(
354
399
os.path.expanduser(" ~/Downloads" ), " sample_template.pdf"
355
400
) # Change this to where you downloaded the sample PDF form
356
401
402
+ PATH_TO_SAMPLE_TTF_FONT_FILE = os.path.join(
403
+ os.path.expanduser(" ~/Downloads" ), " LiberationSerif-Italic.ttf"
404
+ ) # Change this to where you downloaded the sample font file
405
+
357
406
PATH_TO_FILLED_PDF_FORM = os.path.join(
358
407
os.path.expanduser(" ~" ), " output.pdf"
359
408
) # Change this to where you wish to put your filled PDF form
360
409
410
+ with open (PATH_TO_SAMPLE_TTF_FONT_FILE , " rb+" ) as font:
411
+ PyPDFForm.register_font(" LiberationSerif-Italic" , font.read())
412
+
361
413
with open (PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM , " rb+" ) as template:
362
414
pdf_form = PyPDFForm(template.read(), simple_mode = False )
363
415
@@ -367,6 +419,7 @@ with open(PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM, "rb+") as template:
367
419
pdf_form.elements[" test_2" ].text_y_offset = - 50
368
420
pdf_form.elements[" test_2" ].text_wrap_length = 1
369
421
pdf_form.elements[" test_2" ].font_color = (0 , 1 , 0 )
422
+ pdf_form.elements[" test_3" ].font = " LiberationSerif-Italic"
370
423
pdf_form.elements[" test_3" ].text_wrap_length = 2
371
424
pdf_form.elements[" test_3" ].font_color = (0 , 0 , 1 )
372
425
0 commit comments