#๐Ÿ”’ Extracting text from pdf gone wrong

21 messages ยท Page 1 of 1 (latest)

silver sequoia
#

This is the output when i try to extract text from the pdf when dealing with binary [Running] python -u "c:\Users\Lenovo\Desktop\Github Projects\PDF file opener(old)\script.py" PDF header: b'%PDF-1.3' xref start: 18788 Stream content (raw): b'x\x01\x9dZ\xcb\x92\xdbF\x12\xbc\xe3+\xfa\xc8\x89\xf0\x8c\xd9\r>\x8f^\xd9\x8a\xf0\xc6\xda!\x87\xc7\xbb\x87\r\x1f0$4j\x07\x08R\x040\x9f\xbb\xdf\xb2\x99\xd5U\rP\xa4d\x8d\xf6\x11\xe2\x80\x8dFuVV\xd6\x03\xfc\xe8~s\x1f\xdd\x1c\xff]\xf9\xe0\xd6\xdb\xe0\xce\xb5\xfb\x8fk\xdd\xf7o:\xefv\x9d\xf3\xae\xdb}\xfa\xfd{7' Encoding algorithm: FlateDecode Decoded stream content: b'q Q q 0 0 612 792 re W n /Cs1 cs 1 sc 0 0 612 792 re f 0.6000000 i 0 0 612 792\nre f 0.3019608 sc 0 i' ['Sample PDF', 'This is a simple PDF le. Fun fun fun.', 'pulvinar quis, nisl.', 'feugiat. Aenean pellentesque.', 'quam.'] Extracted text: Sample PDFThis is a simple PDF le. Fun fun fun.pulvinar quis, nisl.feugiat. Aenean pellentesque.quam.

Code:
https://pastebin.com/YZTpcfqJ

sterile coveBOT
#

@silver sequoia

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

silver sequoia
#

i know what the issue is, there are 5 streams but only 1 of them is being outputted but idk how to fix it

slow star
silver sequoia
#

No i am not im tryna extract content from a pdf from scratch

#

How come there are 14 viewers on the pastebin๐Ÿ’€๐Ÿ™

slow star
#

This is a somewhat fragile way to get streams but, hey, it works.

#
        #find body
        text_start = file_content.find(b'stream') #find start of body
        text_end = file_content.find(b'endstream', text_start) #find end of body

You're only looking for one stream. You'd need a loop most likely.

silver sequoia
slow star
#

My recommendation would be to parse the XRef. That's how you're supposed to extract objects from a PDF.

#

The kind you're dealing with is documented in chapter 7.5.4 of the PDF 1.7 standard

silver sequoia
#

Ok

slow star
silver sequoia
#

I need it from scratch

#

Its alr

slow star
sterile coveBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.