Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Opening a PDF web file in VB.net form.

Posted on 2004-03-25
15
52,218 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:DaneJurkovic
  • 9
  • 6
15 Comments
 

Author Comment

by:DaneJurkovic
ID: 10679896
UPDATE:

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.PDDoc")

        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...
0
 

Author Comment

by:DaneJurkovic
ID: 10686512
Anyone?
0
 
LVL 2

Expert Comment

by:Psychotext
ID: 10731445
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.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 2

Expert Comment

by:Psychotext
ID: 10732417
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.PDDoc")

        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(strPathArray))
    End Function
0
 

Author Comment

by:DaneJurkovic
ID: 10732567
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.GetFiles(PDFFolderDL)
    Dim DeleteThisFile As String

    For Each DeleteThisFile In DeleteFiles
        System.IO.File.Delete(DeleteThisFile)
    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.PDDoc")

    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??
0
 
LVL 2

Expert Comment

by:Psychotext
ID: 10732649
In this file:

http://www.pdfimage.com/pdf_ps/acroole/AcroOLE.pdf

You have to use the "AcroExch.AVPageView.ZoomTo" method to control the magnification.
0
 
LVL 2

Expert Comment

by:Psychotext
ID: 10732653
Sorry, that should have read "Found in this file:"
0
 

Author Comment

by:DaneJurkovic
ID: 10733136
This is exactly my problem now. I can not figure out how to implement the "AcroExch.AVPageView.ZoomTo" 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.
0
 
LVL 2

Expert Comment

by:Psychotext
ID: 10733226
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)
0
 
LVL 2

Expert Comment

by:Psychotext
ID: 10766485
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.
0
 

Author Comment

by:DaneJurkovic
ID: 10767837
I still can not figure out how to implement the "AcroExch.AVPageView.ZoomTo" method.
0
 
LVL 2

Accepted Solution

by:
Psychotext earned 500 total points
ID: 10770737
Sorted, I coded the entire thing myself because I was interested.  Here is the part of the code that will open the document and zoom.  I assume you can fit this in with your code above (Just need to ?

    Private Sub ViewThisPDF(ByVal ViewThisNow As String)
        Dim AcroExchApp As Object
        Dim AcroExchAVDoc As Object
        Dim AcroExchAVPageView As Acrobat.CAcroAVPageView

        AcroExchApp = CreateObject("AcroExch.App")
        AcroExchAVDoc = CreateObject("AcroExch.AVDoc")

        If (AcroExchAVDoc.Open(ViewThisNow, "Text for window title") = False) Then
            MsgBox("Could not open file")
            Exit Sub
        End If

        AcroExchAVPageView = AcroExchAVDoc.GetAVPageView

        'I have absolutely no idea what the options for the zoom type param are, but 0 works
        AcroExchAVPageView.ZoomTo(0, 200)

        AcroExchApp.Show()
        AcroExchApp.Maximize(100)

        ' Close Acrobat when done
        'AcroExchApp.Exit()

        ' Cleanup the Acrobat objects when done
        'AcroExchApp = Nothing
        'AcroExchAVDoc = Nothing
        'AcroExchPDDocSource = Nothing
    End Sub
0
 
LVL 2

Expert Comment

by:Psychotext
ID: 10770755
Top line should have read: (Just need to replace your sub of the same name).
0
 

Author Comment

by:DaneJurkovic
ID: 10774104
Well done Psychotext!!!
0
 
LVL 2

Expert Comment

by:Psychotext
ID: 10774153
No problem, was a good little challenge.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Outlook 2010 corrupting incoming PDF attachments 23 4,183
Creating a Word Form 3 65
Notification massage in SharePoint 2010 5 71
Adobe Acrobat DC "Out of Memory" 7 453
Can Be Caused By Disabled Services I have encountered a problem viewing PDF files using Adobe Acrobat Reader.  For the longest time, PDFs might launch or might not.  Sometimes they took about 15 minutes to appear after launching them. After som…
One of the questions I get asked again and again is how to validate a field value in an AcroForm with a custom validation script. Adobe provided a lot of infrastructure to do that with just a simple script. Let’s take a look at how to do that wit…
In this video, we show how to perform Bates Numbering/Stamping of PDF documents using Power PDF Advanced, the newest product from the Document Imaging division of Nuance Communications. There are two editions of Power PDF — Standard and Advanced. Th…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question