📄 PDF Module
The PDF module provides everything needed to create, edit, merge, split, secure, compress and analyze PDF documents using simple Python functions.
- Create PDF documents
- Merge and split PDFs
- Extract text and images
- Insert or delete pages
- Rotate pages
- Add watermarks
- Encrypt and decrypt PDFs
- Compress PDF files
- Read metadata and page information
Quick Example
💻 Code
import allkitpy
allkitpy.pdf.create(
"hello.pdf",
"Hello from AllkitPy"
)
📄 Output
hello.pdf created
Functions
create()
Create a new PDF document containing the specified text.
💻 Code
import allkitpy
allkitpy.pdf.create(
"hello.pdf",
"Hello from AllkitPy"
)
📄 Output
hello.pdf created
merge()
Merge multiple PDF files into a single PDF document.
💻 Code
import allkitpy
allkitpy.pdf.merge(
[
"chapter1.pdf",
"chapter2.pdf",
"chapter3.pdf"
],
"book.pdf"
)
📄 Output
book.pdf created
split()
Split a PDF document into individual PDF files.
💻 Code
import allkitpy
allkitpy.pdf.split(
"book.pdf",
"pages"
)
📄 Output
pages/
├── page_1.pdf
├── page_2.pdf
├── page_3.pdf
...
extract_text()
Extract all text from a PDF document.
💻 Code
import allkitpy
text = allkitpy.pdf.extract_text(
"book.pdf"
)
print(text)
📄 Output
Hello World
Chapter 1
This is the content
inside the PDF...
extract_images()
Extract every image from a PDF document into a folder.
💻 Code
import allkitpy
allkitpy.pdf.extract_images(
"book.pdf",
"images"
)
🖼️ Output
images/
├── image_1.png
├── image_2.jpg
├── image_3.png
...
metadata()
Retrieve metadata stored inside a PDF document.
💻 Code
import allkitpy
info = allkitpy.pdf.metadata(
"book.pdf"
)
print(info)
📄 Output
{
'title': 'Python Guide',
'author': 'John',
'creator': 'Word',
'producer': 'Microsoft'
}
page_count()
Return the total number of pages in a PDF document.
💻 Code
import allkitpy
count = allkitpy.pdf.page_count(
"book.pdf"
)
print(count)
📄 Output
125
page_size()
Return the width and height of a page.
💻 Code
import allkitpy
size = allkitpy.pdf.page_size(
"book.pdf"
)
print(size)
📄 Output
(595.0, 842.0)
rotate()
Rotate every page in a PDF by 90°, 180°, or 270°.
💻 Code
import allkitpy
allkitpy.pdf.rotate(
"book.pdf",
90,
"rotated.pdf"
)
📄 Output
rotated.pdf created
delete_pages()
Delete one or more pages from a PDF document.
💻 Code
import allkitpy
allkitpy.pdf.delete_pages(
"book.pdf",
[0, 2],
"updated.pdf"
)
📄 Output
updated.pdf created
insert_pages()
Insert pages from another PDF into an existing PDF.
💻 Code
import allkitpy
allkitpy.pdf.insert_pages(
"book.pdf",
"appendix.pdf",
5,
"updated.pdf"
)
📄 Output
updated.pdf created
watermark()
Add a text watermark to every page of a PDF document.
💻 Code
import allkitpy
allkitpy.pdf.watermark(
"report.pdf",
"CONFIDENTIAL",
"watermarked.pdf"
)
📄 Output
watermarked.pdf created
encrypt()
Protect a PDF document using AES-256 password encryption.
💻 Code
import allkitpy
allkitpy.pdf.encrypt(
"report.pdf",
"mypassword",
"secure.pdf"
)
🔒 Output
secure.pdf created
Password Protected
decrypt()
Remove password protection from an encrypted PDF document.
💻 Code
import allkitpy
allkitpy.pdf.decrypt(
"secure.pdf",
"mypassword",
"unlocked.pdf"
)
🔓 Output
unlocked.pdf created
Password Removed
compress()
Optimize and compress a PDF document to reduce file size.
💻 Code
import allkitpy
allkitpy.pdf.compress(
"large.pdf",
"compressed.pdf"
)
📦 Output
compressed.pdf created
Smaller file size