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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URL to PDF

Status
Not open for further replies.

DChalom

Programmer
Jun 8, 2002
59
US
How would I go about saving a PDF that a URL points to to a PDF File?
I am looking for a funtion that I send it the URL of a PDF file and the file name I want ity saved to. i.e.,
pURL2PDF(pURL, pPDF)

 


How would I go about saving a PDF that a URL points to to a PDF File?

Can you rephrase that? Do you mean copy a PDF from one place to another, picking up the path from a URL? Is this a FoxPro question?


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
OK...I am processing a bunch of emails.
The emails have links to PDF files.
I want to be able to take the URL of the link and save the refernced PDF file to a file on my hard drive.
Yes I want to do this in VFP.

 
The emails have links to PDF files.
I want to be able to take the URL of the link and save the refernced PDF file to a file on my hard drive.

FAQ184-2838


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
your link of FAQ184-2838 returns an invalid page.....

 

I'm not sure why but here is the text:
Code:
How to retrieve attachments from e-mails via Automation 
faq184-2838 

The following code will detect if there are any attachments, in an e-mail and save it to a directory.


Local lcFilename,lcPath
lcPath="c:\savedattachments\"
If  !Directory("c:\savedAttachments")
    Md "c:\savedAttachments" && Create the directory if it doesn't exist.
Endif
oOutLookObject = Createobject("Outlook.Application")
olNameSpace = oOutLookObject.GetNameSpace("MAPI")
myAtts=olNameSpace.GetDefaultFolder(6).Items
For Each loItem In myAtts
    If loItem.attachments.Count >0 && Make sure there is an actual attachment.
        For i = 1 To loItem.attachments.Count
            lcFilename=""
            lcFilename = loItem.attachments.Item(i).filename
            lcFilename = Alltrim(lcPath)+lcFilename
            loItem.attachments.Item(i).SaveAsFile(lcFilename)
           *loItem.Delete() && The option to delete the message once the attachment has been saved.
        Next
    Endif
Next




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
I can do that...the thing is my attachments are not attachments but rather html links to pdf documents. And I need to beable to save those PDF documents as files to a given folder.

I hope you understand and can help me....

 
I can do that...the thing is my attachments are not attachments but rather html links to pdf documents. And I need to beable to save those PDF documents as files to a given folder.

Are these PDF on an internal serveur or an FTP server?


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Actually on an external server. But none the less a server.

 

One suggestion might be to use FILETOSTR() on the e-mail message, locate the URL (most likely the pattern has "\\"), store the filename to a variable and use the COPY TO function, if you have direct access to the server.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
But again i would like to keep it as a PDF file....l
 
But again i would like to keep it as a PDF file....l

Sorry I meant COPY command. In VFP you can copy a file of any format to another folder without changing the format.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Thank you for all your help on this...I will test this out later and let you know.



Dorian C. Chalom
 
I did get a solution that works...

*- start code
ox = CREATEOBJECT("_wDownloadPDF")
ox.DownloadPdf("

DEFINE CLASS _wDownloadPDF AS RELATION
oHTTP = NULL

*-------------------------
PROCEDURE CreateHTTPClient
*-------------------------
*- Returns an handle to the http class.
THIS.oHTTP = CREATEOBJECT("wwHTTP")
THIS.oHTTP.nConnectTimeout = 10
RETURN THIS.oHTTP
ENDPROC

*-----------------------
PROCEDURE DownloadPDF
*-----------------------
*- Downloads the update file from the website
*- Returns .T. or .F. succes or failure
LPARAMETERS tcPdfUrl

LOCAL lcData, lnSize, loUrl, llReturn

llReturn = .T.

*- Check if the update is not already downloaded

WITH This
IF ISNULL(.oHTTP)
.CreateHTTPClient()
ENDIF

*- Break down the URL into its components
loUrl = .oHTTP.InternetCrackUrl(tcPdfUrl)

IF !ISNULL(loUrl)
*- Continue
IF .oHTTP.HTTPConnect(loUrl.cServer,"","",IIF(lower(loUrl.cProtocol)="https",.T.,.F.)) = 0
*- Connection succesfull continue


lcTFile = "c:\" + JUSTFNAME(STRTRAN(tcPdfUrl,"/","\"))
lcData = ""
lnSize = 0

IF .oHTTP.HTTPGetEx( TRIM(loUrl.cPath),@lcData,@lnSize,,lcTFile) = 0
*- Download successfull

ELSE
.SetError(.oHttp.cErrorMsg)
llReturn = .F.
ENDIF
ELSE
.SetError(.oHTTP.cErrorMsg)
llReturn = .F.
ENDIF
*- Close the connection
.oHTTP.HTTPClose()
ELSE
llReturn = .F.
ENDIF
ENDWITH

RETURN llReturn
ENDPROC

************************************************************************
* WCONNECT Header File
**********************
*** Author: Rick Strahl
*** (c) West Wind Technologies, 1995-2002
*** Contact: *** Function: Global DEFINEs used by West Wind Web Connection.
***
*** IMPORTANT: Any changes made here or in WCONNECT_OVERRIDE.H
*** require a full recompile of all files that use
*** this header file!
************************************************************************

And the Rick Strahl code continues....

If you have another solution I would love to see it.
If you would like the complete solution let me know.....


Dorian C. Chalom
 
Yes but does that read in pdf and save them as pdf's?

Dorian C. Chalom
 
It will read whatever is at that url, and return it as a string (or, if you provide the SaveToFile parameter, it will stor it directly into a file: VFP has a 16MB limit on the length of a string).

PDF's are just binary files, like every other file on your computer. Save it with a filename with a .PDF extension, and you'll have a PDF.
 
Use it like:

Code:
lcPdfUrl = "[URL unfurl="true"]http://www.myserver.com/MyDoc.pdf"[/URL]

lcPdfData = ReadUrl( lcPdfUrl )
if not isnull(lcPdfData) and vartype(lcPdfData)='C'
  * Success! Write to a local file:
  StrToFile(lcPdfData,'C:\MyPath\MyPDFFile.PDF')
endif

* OR:

llResult = ReadUrl(lcPdfUrl, .f.,.f., 'C:\MyPath\MyPDFFile.PDF')
if not isnull(llResult) and vartype(llResult)='L' and llResult
  * Success!!
ENDIF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top