Extract text from PDF lazarus / 31-LCL ---------------------------------------------------------------------- wittbo · 2020-09-17 15:51 I'm looking for a component (if there is one), which allows to extract all text from a given PDF. It should load the PDF from file and extract the pure text into a stringlist. I know, there were one or two threads towards this direction nearly 8 years ago. Recently I saw something about fpPDF or fPDF; but I imagine, that these component(s) generate a PDF, not the reverse way. Does anyone have some experience with this topic? Or some hints where to look for more information? ---------------------------------------------------------------------- af0815 · 2020-09-17 17:46 PDF can hold text in varios form. maybe as picture. so it is very complex. i did not found any component for this. last time i used OCR for converting, because my PDF encapsulate text as a picture. ---------------------------------------------------------------------- wittbo · 2020-09-17 19:47 OK, thanks for the objection. For my purpose it would be enough to limit myself to the PDFs with real text, no OCR. ---------------------------------------------------------------------- af0815 · 2020-09-17 20:03 You can use some commanlinetool with TProcess to do some conversion -> see pdftotext and poppler-utils https://www.linuxuprising.com/2019/05/how-to-convert-pdf-to-text-on- linux-gui.html i have seen this utils can work with simpler pdf, if the text is not grapical embedded ---------------------------------------------------------------------- rvk · 2020-09-17 20:07 There are pdf2text solutions but you would need to call some executable from your program. Other option could be to print the pdf automatically to a text printer and catch the output in file (which can be done in code)  (But for that a text-printer driver should be present.) You could use the txtwrite-device from Ghostscript. (for this you would need to supply a version of ghostscript, installed or portable). Last option would be to decipher the pdf (which are streams) yourself. Other topics: https://forum.lazarus.freepascal.org/index.php?topic=46859.0 https://www.lazarusforum.de/viewtopic.php?t=2659 https://stackoverflow.com/questions/3650957/how-to-extract-text-from- a-pdf ---------------------------------------------------------------------- trev · 2020-09-18 00:09 Quote from: af0815 on September 17, 2020, 10:03:38 pmYou can use some commanlinetool with TProcess to do some conversion -> see pdftotext and poppler-utils I've used pdftotext and pdftohtml on a massive scale to convert fairly complex legislation very successfully unless there were any images (eg for mathematical formulae) which then required manual intervention. ---------------------------------------------------------------------- wittbo · 2020-09-19 14:53 That sounds interesting. Does anyone know the price of pdf2text or is it free for private use? ---------------------------------------------------------------------- winni · 2020-09-19 15:01 Hi! pdf2text and his friends are open source. They come with nearly all Linux distros. Have a look at https://poppler.freedesktop.org/ Winni ---------------------------------------------------------------------- rvk · 2020-09-19 15:05 Quote from: wittbo on September 19, 2020, 04:53:25 pmThat sounds interesting. Does anyone know the price of pdf2text or is it free for private use? It depends. You are on Mac? Is it standard installed on Mac (like it is often on Linux)? https://en.m.wikipedia.org/wiki/Pdftotext There are also lots of other versions floating around. You would need to look at the licenses to see if it's freely usable. Calling a GPL program as executable from your closed sourced program is usually allowed. Calling a GPL library from your closed sourced program usually not. But that could spark a while different license discussion ---------------------------------------------------------------------- wittbo · 2020-09-19 21:39 Thanks to all for your help. @rvk: yes, I'm on mac. When looking for pdftotext for macOS I found the site of Carsten Bluem (https://www.bluem.net/files/pdftotext.dmg), who extracted the pdftotext command line tool as a part of the "Xpdf" software (http://www.xpdfreader.com) with easy to use package installation. So, no license problem, it's open source. ---------------------------------------------------------------------- rvk · 2020-09-20 19:21 Quote from: wittbo on September 19, 2020, 11:39:09 pmSo, no license problem, it's open source. Open source doesn't necessarily mean no problem. Xpdf is licensed under GPL v2 and GPL v3. http://www.xpdfreader.com/opensource.html You can't dynamic link (dll, .so etc.) to it without open sourcing your own software. You can install it separately and call the executable and keep your own software closed source. But even with open source you always need to examine the licence if you want to keep your software closed source. (With calling the executable you are 'safe' in this case.) ---------------------------------------------------------------------- trev · 2020-09-21 01:02 Quote from: rvk on September 20, 2020, 09:21:20 pmXpdf is licensed under GPL v2 and GPL v3. http://www.xpdfreader.com/opensource.html Better link: https://www.glyphandcog.com/opensource.html according to my man pages (FreeBSD and Solaris). ---------------------------------------------------------------------- LacaK · 2025-04-12 09:40 I was also looking for a way to extract text from PDF documents and found the open-source library pdfium. I made pascal headers for it https://lacak.sourceforge.io/freepascal.html#pdfium (there is also TFPDFDocument class which encapsulates some library calls) ---------------------------------------------------------------------- Jurassic Pork · 2025-04-13 00:26 Hello, have a look to these links : https://forum.lazarus.freepascal.org/index.php/topic,58056.msg432524.h tml#msg432524 https://github.com/grahamegrieve/PdfiumLib/tree/master https://github.com/ahausladen/PdfiumLib/tree/master https://github.com/bblanchon/pdfium- binaries/releases/tag/chromium%2F7113 with that you can make a great PDF Reader Viewer  Text Extractor working with the last PDFium Release. See attachments ( Lazarus 2.2.6 Windows 11, PDFium 137 -> paweId project with ahausladen files with last pdfium.dll ) PDFium binaries exists for linux and mac . To see if the project can be modify to work with all O.S. Friendly, J.P ---------------------------------------------------------------------- d2010 · 2025-04-15 13:18 Quote from: wittbo on September 17, 2020, 05:51:20 pmDoes anyone have some experience with this topic? Or some hints where to look for more information? I have same experienced, but.. Can  you upload here a Demo.pdf . Please with  PDf +tables+graphics+wav+mp3.? Please,please a few quite demo/s./pdf, for comparisson the results.