'PyPDF2 Merger Gives Empty Output
I'm a student pursuing GIS and Python is something I've just dipped my toes into. I have an internship that requires me to convert large 500+ pdf reports into individual pdf files for each sample. I've named the pdfs by an alphabetical convention by the order I want the pages, for example, the samples are named 13-A100, 13-A101 etc, and for the first page, I add an alphabetical suffix, like 13-A100-A1,13-A100-B1,13-A100-B2 Files. All of the pdf files I've split into individual pages, and are all located in the same directory. I've assembled a rough draft of the script do this, but it doesn't output anything, the output directory is empty, but I wasn't getting any syntax errors earlier. For the record, with some help, I did get a code very similar to this one to work before, so I know it can be done without a complete redo. Any help is greatly appreciated. Here is the code from:
from PyPDF2 import PdfFileMerger
from os import listdir
input_dir = r"C:\Users\Owen\Desktop\GLO\TxSED\GRG_350E\All_pages"
merger = PdfFileMerger()
count = 100
while count <= 129:
merge_list = []
for x in listdir(input_dir):
x.startswith('13-A' + str(count)):
merge_list.append(input_dir + x)
for pdf in merge_list:
if count >= 100:
merger.append(pdf)
merger.write(f"C:\Users\Owen\Desktop\GLO\TxSED\GRG_350E\MergedCores\13-A{str(count)}.pdf"))
merger.close()
count += 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|