Question: Hey Ahmad, I have wrote this python code to convert pdf file to . COB I am not receiving the output files, that is I
Hey Ahmad,
I have wrote this python code to convert pdf file to COB I am not receiving the output files, that is I am not getting the COB can you assist?
# importing required classes
from PyPDF import PdfReader
import os
from openbabel import openbabel as ob
def pdftotextpdffile:
text
# Open the PDF file
with openpdffile, rb as file:
reader PdfReaderfile
# Extract text from each page
for pagenum in rangelenreaderpages:
page reader.pagespagenum # Fixed from pagenumber to pagenum
text page.extracttext
return text
def texttocobtext cobfile:
# Initialize OpenBabel converter
conv obOBConversion
conv.SetInAndOutFormatssmi "cob"
# Convert text to COB format
mol obOBMol
conv.ReadStringmol text
# Print the converted text
convertedtext conv.WriteStringmol
printConverted text to COB format:"
printconvertedtext
# Write COB file
conv.WriteFilemol cobfile
printfCOB file cobfile created successfully."
def batchconvertpdftocobpdffolder, cobfolder:
# Iterate through all PDF files in the folder
for filename in oslistdirpdffolder:
if filename.endswithpdf:
pdffile ospath.joinpdffolder, filename
printfProcessing PDF file: pdffile
# Open the PDF file
with openpdffile, rb as file:
pdfreader PdfReaderfile
# Process the PDF content
# For example, you can access pages using pdfreader.pages
# and extract text using page.extracttext method
# You need to define your logic here based on what you want to do with the PDF content
tex pdftotextpdffile
cobfile ospath.joincobfolder, ospath.splitextfilenamecob'
texttocobtext cobfile
printfCOB file cobfile created successfully."
# Specify input and output folders
pdffolder rC:UserscDocumentsmainframeCOBOL'
cobfolder rC:UserscDocumentsoutputcobfolder'
# Perform batch conversion
batchconvertpdftocobpdffolder,cobfolder
this is the output: Processing PDF file: C:UserscDocumentsmainframeCOBOLZLpdf
Converted text to COB format:
COB file C:UserscDocumentsoutputcobfolderZLcob' created successfully.
COB file C:UserscDocumentsoutputcobfolderZLcob' created successfully.
Processing PDF file: C:UserscDocumentsmainframeCOBOLZPpdf
Converted text to COB format:
what's up get the correct message but not conversion files
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
