Solved

Opening a PDF web file in VB.net form.

Posted on 2004-03-25
15
52,340 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
[X]
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
  • 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] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Update 21-May-2015: I temporarily removed the source code and the code snippets to make major changes to the program. Regards, Joe INTRODUCTION This Article is a follow-up to the Article entitled How To Rename-Move a Batch of PDF Files Based o…
The Adobe PDF proprietary file format is recognized as secure and formulated. But these PDF files are also prone to corruption and any external threat like virus attacks, improper storage can hit PDF file integrity.This type of damages can make cruc…
We often encounter PDF files that are pure images, that is, they do not have text characters, but instead contain only raster graphics. The most common causes of this are document scanning software and faxing software/services that create image-only…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

636 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