Results 1 to 4 of 4

Thread: Auto printing PDF files

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Location
    Southeast Michigan
    Posts
    155

    Auto printing PDF files

    Is there a way to print PDF files within the .NET framework? I'd like to set up a directory to monitor and when files are copied there, the program prints the PDF file and deletes it. I just don't know how to handle the printing without using Adobe.

    Thanks in advance for you help.
    Dave

    Helpful information I've found here so far : The Definitive "Passing Data Between Forms" : Restrict TextBox to only certain characters, numeric or symbolic :
    .NET Regex Syntax (scripting) : .NET Regex Language Element : .NET Regex Class : Regular-Expressions.info
    Stuff I've learned here so far : Bing and Google are your friend. Trying to help others solve their problems is a great learning experience

  2. #2
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Auto printing PDF files

    To programatically print PDF's you are pretty much stuck to using a 3rd party product, such as Adobe Reader. PDF-Xchange & Foxit also allow printing from the command line if you dont like Adobe, but with any of them you need to have the product installed on the machine that will be doing the printing.

  3. #3
    Junior Member
    Join Date
    Jun 2010
    Posts
    28

    Re: Auto printing PDF files

    This should work for you. Use this to call
    VB Code:
    1. Try
    2.             Print.PrintPDF("C:\mypdffile.pdf")
    3.         Catch ex As Exception
    4.             MessageBox.Show(ex.Message)
    5.         End Try

    This

    VB Code:
    1. Imports System.IO
    2. Imports System.Runtime.InteropServices
    3.  
    4. Public Class Print
    5.     Private Const SW_SHOWNORMAL As Integer = 2
    6.     <DllImport("shell32")> _
    7.     Private Shared Function ShellExecute(ByVal hWnd As IntPtr, _
    8.                                         ByVal lpOperation As String, _
    9.                                         ByVal lpFile As String, _
    10.                                         ByVal lpParameters As String, _
    11.                                         ByVal lpDirectory As String, _
    12.                                         ByVal nShowCmd As Integer) As IntPtr
    13.     End Function
    14.  
    15.     Public Shared Sub PrintPDF(ByVal FilePath As String)
    16.         If IO.File.Exists(FilePath) Then
    17.             If ShellExecute(CType(1, IntPtr), "Print", FilePath, "", _
    18.             Directory.GetDirectoryRoot(FilePath), SW_SHOWNORMAL).ToInt32 <= 32 Then
    19.                 Throw New Exception("Error: The file did not print.")
    20.             End If
    21.         Else
    22.             Throw New Exception("Error: The file does not exist.")
    23.         End If
    24.     End Sub
    25. End Class

    After reading nbrege's post I am wondering if I misunderstood the original request. Are you trying to do this without having Adobe (or equivalent) installed on the client machines?
    Last edited by Elfish; Sep 9th, 2010 at 12:06 PM.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2010
    Location
    Southeast Michigan
    Posts
    155

    Re: Auto printing PDF files

    Actually I was asking if it could be done without Adobe, or third party software, installed.

    If I have to use third party software then Adobe is fine. Can I handle errors in the background? We have an older VB6 program that is used currently and it runs into problems if there is anything wrong with the PDF file. An Abobe message pops up waiting for user to respond and the program stops functioning.
    Dave

    Helpful information I've found here so far : The Definitive "Passing Data Between Forms" : Restrict TextBox to only certain characters, numeric or symbolic :
    .NET Regex Syntax (scripting) : .NET Regex Language Element : .NET Regex Class : Regular-Expressions.info
    Stuff I've learned here so far : Bing and Google are your friend. Trying to help others solve their problems is a great learning experience

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width