@kowts @Allan_Zimmermann .
I am run this code in open rpa
import os
from PyPDF2 import PdfReader, PdfWriter
Set the input file name
input_file = ‘Sample 3.pdf’
folder_Name = os.path.splitext(input_file)[0]
Set variable that the number of pages per output PDF file
pages_per_file = 1
Create the output folder as that of pdf name
if not os.path.exists(folder_Name):
os.mkdir(folder_Name)
now open the respective pdf fil and read it after reading store it in another variable.
with open(input_file, ‘rb’) as infile:
pdf_reader = PdfReader(infile)
# using for loop Iterate through the pages of the input PDF file
for page_num in range(len(pdf_reader.pages)):
# It Create a new PDF file for every 'pages_per_file' number of pages
if page_num % pages_per_file == 0:
# If this is not the first file, close the previous one
if 'outfile' in locals():
outfile.close()
# Create a new output PDF file
output_file = folder_Name+'/{}_{}.pdf'.format(os.path.splitext(input_file)[0], page_num // pages_per_file + 1)
outfile = open(output_file, 'wb')
# Create a new PDF writer object for the output file
pdf_writer = PdfWriter()
# Get the current page of the input PDF file
page = pdf_reader.pages[page_num]
# Add the page to the current output PDF file
pdf_writer.add_page(page)
# If we have reached the end of a 'pages_per_file' number of pages, save the output file and start a new one
if (page_num + 1) % pages_per_file == 0:
pdf_writer.write(outfile)
# If there are any remaining pages, save them to a new output file
if 'outfile' in locals():
pdf_writer.write(outfile)
outfile.close()
But get the error like this :- ERROR: Could not find a version that satisfies the requirement PdfWriter (from versions: none)
ERROR: No matching distribution found for PdfWriter
i also use PIP install activity and pass the value like this {“PyPDF2”,“PdfReader”,“PdfWriter”,“os”}.
Correct me if am wrong