This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyPDF2 import PdfFileWriter, PdfFileReader | |
def add_encryption(input_pdf, output_pdf, password): | |
pdf_writer = PdfFileWriter() | |
pdf_reader = PdfFileReader(input_pdf) | |
for page in range(pdf_reader.getNumPages()): | |
pdf_writer.addPage(pdf_reader.getPage(page)) | |
pdf_writer.encrypt(user_pwd=password, owner_pwd=None, use_128bit=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# importing the required modules | |
from PyPDF2 import PdfFileReader, PdfFileWriter | |
def PDFrotate(Filename, output_name, rotation): | |
pdfFile = open(Filename, 'rb') | |
pdfReader = PdfFileReader(pdfFile) | |
pdfWriter = PdfFileWriter() | |
# rotating each page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# importing the required modules | |
from PyPDF2 import PdfFileReader, PdfFileWrite | |
def PDFrotate(File_Name, output, rotation): | |
pdfFile = open(File_Name, 'rb') | |
pdfReader = PdfFileReader(pdfFile) | |
# creating a pdf writer object for new pdf | |
pdfWriter = PdfFileWriter() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyPDF2 import PdfFileReader | |
pdf_file=open("sample.pdf", 'rb'): | |
pdf = PyPDF2.PdfFileReader(pdf_file) | |
information = pdf.getDocumentInfo() | |
number_of_pages = pdf.getNumPages() | |
info = f""" | |
Information about {pdf_path}: | |
Author: {information.author} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyPDF2 import PdfFileWriter, PdfFileReader | |
def create_watermark(input, output, watermark): | |
watermark_obj = PdfFileReader(watermark) | |
watermark_page = watermark_obj.getPage(0) | |
pdf_reader = PdfFileReader(input_pdf) | |
pdf_writer = PdfFileWriter() | |
# Watermark all the pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyPDF2 import PdfFileReader, PdfFileWriter | |
def merge_pdfs(filenames): | |
pdf_writer = PdfFileWriter() | |
for path in filenames: | |
pdf_reader = PdfFileReader(path) | |
for page in range(pdf_reader.getNumPages()): | |
# Add each page to the writer object | |
pdf_writer.addPage(pdf_reader.getPage(page)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#importing libraries | |
from PyPDF2 import PdfFileReader, PdfFileWriter | |
def split(path): | |
pdf = PdfFileReader(path) | |
for page in range(pdf.getNumPages()): | |
pdf_writer = PdfFileWriter() | |
pdf_writer.addPage(pdf.getPage(page)) | |
output = f'page{page}.pdf' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# importing modules | |
import PyPDF2 | |
pdfFileObj = open('file.pdf', 'rb') | |
# creating a pdf reader object | |
pdfReader = PyPDF2.PdfFileReader(pdfFileObj) | |
pagecount=pdfReader.numPages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# importing modules | |
import PyPDF2 | |
pdfFileObj = open('file.pdf', 'rb') | |
# creating a pdf reader object | |
pdfReader = PyPDF2.PdfFileReader(pdfFileObj) | |
# creating a page object | |
pageObj = pdfReader.getPage(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# importing required modules | |
import PyPDF2 | |
# creating a pdf file object | |
pdfFileObj = open('file.pdf', 'rb') | |
# creating a pdf reader object | |
pdfReader = PyPDF2.PdfFileReader(pdfFileObj) | |
# printing number of pages in pdf file |
NewerOlder