DaneJurkovic
asked on
Opening a PDF web file in VB.net form.
Hello Everyone,
Here is my problem. I would like to check if a PDF file exists in a website. Then if it does to send that PDF file to my default printer. I am writing all the code in VB.net. This is what I have so far.
Public Function PdfCheck()
Dim URL As String = "http://www.vecernjilist.hr/ARHIVA/2004/03/25/040325-11.pdf"
Dim PDFDoc As Acrobat.CAcroPDDoc
Try
PDFDoc.Open(URL)
Catch e As Exception
MessageBox.Show(e.Message)
End Try
‘Add printing code here..
PDFDoc.Close()
End Function
Now my problem is that the “PDFDoc.Open(URL)” line is for opening a file on the local computer. What is the syntax for open a PDF from the web?
If anyone has ever done something like this and may give me some code I can use, I will increase points
Here is my problem. I would like to check if a PDF file exists in a website. Then if it does to send that PDF file to my default printer. I am writing all the code in VB.net. This is what I have so far.
Public Function PdfCheck()
Dim URL As String = "http://www.vecernjilist.hr/ARHIVA/2004/03/25/040325-11.pdf"
Dim PDFDoc As Acrobat.CAcroPDDoc
Try
PDFDoc.Open(URL)
Catch e As Exception
MessageBox.Show(e.Message)
End Try
‘Add printing code here..
PDFDoc.Close()
End Function
Now my problem is that the “PDFDoc.Open(URL)” line is for opening a file on the local computer. What is the syntax for open a PDF from the web?
If anyone has ever done something like this and may give me some code I can use, I will increase points
ASKER
Anyone?
I think the best way of doing it in this case is to buffer the pdf to your local machine / server and then send the buffer to Acrobat. I'm not sure of the code right now, but i'll have a look.
By the way, this assumes that there isn't a method for using a remote file! I really dont know but this will help if there isn't.
By the way, this assumes that there isn't a method for using a remote file! I really dont know but this will help if there isn't.
Try this... it's not the best code in the world, but it should work. You'll need to give ASPNET write access to where you want the file (In this case the dir that the aspx file is in.). You can do the same with buffering to avoid saving the file. It still seems unlikely that the adobe object can't access urls though.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strURL As String = "http://www.adobe.com/products/acrobat/pdfs/docsforms.pdf"
PdfCheck(strURL)
End Sub
Sub PdfCheck(ByVal strURL As String)
Dim AcroApp As Acrobat.CAcroApp
Dim PDDoc As Acrobat.CAcroPDDoc
Dim avDoc As Acrobat.CAcroAVDoc
Dim wc As New WebClient()
Dim strLocalName As String = Server.MapPath(".") & "\" & GetFileName(strURL)
wc.DownloadFile(strURL, strLocalName)
AcroApp = CreateObject("AcroExch.App ")
PDDoc = CreateObject("AcroExch.PDD oc")
If PDDoc.Open(strLocalName) Then
AcroApp.Show()
avDoc = PDDoc.OpenAVDoc("")
Else
MsgBox("Unable to open the PDF-file", vbInformation)
End If
avDoc = Nothing
PDDoc = Nothing
AcroApp = Nothing
End Sub
Function GetFileName(ByVal URL As String) As String
Dim strPathArray() = Split(URL, "/")
GetFileName = strPathArray(UBound(strPat hArray))
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strURL As String = "http://www.adobe.com/products/acrobat/pdfs/docsforms.pdf"
PdfCheck(strURL)
End Sub
Sub PdfCheck(ByVal strURL As String)
Dim AcroApp As Acrobat.CAcroApp
Dim PDDoc As Acrobat.CAcroPDDoc
Dim avDoc As Acrobat.CAcroAVDoc
Dim wc As New WebClient()
Dim strLocalName As String = Server.MapPath(".") & "\" & GetFileName(strURL)
wc.DownloadFile(strURL, strLocalName)
AcroApp = CreateObject("AcroExch.App
PDDoc = CreateObject("AcroExch.PDD
If PDDoc.Open(strLocalName) Then
AcroApp.Show()
avDoc = PDDoc.OpenAVDoc("")
Else
MsgBox("Unable to open the PDF-file", vbInformation)
End If
avDoc = Nothing
PDDoc = Nothing
AcroApp = Nothing
End Sub
Function GetFileName(ByVal URL As String) As String
Dim strPathArray() = Split(URL, "/")
GetFileName = strPathArray(UBound(strPat
End Function
ASKER
Psychotext,
You just about have what I got so far. Good work!!! This is my code so far......
Private Sub cmdGetPdf_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdScanDL.Click
Dim ThisURL As String = "http://www.adobe.com/products/acrobat/pdfs/docsforms.pdf"
Dim PDFFolder As String = "c:\TempPDF\"
Dim LocalPdfSave As String = PDFFolder & "LocalPdf.pdf"
Dim DeleteFiles() As String = System.IO.Directory.GetFil es(PDFFold erDL)
Dim DeleteThisFile As String
For Each DeleteThisFile In DeleteFiles
System.IO.File.Delete(Dele teThisFile )
Next
If PdfCheck(ThisURL, LocalPdfSave) Then
MessageBox.Show("Done Importing PDF Files", "Import", MessageBoxButtons.OK, MessageBoxIcon.Information )
ViewThisPDF(LocalPdfSave)
Else
MessageBox.Show("Error in Importing PDF files!!!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Public Function PdfCheck(ByVal URL As String, ByVal localPdfFile As String) As Boolean
Dim wc As New WebClient
Dim LocalError As Boolean = True
Try
wc.DownloadFile(URL, localPdfFile)
Catch e As Exception
LocalError = False
End Try
Return LocalError
End Function
Private Sub ViewThisPDF(ByVal ViewThisNow As String)
Dim AcroApp As Acrobat.CAcroApp
Dim PDDoc As Acrobat.CAcroPDDoc
Dim avDoc As Acrobat.CAcroAVDoc
AcroApp = CreateObject("AcroExch.App ")
PDDoc = CreateObject("AcroExch.PDD oc")
If PDDoc.Open(ViewPDFNow) Then
'PDDoc.Magnification(200)
AcroApp.Show()
AcroApp.Maximize(100)
avDoc = PDDoc.OpenAVDoc("")
Else
MsgBox("Unable to open the PDF file", vbInformation)
End If
avDoc = Nothing
PDDoc = Nothing
AcroApp = Nothing
End Sub
What I am trying to figure out now is setting the magnification (zoom) to "200%". Any thoughts??
You just about have what I got so far. Good work!!! This is my code so far......
Private Sub cmdGetPdf_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdScanDL.Click
Dim ThisURL As String = "http://www.adobe.com/products/acrobat/pdfs/docsforms.pdf"
Dim PDFFolder As String = "c:\TempPDF\"
Dim LocalPdfSave As String = PDFFolder & "LocalPdf.pdf"
Dim DeleteFiles() As String = System.IO.Directory.GetFil
Dim DeleteThisFile As String
For Each DeleteThisFile In DeleteFiles
System.IO.File.Delete(Dele
Next
If PdfCheck(ThisURL, LocalPdfSave) Then
MessageBox.Show("Done Importing PDF Files", "Import", MessageBoxButtons.OK, MessageBoxIcon.Information
ViewThisPDF(LocalPdfSave)
Else
MessageBox.Show("Error in Importing PDF files!!!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Public Function PdfCheck(ByVal URL As String, ByVal localPdfFile As String) As Boolean
Dim wc As New WebClient
Dim LocalError As Boolean = True
Try
wc.DownloadFile(URL, localPdfFile)
Catch e As Exception
LocalError = False
End Try
Return LocalError
End Function
Private Sub ViewThisPDF(ByVal ViewThisNow As String)
Dim AcroApp As Acrobat.CAcroApp
Dim PDDoc As Acrobat.CAcroPDDoc
Dim avDoc As Acrobat.CAcroAVDoc
AcroApp = CreateObject("AcroExch.App
PDDoc = CreateObject("AcroExch.PDD
If PDDoc.Open(ViewPDFNow) Then
'PDDoc.Magnification(200)
AcroApp.Show()
AcroApp.Maximize(100)
avDoc = PDDoc.OpenAVDoc("")
Else
MsgBox("Unable to open the PDF file", vbInformation)
End If
avDoc = Nothing
PDDoc = Nothing
AcroApp = Nothing
End Sub
What I am trying to figure out now is setting the magnification (zoom) to "200%". Any thoughts??
In this file:
http://www.pdfimage.com/pdf_ps/acroole/AcroOLE.pdf
You have to use the "AcroExch.AVPageView.ZoomT o" method to control the magnification.
http://www.pdfimage.com/pdf_ps/acroole/AcroOLE.pdf
You have to use the "AcroExch.AVPageView.ZoomT
Sorry, that should have read "Found in this file:"
ASKER
This is exactly my problem now. I can not figure out how to implement the "AcroExch.AVPageView.ZoomT o" method in my code (from above) to control the magnification of the page after it opens. Mine you this is not a web app, this is all windows forms.
The link you sent had this in it for the “ZoomTo” method.
ZoomTo
BOOL ZoomTo(short nType, short nScale);
Description: Zooms to a specified magnification.
Parameters: nType
Zoom type
nScale
The desired zoom factor
Return Value: true or false
Many thanks for your help so far. You’re doing great!!! In helping me.
The link you sent had this in it for the “ZoomTo” method.
ZoomTo
BOOL ZoomTo(short nType, short nScale);
Description: Zooms to a specified magnification.
Parameters: nType
Zoom type
nScale
The desired zoom factor
Return Value: true or false
Many thanks for your help so far. You’re doing great!!! In helping me.
Sorry, I dont think I'm going to be able to help on this bit because I dont have the right components. My assumption would be that you have to instantiate the AcroExch.AVPageView object and then use the ZoomTo method on it. (Much as you have with the PDDoc)
Do you still need assistance on this question? I think your original question has been answered, but if you need any more help, just post.
ASKER
I still can not figure out how to implement the "AcroExch.AVPageView.ZoomT o" method.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Top line should have read: (Just need to replace your sub of the same name).
ASKER
Well done Psychotext!!!
No problem, was a good little challenge.
ASKER
This works...
Sub PdfCheck(ByVal URL As String)
Dim AcroApp As Acrobat.CAcroApp
Dim PDDoc As Acrobat.CAcroPDDoc
Dim avDoc As Acrobat.CAcroAVDoc
AcroApp = CreateObject("AcroExch.App
PDDoc = CreateObject("AcroExch.PDD
If PDDoc.Open(URL) Then
AcroApp.Show()
avDoc = PDDoc.OpenAVDoc("")
Else
MsgBox("Unable to open the PDF-file", vbInformation)
End If
avDoc = Nothing
PDDoc = Nothing
AcroApp = Nothing
End Sub
But, only for a "local" file on the computer. i am looking for a way to open up a PDF from the web.
Thanks...