Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 676405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:55:27+00:00 2026-05-14T00:55:27+00:00

I have some code to read from a pdf file. Is there a way

  • 0

I have some code to read from a pdf file. Is there a way to read line by line from the pdf file (not pages) using Pypdf, Python 2.6, on Windows?

Here is the code for reading the pdf pages:

import pyPdf

def getPDFContent(path):
    content = ""
    num_pages = 10
    p = file(path, "rb")
    pdf = pyPdf.PdfFileReader(p)
    for i in range(0, num_pages):
        content += pdf.getPage(i).extractText() + "\n"
    content = " ".join(content.replace(u"\xa0", " ").strip().split())
    return content

Update:

The call code is this:

f= open('test.txt','w')
pdfl = getPDFContent("test.pdf").encode("ascii", "ignore")
f.write(pdfl)
f.close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:55:27+00:00Added an answer on May 14, 2026 at 12:55 am

    Looks like what you have is a large chunk of text data that you want to interpret line-by-line.

    You can use the StringIO class to wrap that content as a seekable file-like object:

    >>> import StringIO
    >>> content = 'big\nugly\ncontents\nof\nmultiple\npdf files'
    >>> buf = StringIO.StringIO(content)
    >>> buf.readline()
    'big\n'
    >>> buf.readline()
    'ugly\n'
    >>> buf.readline()
    'contents\n'
    >>> buf.readline()
    'of\n'
    >>> buf.readline()
    'multiple\n'
    >>> buf.readline()
    'pdf files'
    >>> buf.seek(0)
    >>> buf.readline()
    'big\n'
    

    In your case, do:

    from StringIO import StringIO
    
    # Read each line of the PDF
    pdfContent = StringIO(getPDFContent("test.pdf").encode("ascii", "ignore"))
    for line in pdfContent:
        doSomething(line.strip())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using iTextSharp to read the text from a PDF file. However, there are
I have some code to read the lines from a file, I would like
I have been trying to write some code in Scala to read a file
In support of some legacy code, I have to read a text file and
I currently have some code in Python where I have entered the values from
I have some code that downloads a file from the internet located here: http://www.amsat.org/amsat/ftp/keps/current/nasa.all
I have some code to download a text file from a website. When the
I have some SerialPort code that constantly needs to read data from a serial
I have some code in my classes to read from NSUserDefaults NSUserDefaults *defs =
Imagine I have some code to read from the start to end of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.