Avatar of Peter Kiers
Peter Kiers
Flag for Netherlands

asked on 

Convert PDF to TXT

Dear Experts,

I have made a little Notepad. And I want the user to be able to open
a PDF-file in my TRichEdit. But just the content of the PDF.
So I have to convert the PDF to TXT.

I found this in the Delphi Knowledgebase:


procedure Tform1.PDF2Text(APDFFileName, ATextFileName: TFileName);
var
  App, AVDoc: Variant;
begin
  //create an instance. if no running instance is found a new one is started
  App := CreateOleObject('AcroExch.App');
  // App.Show;   //only if you want to..
  AVDoc := App.GetActiveDoc; //doc handle
  AVDoc.Open(APDFFileName, ''); //see note below
  //select all and copy to clipboard
  App.MenuItemExecute('Edit');
  App.MenuItemExecute('SelectAll');
  App.MenuItemExecute('Edit');
  App.MenuItemExecute('Copy');
  // Memo1 CAN be set to invisible
  // You need this in order to get it from
  // the clipboard into a text file
  Memo1.PasteFromClipboard;
  // Save the text to a file
  Memo1.Lines.SaveToFile(ATextFileName);
  App.Exit; //unless you want to leave it running.
end;

I don't understand this procedure above and how to
implement it in my Open1Click procedure:

procedure TfrmTextToSpeech.Open1Click(Sender: TObject);
//GOED van EE
var
  sFileName: String;
begin
  if OpenDialog1.Execute then
  begin
    sFileName := OpenDialog1.FileName;
    reText.Lines.LoadFromFile(OpenDialog1.FileName);
    frmTextToSpeech.Caption := ExtractFileName(OpenDialog1.FileName) + ' - ' + 'Text2Speech';
    updateRecent(sFileName);
  end;
end;

Who can help me with this, or perhaps know a better way to do this.

Greetings,

Peter Kiers

Delphi

Avatar of undefined
Last Comment
Peter Kiers

8/22/2022 - Mon