Skip to content

Looking for all pages with for loop #381

Answered by samkit-jain
erkin98 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @erkin98 , could you confirm that the PDF indeed has more than 1 page and there is no break condition in the code that you may have missed out on adding here?

Running

import pdfplumber
tb = []

with pdfplumber.open(path) as pdf:
    for i in range(len(pdf.pages)):
        print(pdf.pages[i].extract_text())

works fine for me. Also, instead of doing for i in range, you can also do

for page in pdf.pages:
    print(page.extract_text())

since pdf.pages is an iterable and to get the iteration number, you can leverage using page.page_number (it will be 1-based and not 0-based).

If the PDF indeed has more than 1 page, request you to share the PDF and the output you are getting so that I can in…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@erkin98
Comment options

@samkit-jain
Comment options

@erkin98
Comment options

Answer selected by erkin98
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants