Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Opening a PDF web file in VB.net form.

Posted on 2004-03-25
15
Medium Priority
?
52,511 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
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 
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 2000 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: 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.

Question has a verified solution.

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

In a previous article published here at Experts Exchange, Signature Image with Transparent Background (http://www.experts-exchange.com/Web_Development/Document_Imaging/A_12380-Signature-Image-with-Transparent-Background.html), I explained how to cre…
This article focuses on how to remove password security from multiple PDF files by Adobe Acrobat program. Sometimes it is essential to access the stored data items and to print, edit as well as copy content from Portable Document Format files in abs…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

773 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