Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting Text

Status
Not open for further replies.

Opieo

Programmer
Jul 26, 2006
454
GB
Ok guys, I have looked far and wide for something to do something like this, but with no luck.
I need to be able to extract certain texts out of PDFs.
I found a certain type of function that basically opens Adobe with the selected file (I will be doing batches at once, but I can easily set that up). It then reads the text in from Adobe into a RichEdit (used for searching for the text). My problem is that I am not sure this solution would work anymore, as for the latest 3 sets of contracts we have received now have permission restrictions on them for no good reason. We have been receiving them for years without them, and now they are restricted. The code that I was able to find does this to take the text from PDF and put it into a RichEdit:

var
App, AVDoc : Variant;

begin
App := CreateOleObject ('AcroRd32.Application');
AVDoc := App.GetActiveDoc;
AVDoc.Open (APDFFileName,'');
App.MenuItemExecute('Edit');
App.MenuItemExecute('SelectAll');
App.MenuItemExecute('Edit');
App.MenuItemExecute('Copy');
pdfer.PasteFromClipboard;
end;

I believe this will not work because it still uses Adobe to open the file, and would probably prevent the Copy command from working (I tested manually copying out of the PDF and it is restricted, as it says so in the Security settings).

So I suppose I kind of have 2 questions.
As is, that code is not working at all. I figured out the adding ComObj to the uses for Delphi to understand the CreateOLEObject part. But that line is still giving me an error. It says "Invalid Class String". I have tried changing the name of the application around to a few things, but so far have not fixed it (I think that is where the problem is?).

The second question is, does anyone have any small amount of code that can go through and remove permission restrictions on PDFs? This would solve my problem about not being able to copy from the PDFs that are our contracts anyways. Right now we can only open and print them (which is a huge waste of paper and time since we only need a small amount of info from them).

~
Give a man some fire, he will be warm for a day, Set a man on fire, he will be warm for the rest of his life.
 
No, I got hung up and went back to my primary project.
My mini test program is there but still at this nicely stopped position where I have the same problems mentioned in the previous post.

~
Give a man some fire, he will be warm for a day, Set a man on fire, he will be warm for the rest of his life.
 
I had problems with Acrobat Reader version 8. But this works for versions 7 and below:

Follow the instructions described in:

Now create a new form. Drop a TPanel on it and set the Align property to alBottom. Drop a TButton on Panel1.

Go to the ActiveX palette and drop a TAcroPDF on the form (not Panel1). Set its Align property to alClient.

Now double-click your Button. In the resulting TForm1.Button1Click event type AcroPDF1.src:= 'C:\Delphi7\Demos\IntraWeb\Features\Files\Cover Page.pdf';
(or a full path string to a known PDF file on your system.)

Run the application, click the button and VIOLA!

Once you get it working, add a TOpenDialog and change the hardcode PDF filename to OpenDialog.FileName. (and the button event to OpenDialog.execute)

It worked for me. Now, to figure out what's up with version 8...

Roo
Delphi Rules!
 
Yah, the computers here all have v8.
It still tells me it makes the TAcroPDF, I get that far.
But I can never find the component anywhere.
I tried adding it to one of the component palettes manually and it still did not show up.
Stupid PDFs .....

~
Give a man some fire, he will be warm for a day, Set a man on fire, he will be warm for the rest of his life.
 
Okay, nvm, I have the component now.
Just created my own Package with the component in it.
Then installed the package itself.
I now have the TAcroPDF.
Perhaps I will pick up this little project again with your directions there.

~
Give a man some fire, he will be warm for a day, Set a man on fire, he will be warm for the rest of his life.
 
erp, wish I could edit the previous post.
Forgot to say, Thank You =)

~
Give a man some fire, he will be warm for a day, Set a man on fire, he will be warm for the rest of his life.
 
Okay, I got everything working out how you suggested.
It still doesn't really solve my problem though.
I do not want to just run acrobat inside of my form.
Its neat and all, but not my current goal.
I wanted to import the text from it (they are always text only) and then search through the text for what I need.
I found a different walkthrough than the one above.
It can be found here

I got it all set up, imported the Type Library for Acrobat_TLB, got that working.
Imported all the code and I am still getting my [red]Invalid Class String[/red] error.
Again it is right at the [green]CreateOLEObject[/green] line.
now: [blue]acrobat := CreateOleObject('AcroExch.pdDoc');[/blue]
Something I am doing doesn't want to make an OLE object.
I have [green]ComObj[/green] in the uses so I am still at a loss.

~
Give a man some fire, he will be warm for a day, Set a man on fire, he will be warm for the rest of his life.
 
try to insert this line before the
"acrobat := CreateOleObject('AcroExch.pdDoc');" line

AcroApp := CreateOleObject('AcroExch.App');

define AcroApp as Variant;

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Daddy, now it just gives me an [red]Invalid Class String[/red] error at the first [green]CreateOleObject[/green] line.
I think I read somewhere that it could have something to do with a DLL not being properly registered. That is a whole can of worms I have no idea which one it would ever be - IF that is it.

~
Give a man some fire, he will be warm for a day, Set a man on fire, he will be warm for the rest of his life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top