Skip to content

Commit e86d9ba

Browse files
Merge pull request #189 from chinapandaman/PPF-179
PPF-179: update docs for file adapter
2 parents babf263 + 4d57d9c commit e86d9ba

16 files changed

+304
-359
lines changed

PyPDFForm/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
PyPDFForm = Wrapper
66

7-
__version__ = "0.3.1"
7+
__version__ = "0.3.2"

README.md

+16-17
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,23 @@ PATH_TO_FILLED_PDF_FORM = os.path.join(
3131
os.path.expanduser("~"), "output.pdf"
3232
) # Change this to where you wish to put your filled PDF form
3333

34-
with open(PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM, "rb+") as template:
35-
filled_pdf = PyPDFForm(
36-
template.read(),
37-
simple_mode=False,
38-
global_font_size=20,
39-
).fill(
40-
{
41-
"test": "test_1",
42-
"check": True,
43-
"test_2": "test_2",
44-
"check_2": False,
45-
"test_3": "test_3",
46-
"check_3": True,
47-
},
34+
with open(PATH_TO_FILLED_PDF_FORM, "wb+") as output:
35+
output.write(
36+
PyPDFForm(
37+
PATH_TO_DOWNLOADED_SAMPLE_PDF_FORM, simple_mode=False, global_font_size=20,
38+
)
39+
.fill(
40+
{
41+
"test": "test_1",
42+
"check": True,
43+
"test_2": "test_2",
44+
"check_2": False,
45+
"test_3": "test_3",
46+
"check_3": True,
47+
},
48+
)
49+
.read()
4850
)
49-
50-
with open(PATH_TO_FILLED_PDF_FORM, "wb+") as output:
51-
output.write(filled_pdf.read())
5251
```
5352

5453
After running the above code snippet you can find `output.pdf` at the location you specified,

docs/v2/api_reference.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ mode on and off yields different interactions with the fill method.
1515

1616
#### Parameters:
1717

18-
* **template** - a byte stream of the unfilled PDF form template. Usually generated
19-
by Python IO's `.read()` method.
18+
* **template** - a file path, file object, or `bytes` stream of the unfilled PDF form template.
2019

2120
* **simple_mode** - a simple mode PyPDFForm object only allows filling data without specifying
2221
details like font size. Turning simple mode on also allows leaving PDF editable
@@ -48,13 +47,12 @@ This operation can also be done by assignment operator `+=`.
4847

4948
### **draw_image**(*image, page_number, x, y, width, height, rotation=0*)
5049

51-
The draw image method takes an image byte stream and draws it
50+
The draw image method takes an image and draws it
5251
on the specified page, coordinates with specified resolutions and rotation angle.
5352

5453
#### Parameters:
5554

56-
* **image** - bytes, a byte stream of the image. Usually generated by Python IO's
57-
`.read()` method.
55+
* **image** - a file path, file object, or `bytes` stream of the image.
5856

5957
* **page_number** - integer, page number of which the image will be drawn on.
6058

@@ -121,7 +119,7 @@ Its values currently support the following:
121119
3) An `integer`, which will select the corresponding option of a group of radio buttons with the same name.
122120
NOTE: Only groups of radio buttons with the same name are supported. If there is only one
123121
radio button with a name, please consider using `checkbox` instead.
124-
4) A valid image `bytes` stream, which will be drawn on the corresponding `image` element.
122+
4) A valid image file path, file object, or `bytes` stream, which will be drawn on the corresponding `image` element.
125123

126124
* **editable** - only available if `simple_mode` is `True`, enabling this will allow the filled PDF to be still
127125
editable. NOTE: `image` elements that are filled via the `fill` method will NOT be editable even if this is `True`.
@@ -130,7 +128,7 @@ editable. NOTE: `image` elements that are filled via the `fill` method will NOT
130128

131129
Returns the `stream`. This method allows the implementation of PyPDFForm to behave like a file object.
132130

133-
### **register_font**(*font_name, ttf_stream*)
131+
### **register_font**(*font_name, ttf_file*)
134132

135133
This class method takes a TTF font file stream and register it with the `font_name` specified.
136134
Registered fonts can then be used by any instance of object.
@@ -140,7 +138,7 @@ Registered fonts can then be used by any instance of object.
140138
* **font_name** - a string of which the font will be registered as. Registered fonts can be referenced and
141139
used via this name.
142140

143-
* **ttf_stream** - a byte stream of the ttf font file.
141+
* **ttf_file** - a file path, file object, or `bytes` stream of the ttf font file.
144142

145143
### **simple_mode** = *True*
146144

@@ -149,7 +147,7 @@ like font size.
149147

150148
### **stream** = *b""*
151149

152-
A byte object which holds the stream with the current state of the PDF form. This can be used by
150+
A `bytes` object which holds the stream with the current state of the PDF form. This can be used by
153151
Python IO to `.write` to another destination.
154152

155153
## Element Object

0 commit comments

Comments
 (0)