none
Printing PDF Files RRS feed

  • Question

  • Hi all, i want to print pdf files by using word but i don't want to open word and the user should not be informed that word is doing something. Unfortuneately a message displays evertime word is opening the "foreign" pdf file to convert it. As far as i know there is a parameter to suppress this info in the "open" function (confirmConversions). But it seems not to work, the message appears anyway. Please have a look:


        Private Shared Sub PrintWithWord(strFile As String, strPrinter As String)
            'Dim f As New OpenFileDialog
            Dim p As New PrintDialog
            p.PrinterSettings.PrinterName = strPrinter
            Dim app As Word.Application
            Dim doc As Word.Document
            app = New Word.Application
            app.Visible = False
            'Set Printer
            app.WordBasic.FilePrintSetup(Printer:=p.PrinterSettings.PrinterName, DoNotSetAsSysDefault:=1)
            Dim m As Object = System.Reflection.Missing.Value
            'Open document
            Dim confirmConversions As Object = False
            doc = app.Documents.Open(strFile, confirmConversions, m, m, m, m, m, m, m, m, m, m)
            'Print document
            app.PrintOut()
            'Close document
            app.Documents.Close()
            'Quit word application
            app.Quit()
            'Release
            app = Nothing
        End Sub

    How can i get rid of the warning message?

    Rgds

    Thomas

    Saturday, November 12, 2016 1:35 PM

All replies

  • ConfirmConversions is a Boolean, not an Object. Delete the lines

    Dim m As Object = System.Reflection.Missing.Value

    and

    Dim confirmConversions As Object = False

    and change the line that opens the document to

    doc = app.Documents.Open(strFile, False)


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Saturday, November 12, 2016 2:17 PM
  • no matter if boolean or object - it still persits.

    It seems the message is especially for PDF conversations, i'm attaching it.

    Rgds

    Thomas

    Saturday, November 12, 2016 3:20 PM
  • I can't reproduce the problem - I can open a PDF file without getting a dialog box using code similar to yours.

    But try the following:

    app.DisplayAlerts = False
    doc = app.Documents.Open(strFile, False)
    app.DisplayAlerts = True


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Saturday, November 12, 2016 6:34 PM
  • Hello Hans, i've just tried that

    app.DisplayAlerts = False

    the code ignores that, the message still displays

    Rgds

    Thomas

    Saturday, November 12, 2016 6:48 PM
  • Perhaps you should use another method. See http://www.vbforums.com/showthread.php?508684-Silently-Print-PDF-with-ShellExecute

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Saturday, November 12, 2016 9:07 PM
  • Hi,

    You can try below solution to print PDF file silently without showing any dialog box or Adobe software.

    Dim doc = New PdfDocument()
    doc.LoadFromFile("E:\Sample1.pdf")
    Dim printDoc As PrintDocument = doc.PrintDocument
    printDoc.PrintController = New StandardPrintController()
    printDoc.Print()
    doc.Close()

    Note that this solution is based on a free dll rather than Word.



    • Edited by Jamesbn Monday, November 14, 2016 1:51 AM
    • Marked as answer by datech-hh Monday, November 14, 2016 6:36 PM
    • Unmarked as answer by datech-hh Friday, November 18, 2016 1:34 PM
    Monday, November 14, 2016 1:41 AM
  • Hi datech-hh,

    This warning message displays to you because you are trying to open a PDF file using Word Application.

    so Word Application will give you a Facility that you can convert your PDF file in to Word document to edit the file.

    if you try to open the same file manually then also you will get this message.

    I try to set the format when opening file like mentioned below.

    doc = app.Documents.Open(strFile, False, m, m, m, m, m, m, m, WdOpenFormat.wdOpenFormatAuto, m, m)

    but it didn't help to suppress this dialog.

    also I try to set ConfirmConversion False but it also did not work.

    For more information regarding document.open method please visit the link mentioned below

    Documents.Open Method (Word)

    so it seems that you need to find a different way to achieve your requirement.

    Regards

    Deepak


    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, November 14, 2016 1:46 AM
    Moderator
  • @jamesbn: Free SpirePDF is limited to only 10 Pages in document. The full Version is not free:

    http://www.e-iceblue.com/Buy/Spire.PDF.html

    Friday, November 18, 2016 1:41 PM
  • Hi datech-hh,

    you can use the code mentioned below to print instead of using word.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            Dim PrintPDF As New ProcessStartInfo
            PrintPDF.UseShellExecute = True
            PrintPDF.Verb = "print"
            PrintPDF.WindowStyle = ProcessWindowStyle.Hidden
            PrintPDF.FileName = pdfFileName
            Process.Start(PrintPDF)
    
    End Sub
    
    

    make sure Adobe Reader installed on your machine. it will use that to print the pdf.

    Regards

    Deepak


    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, November 21, 2016 2:21 AM
    Moderator