53

I asked a question on Stack Overflow just a while ago, and it is getting a bunch of downvotes. I just don't understand why though, and I would like to get to the bottom of it, so I don't make the mistake repeatedly.

Here is the question:

TITLE: How to parse text in a .pdf, .doc, or .ppt using php?

QUESTION:

Is there a way given a .pdf, .doc, .ppt, or .txt I can read the text content of those files and return the results in a large string. Essentially it takes a file and puts all the text in said file into a string in return. I looked around I don't see anything that can do it all.

Now I get that obviously doing this for a .txt file is a piece of cake, but I feel like from a .ppt or .pdf is a little tricker. I just thought to see if someone has a solution off the top of their head, but it almost instantly got six downvotes.

What am I doing wrong guys?

22
  • 23
    Thank you everyone. I see, that I shouldn't assume that people who might answer know I have made strives already to answer the question. I will provide code next time.
    – Chris
    Commented Oct 9, 2015 at 19:44
  • 51
    Chris, THANK YOU for taking this in stride and improving :) we get too many users who just complain and don't try to improve. Hope you enjoy the site :)
    – Patrice
    Commented Oct 9, 2015 at 19:53
  • 18
    Perhaps the core misunderstanding here was about SO's philosophy. While it is a place to get questions answered quickly, its core mission is to build an archive of canonical Q&A. Everything you write here is written with an eye on how it will benefit future generations. What would be totally cool to ask in a group of colleagues in the pub ("hey guys, I'm writing this search function, anyone know a way, etc. etc.") won't work that way here.
    – Pekka
    Commented Oct 9, 2015 at 20:05
  • 4
    Here, you are expected to look up first what exists on the topic, what can be found on the web, what are the typical existing solutions etc... if after that you hit a snag, it's totally cool to come back, and ask presenting the specific case
    – Pekka
    Commented Oct 9, 2015 at 20:06
  • 6
    The dupe doesn't really answer the question here at all. I found substantially more value in @Pekka웃's answer than the generic, "When should we downvote a question?"
    – Makoto
    Commented Oct 9, 2015 at 21:05
  • 12
    I'm surprised at the total complete lack of meta downvotes, "We are not mind readers", "Nobody is obligated to explain their votes or anyone else's votes", etc in this question. What about it sets it apart from all the other "Why is my question getting downvoted and what can I do to improve it?" questions? Why is everyone acting so positively here? (Not that I disagree with it - I'm just surprised at the complete turnaround, and I hope it stays this way.)
    – BoltClock Mod
    Commented Oct 10, 2015 at 5:16
  • 3
    Quora will happily accept such questions. Sample: How do I parse a PDF file in Java? Commented Oct 10, 2015 at 11:59
  • 16
    @BoltClock: I'd think that starting with "so I don't make the mistake repeatedly" and ending with "What am I doing wrong guys?" helps a lot :)
    – brasofilo
    Commented Oct 10, 2015 at 12:58
  • 2
    Came here expecting a flamefest, and got a very reasonable discussion. Good job, SO! Commented Oct 10, 2015 at 16:10
  • 11
    @BoltClock the OP's question has a clear intent to learn from his mistakes and do better, and that earns respect. Other questions have a tone of "I got downvoted, and I feel wronged" This one is "I got downvoted so obviously made a mistake, how can I do better"?
    – paisanco
    Commented Oct 10, 2015 at 20:02
  • 1
    lol there is no rhyme nor reason to getting downvotes here, it's all up to the whim of the person clicking the button. In the past, I've written questions more organized than I would write for a college term paper. Headings, clearly defined problem and outcome desired, minimum code provided and a working example. Took me over an hour to put together. I clicked the post button confident that I had finely crafted a question that could make SO happy . . .. DOWNVOTE.
    – user5075489
    Commented Oct 10, 2015 at 20:22
  • 1
    @Boltclock What made ME say thanks is that, by the time I got to the question, Pekka & Servy already answered it, there were good explanations and Chris was thanking people already. I don't think anyone is snarky, as long as the question doesn't sound like he's ranting (look at "Actually Helps People"'s comment)
    – Patrice
    Commented Oct 10, 2015 at 20:35
  • 10
    All of you, this was very informative. I am glad this has helped the community a bit, I have used SO a TON throughout my career and I have just started trying to give back and ask quality questions and give informed answers when I can. I see that the question I asked on SO was not as informed and well constructed as this place deserves. This has been very, VERY, helpful for me and I learned a lot about just the people who use this site through it! I never take a downvote as offense, I take a downvote as a need to improve. Thank you all again! So helpful!
    – Chris
    Commented Oct 11, 2015 at 1:45
  • 2
    @BoltClock: is there any comment deleted before OP's first one? If not, hats off.
    – brasofilo
    Commented Oct 11, 2015 at 4:42
  • 3
    @f470071 did you actually read any of the discussion on this page?
    – Pekka
    Commented Oct 12, 2015 at 18:01

3 Answers 3

90

The question is

  • a resource recommendation which we don't do around here (as Servy already pointed out)

  • super easy to Google and has a million existing solutions (php parse pdf, pdf parse doc....)

  • actually three questions with vastly different (and huge) answers in one

  • touching three enormously complex areas with a truckload of follow-up questions that become evident with a bit of research, like like

    • which versions of .doc and .ppt?
    • What do you want to extract from a PDF or PPT where text may be scattered around the layout, making zero sense if extracted stupidly into a string?
    • What server operating system do you need this on?
    • Can you use external executables?
    • Can you use external web services?
    • Are you willing to pay for external tools?
    • Are you willing to pay for external web services?
    • How large are the relevant files going to be?
    • What PDF versions do you need to cover?
    • Will you be needing to deal with different character sets (which again will be a super complex topic for each of the file formats?))
    • and so on.....
11
  • 1
    Yes, I guess I should have put what I had done so far, but the more I Google the more I see that these are very different questions asking for one solution.
    – Chris
    Commented Oct 9, 2015 at 19:42
  • Not necessarily. It'll depend on which way you're going to take, web service or command line tool or something else (see my edit). In my experience there is no one single perfect library to do them all, but I last dealt with this seven years ago and things may have changed.
    – Pekka
    Commented Oct 9, 2015 at 19:44
  • 12
    Yeah, it is for a full-text search function I wrote. It provides documents based on the text results, but I needed a way to read the text out of .ppts and Docxs so I could store them in my DB to use that function. I closed the question and will search more thoroughly then re-ask with more specifics.
    – Chris
    Commented Oct 9, 2015 at 19:48
  • 2
    I haven't seen the original question\post. But shouldn't these things be explained in the comments when someone down-votes? Simply down-voting doesn't tell someone what they did wrong Commented Oct 11, 2015 at 3:43
  • 7
    So you like bulletpoints too? Commented Oct 11, 2015 at 3:50
  • 4
    @dangel No, downvoters are not required to explain their downvote. Commented Oct 11, 2015 at 7:35
  • 2
    @SpencerWieczorek but bullet points are justified here, seeing as it's a list, no?
    – Pekka
    Commented Oct 11, 2015 at 10:16
  • 2
    @Pekka웃 I know, It was just my attempt to be funny :( Commented Oct 11, 2015 at 14:04
  • 1
    @ Mark Rotteveel, not required, but it helps to make the community a better place and keeps people from making the same mistakes over and over again. Commented Oct 11, 2015 at 22:19
  • 3
    @dangel there's nothing fundamentally wrong with what you say, we should strive to provide something helpful along with a downvote whenever we can. But with 10,000+ questions coming in every day, you can't expect a comment going along with each downvote. It would destroy quality control on the sites.
    – Pekka
    Commented Oct 11, 2015 at 22:54
  • @SpencerWieczorek haha, you got shut down quick
    – nick
    Commented Oct 12, 2015 at 21:06
26

The question is off topic for the following reason, and should soon be closed accordingly:

Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

It would be either that or Too Broad if you interpret the question as asking an answer to provide a solution to do all of what you want from scratch, which it doesn't sound like you are.

10
  • 2
    Yeah, that makes sense. I have done the .pdf and the .txt portions. As I started trying to figure out how to do a power point, I thought I would throw it out there on stack and see if there was library or solution for all of them in one place.
    – Chris
    Commented Oct 9, 2015 at 19:39
  • I disagree. The question deserves killing for being 4 questions in one (which is more than sufficient reason to close it as "Too Broad"). But it doesn't deserve killing for being a "recommendation question", because it isn't. I'm strongly against using the 'off-site resource' close reason in cases where it merely happens to be the case that the solution to the question - according to the best judgement of the close-voter - is likely to involve a third-party library.
    – Mark Amery
    Commented Oct 12, 2015 at 18:37
  • For one thing, often questions that look like they require third-party libraries may not in fact require them. This question is a good example; we don't know what language the OP tagged his question with, but PDF-handling is actually built into some languages, like PHP. I'm not certain there's a trivial solution to any of his problems with only built-in functions, but there may well be.
    – Mark Amery
    Commented Oct 12, 2015 at 18:37
  • Secondly, it means that whether the question is off-topic or not will change as the language evolves; are you going to go back and reopen questions as the functionality being asked for gets added to the language and a library is no longer required? Do you think it's sensible to create a situation in which we may need to do so? Thirdly, it means that the OP can't know with confidence whether their question is on-topic or not before asking it, because whether it's on-topic becomes contingent upon what the answer is, which presumably they don't know, or else they wouldn't be asking.
    – Mark Amery
    Commented Oct 12, 2015 at 18:37
  • And fourthly... it just isn't a recommendation question. It's not asking "which is the best tool for X", it's just asking "how do I do X" where X is a (reasonably) well-defined problem. Even if using a third-party library is the best approach to doing X, good answers will necessarily involve not just a link to a library, but a link to a library plus example code showing how to do X with that library. That seems, to me, like an important distinction between the OP's four questions and the sort of thing "no recommendation questions" is supposed to combat.
    – Mark Amery
    Commented Oct 12, 2015 at 18:38
  • @MarkAmery The question was in fact asking for a tool to do what he wanted, he wasn't asking how to write something to do that from scratch. I also specifically said in my answer that if the question was edited to not be a recommendation, and to just ask how to solve the problem without asking for a product, then it would be Too Broad.
    – Servy
    Commented Oct 12, 2015 at 18:40
  • @Servy the wording of the question doesn't indicate to me that the asker is only interested in answers that use tools or libraries. And it seems patently daft to me to suggest (as I think you are) that a question narrowed down to ask about only one of the four completely different filetypes listed by the OP would still necessarily be "too broad", when we don't know what language the question was tagged with and for all that either of us know there might be a one-line solution for that language/file-type combination without any third-party tools.
    – Mark Amery
    Commented Oct 12, 2015 at 18:46
  • @MarkAmery 1. He didn't quote the entire question. 2. The question isn't asking about a specific file type, and it's also not asking a specific question about how to parse it. "How do I parse this file type?" is indeed too broad. A specific question involving a specific task parsing a specific type of file, including what the OP is doing, why it's not working, or what they can't do, and what they want to do/get, could be sufficiently narrow.
    – Servy
    Commented Oct 12, 2015 at 18:47
  • @Servy ah, I didn't realise you had access to information about the question that I don't - it's not listed in the OP's profile any more, but I infer that it wasn't yet deleted at the time that you answered here? "How do I extract all the text content from a .foo file as a single string?" seems to me like a reasonably well-defined question, though, and that's what the quoted section here is asking - not just "how do I parse a .foo file", which would indeed be worthy of closure as unclear or too broad.
    – Mark Amery
    Commented Oct 12, 2015 at 18:51
  • See Pekaka's answer which goes into detail about tons of questions that arise when attempting to "get the text context" of files types such as those listed. Keep in mind that that's not a comprehensive list. Just defining what the expected output is is much more complex than just saying, "give me all the text content of this file" when that file isn't a text file. You are correct that the question wasn't deleted when this answer was posted, but has since been deleted.
    – Servy
    Commented Oct 12, 2015 at 18:56
13

Thanks for asking this question. Even after several years here, I'm still surprised when one of my posts gets rapidly downvoted.

When people vote down, don't take it to mean "I don't like you" or "I don't like your question". It may be the question was already asked and answered, or it may be that people feel you didn't do enough research to properly ask the question.

I saw a post about a week ago where someone had very clearly copy-pasted 3 questions from their online homework (including the question number), and when downvoted became aggressive and started demanding people help him and insulting the community.

While that's an extreme example, I guess the underlying meaning is that when asking questions, we should be acting as scientists, and avoiding questions that are too self-serving or show a lack of background research.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .