none
Please help a beginner.

    Question

  • Hello, i'm a beginner in vb.net, i would like to ask you guys on how do i print an external pdf file.
    the process i would like to do is:

    1: click a button
    2: opens a print view window where i can see my options for printing the file. Ex: select printer or default one,paper size, orientation, etc.

    ... thanks.

     

    Friday, March 24, 2017 3:18 AM

All replies

  • i would like to ask you guys on how do i print an external pdf file.

    You use the facilities of your PDF reader.  For instance, Acrobat Reader supports a /p <filename> command line option which takes you straight to the print dialog.
    http://www.robvanderwoude.com/commandlineswitches.php#Acrobat

    Other PDF readers will likely have a similar feature.

    You use the methods of the Process class to execute another application with a command line argument.  In particular, the Start method with the overload that includes the application name and the command line:
    https://msdn.microsoft.com/en-us/library/h6ak8zt5(v=vs.110).aspx

    Friday, March 24, 2017 5:52 AM
  • Thank you for the help :)
    Friday, March 24, 2017 2:30 PM
  • Hi Krey214,

    Based on your description, I put one Button control in Form , the code below that you can refer to.

    Imports System.Drawing.Printing
    Public Class Form14
        Private WithEvents p_Document As PrintDocument = Nothing
        Private Sub SelectPrinterThenPrint()
            Dim PrintersDialog As New PrintDialog()
    
            If PrintersDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then
                Try
                    p_Document = New PrintDocument()
                    PrintersDialog.Document = p_Document
                    AddHandler p_Document.PrintPage, AddressOf HandleOnPrintPage
    
                Catch CurrentException As Exception
    
                End Try
            End If
        End Sub
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            SelectPrinterThenPrint()
        End Sub
        Private Sub HandleOnPrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles p_Document.PrintPage
            Dim MorePagesPending As Boolean = False
    
            'e.Graphics.Draw...(....)
            'e.Graphics.DrawString(....)
            ' Draw everything...
    
            If MorePagesPending Then
                e.HasMorePages = True
            Else
                e.HasMorePages = False
            End If
        End Sub
    End Class
    

    Hope it is helpful to you.

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 27, 2017 5:37 AM
    Moderator