3 ms·
Is there an easy way to do the opposite? e.g. read PDFs as HTML (intended to be read through a remote shell), or text?
by pizza 10y ago
Is there an easy way to do the opposite? e.g. read PDFs as HTML (intended to be read through a remote shell), or text?
- jevinskie 10y agoYou might be able to tweak this pdf.js example to dump out its canvas element after it renders. https://github.com/mozilla/pdf.js/blob/master/examples/learning/helloworld64.html https://github.com/mozilla/pdf.js/blob/master/examples/learn...
- kccqzy 10y agoExtracting text from PDF is not hard, though PDF only contains low-level formatting instructions so the result might not be nice, especially if the original PDF has any non-trivial formatting, like pull quotes, multi-column text, etc. If you don't care about that or the correct "flow" of text, it should be easy enough to just find all the Tj and TJ operators and extract their operands. You might also need to reverse some ligatures though. Producing nice semantic HTML is much harder, though also easy if you don't mind every word in a separate absolutely positioned div. Many PDF reader software already contains empirically tuned routines to infer the text flow and generate text files (because the software needs to handle Select All and Copy), but they often produce bad results. But if you just want to read a PDF on a remote machine over ssh, the easiest solution might be just transferring the file and then opening it locally, or use X forwarding and open the PDF with a graphic reader.
- desdiv 10y agoI'm in the same boat. You might want to check these out: http://coolwanglu.github.io/pdf2htmlEX/ http://coolwanglu.github.io/pdf2htmlEX/ https://github.com/JonathanLink/PDFLayoutTextStripper https://github.com/JonathanLink/PDFLayoutTextStripper http://tabula.technology/ http://tabula.technology/ https://docparser.com https://docparser.com
- ufmace 10y agoEasy, not so much, depending on exactly what you want to get out of it. I did a project with this once https://www.idrsolutions.com/jpdf2html5/ https://www.idrsolutions.com/jpdf2html5/. Last I checked, they only supported it as a Java library that could generate rather nice looking and complete HTML pages from PDF documents. The output was great, but it was kinda pricey and difficult to work with. On the opposite side of the complexity level, I have also used this http://www.pdfsharp.com/PDFsharp/ http://www.pdfsharp.com/PDFsharp/ to extract bits of text from PDFs. It's free, but you only get access to the raw PDF text with formatting codes. It works fine if you just want to grab a short string, but you got your work cut out for you if you want to do anything more sophisticated.