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

vb.net pdf printing

Status
Not open for further replies.

ChainsawJoe

Programmer
Dec 5, 2000
154
GB
Hi all!

I have this function which prints txt files just peachily
Code:
Sub PrintAdobePDF(ByVal Filename As String)
  Dim myProcess As New Process
  Dim i As Integer = 1
  Dim lbRunning As Boolean = True

  Try
      myProcess.StartInfo.FileName = Filename
      myProcess.StartInfo.WorkingDirectory = New FileInfo(Filename).DirectoryName
      myProcess.StartInfo.CreateNoWindow = True
      myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
      myProcess.StartInfo.Verb = "print"
      myProcess.Start()

      If Not myProcess.HasExited Then
         myProcess.WaitForInputIdle(10000)
         While lbRunning And i <= 20
             System.Threading.Thread.Sleep(500)

               Select Case myProcess.HasExited
                  Case True
                      lbRunning = False
                  Case False
                      lbRunning = Not myProcess.CloseMainWindow
              End Select

              i += 1
          End While
        End If

       If lbRunning AndAlso Not myProcess.HasExited Then myProcess.Kill()
       myProcess.Dispose()

   Catch ex As System.ComponentModel.Win32Exception
        Const ERROR_FILE_NOT_FOUND As Integer = 2

        Select Case ex.NativeErrorCode
           Case ERROR_FILE_NOT_FOUND : Throw New System.IO.FileNotFoundException
           Case Else : Throw New Exception(ex.Message & " (PrintAdobePDF)")
        End Select
    Catch ex As Exception
        Throw New Exception(ex.Message & " (PrintAdobeFile)")
   End Try
but just try and give it a pdf and you'll find Acrobat reader hiding in your running processes, not doing a whole lot.

I've tried loads of different versions of this, down to the basics:
Code:
  Dim starter As Process = New Process
  Dim acroPath As String = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe"

  starter.Start(acroPath, "/p/h """ & Server.MapPath("testprint.pdf") & """")

I can get the commandline version to work:
Code:
"C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe" /p/h "c:\testprint.pdf"
but it still sits around in my running processes - I guess if I could get that to work in .net, then i could probably kill the process as well... hmm..

Can anyone help? Here's what I actually want to do:
within one page I'm using dynamicpdf to create a label with a couple of barcodes on it via a web app, and need to send several labels to a label printer sitting next to each user of the app.

So presumably the commandline version might not work unless I manage to specify a network printer on a "per user" basis to define where to print to?

I've scoured google and the previous posts here and can't seem to get any of the suggestions to work - can anyone point me towards anything that might help? Even third party solutions would be appreciated - time is, as always, of the essence!

Many thanks!
 
Can you try this code...You need to kill the Adobe process after finishing the print job.
You can have a look at this also, which may help you to some extent.
Code:
Dim psi As New ProcessStartInfo
psi.UseShellExecute = True
psi.Verb = "print"
psi.WindowStyle = ProcessWindowStyle.Hidden
psi.FileName = fileName
Process.Start(psi)

Sharing the best from my side...

--Prashant--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top