Skip to content

Commit acb2243

Browse files
author
Laurynas Butkus
committed
Add PDF split and merge example
1 parent 0ca7ea0 commit acb2243

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

examples/split_and_merge_pdf.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import convertapi
2+
import os
3+
import tempfile
4+
5+
convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret
6+
7+
# Example of extracting first and last pages from PDF and then merging them back to new PDF.
8+
# https://www.convertapi.com/pdf-to-split
9+
# https://www.convertapi.com/pdf-to-merge
10+
11+
split_result = convertapi.convert('split', { 'File': 'files/test.pdf' })
12+
13+
first_page = split_result.files[0]
14+
last_page = split_result.files[-1]
15+
files = [first_page, last_page]
16+
17+
merge_result = convertapi.convert('merge', { 'Files': files })
18+
19+
saved_files = merge_result.save_files(tempfile.gettempdir())
20+
21+
print("The thumbnail saved to %s" % saved_files)

0 commit comments

Comments
 (0)