Forum > General

Reading pdf into a TMemo

(1/2) > >>

Nicole:
The online package manager shewed me this when I key in "pdf":
https://wiki.lazarus.freepascal.org/PowerPDF

Unfortunately, the homepage says this:
"The output is a PDF version 1.2 document. PowerPDF is not made for reading existing PDF documents. "

So my question:
How to convert a pdf-file into a TMemo?

dje:
You can't. TMemo's are only for text files.
You would need to:
1) convert PDF to TXT via a comand line tool
2) Find a PDF reader component eg:  https://github.com/dinmil/PDFPreview
3) Open the PDF into an installed reader. eg: Adobe reader or qpdfview (Linux)

paweld:
You can also use the PDFium: https://forum.lazarus.freepascal.org/index.php/topic,58056.msg432524.html#msg432524

Nicole:
Thank you for your answers.

I checked the links and cannot find any READING of pdf, just creating.
Did I miss it?

Yes, I know, that there are command line tools for converting. I want to avoid third party software, - as we are programmers.

Such a command line tool would be e.g. the VERY OLD version of pdf-shaper (if there is no other solution).
I have my reasons to want my own code. One of it is, that the new versions of it, trouble me.
So if anybody has or know an unit for it, it would be great.

wp:
Download pdftotext (from https://www.xpdfreader.com/download.html, "Download the Xpdf tools"). Execute the downloaded exe which simply extracts the contained files, it does not "install" anything to Windows. In the created folder you find the tool pdftotext.exe which you can use by itself, without the other files.

Never used it before, but it seems that this syntax seems to create a filename.txt from filename.pdf (maybe it can be optimized...):

--- Code: ---pdftotext -simple filename.pdf
--- End code ---
In your Lazarus program execute pdf2text by means of the RunCommand procedure (or TProcess for more control - see https://wiki.freepascal.org/Executing_External_Programs#Reading_large_output).

Finally load the output file (filename.txt) into the memo.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var  s: String;begin  RunCommand(Application.Location + 'pdftotext.exe', ['-simple', FilenameEdit1.Filename], s);  Memo1.Lines.LoadFromFile(ChangeFileExt(FileNameEdit1.FileName, '.txt'));end;

Navigation

[0] Message Index

[#] Next page

Go to full version