Discussion:
Extracting pdf files from gerneral field
(too old to reply)
d***@msn.com
2007-10-31 04:41:47 UTC
Permalink
I have an application that embeded pdf and paperport documents in
General fields in VFP tables. I can open each individual document by
binding the general field to a olebound control, activate the control
and then save it to disk or print it. However, I have about 20 GB
worth of documents so I can't do them one at a time and so I need to
find a way to programatically extract the documents and save them to
disk and or print them.

Any suggestions?
Roger Ansell
2007-10-31 07:08:03 UTC
Permalink
See if this helps:
http://support.microsoft.com/kb/161832

-Roger
Post by d***@msn.com
I have an application that embeded pdf and paperport documents in
General fields in VFP tables. I can open each individual document by
binding the general field to a olebound control, activate the control
and then save it to disk or print it. However, I have about 20 GB
worth of documents so I can't do them one at a time and so I need to
find a way to programatically extract the documents and save them to
disk and or print them.
Any suggestions?
Roger Ansell
2007-11-01 18:17:20 UTC
Permalink
Further to my previous reply ...

I'm not clear what you mean by "peperport documents" but
extracting PDFs from a General field is fairly straightforward,
with a few important exceptions.

If you use the methodology described in the KB article - IOW
copy each record to a temporary table, you can then peek into
the temp table's FPT file to extract the PDF file.

Unlike the BMP example in the KB article, it's easy to determine
the beginning and end of the PDF file data in the FPT file.
All properly formed PDF files start with "%PDF-" and end with
"%%EOF", so you *could* ...

Load the temp table's FPT into a character variable using
FileToStr();
Use StrExtract() to extract the PDF data into another
character variable;
Then use StrToFile() to create your PDF file.

Main problem with this approach is that if the temp table's
FPT is greater than 16777184 bytes, FileToStr() won't work
as it exceeds VFP's system capacities.

So here's a workaround:
Assume you've created a temporary table (per KB article)
called "pdftest.dbf" ...

<Code>
Create Cursor temp (pdfdata M NoCPTrans)
Select temp
Append Blank
Append Memo pdfdata From pdftest.fpt Overwrite

* Create an empty pdf file
StrToFile("","test.pdf")

lnStartPos = 1
lgStartFile = .F.

Do While .T.
lcChunk = Substr(pdfdata,lnStartPos,CHUNK_SIZE)
If ! lgStartFile
lnFileStartPos = At("%PDF-",lcChunk,1)
If lnFileStartPos > 0
lgStartFile = .T.
lnFileEndPos = At("%%EOF",lcChunk,1)
If lnFileEndPos > 0
lcChunkToWrite = Substr(lcChunk,lnFileStartPos,lnFileEndPos-lnFileStartPos+5)
Else
lcChunkToWrite = Substr(lcChunk,lnFileStartPos)
EndIf
StrToFile(lcChunkToWrite,"test.pdf",1)
EndIf
Else
lnFileEndPos = At("%%EOF",lcChunk)
If lnFileEndPos > 0
lcChunkToWrite = Substr(lcChunk,1,lnFileEndPos + 4)
StrToFile(lcChunkToWrite,"test.pdf",1)
Exit
Else
StrToFile(lcChunk,"test.pdf",1)
EndIf
EndIf
lnStartPos = lnStartPos + CHUNK_SIZE
EndDo
</code>

OK, there are potential problems with this approach.
For example, if your embedded PDF contains PDF sample
data ("%PDF-" or "%%EOF") but that's just one of the
problems of using General fields.

Another problem might occur if the PDFs were appended
to the General field when Acrobat wasn't the default
PDF handler. I noticed this when I had Foxit Reader
installed. If that's the case, bad luck.

-Roger
Allan R. Acuña - NicaFox
2008-01-18 18:06:10 UTC
Permalink
Hi, store the files PDF in any folders, and the DBF Fields path and uses the
API codes to open Files.

See ShellExcecute

Allan
From Nicaragua
Post by d***@msn.com
I have an application that embeded pdf and paperport documents in
General fields in VFP tables. I can open each individual document by
binding the general field to a olebound control, activate the control
and then save it to disk or print it. However, I have about 20 GB
worth of documents so I can't do them one at a time and so I need to
find a way to programatically extract the documents and save them to
disk and or print them.
Any suggestions?
Loading...