Skip navigation
Currently Being Moderated

VB.Net Printing of PDFs

Aug 2, 2007 5:39 AM

I am trying to print a pdf document to a specific printer from VB.Net app. I would like this to be a silent process i.e. no print dialog and no Acrobat Reader popping up.

This solution must only use reader as it needs to work without licensing issues.

Anyone got any ideas?

I have managed to do it using the command line options but a reader window pops up and wont go away.
 
Replies
  • Currently Being Moderated
    Aug 2, 2007 6:36 AM   in reply to (Jon_Beverley)
    Reader is designed to "pop up" to ensure that no one uses Acrobat/Reader as "malware" to start doing unrequested silent printing on the user's computer.

    You can certainly use Windows APIs to "hide" it after the fact, but it will first pop up.
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 2, 2007 10:07 AM   in reply to (Jon_Beverley)
    I won't comment about why Adobe does this, but you might be able to work around the issue using the techniques I employed in pdfp / pdfp8 here:

    http://www.esnips.com/web/PDFTools
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 9, 2008 6:23 AM   in reply to (Jon_Beverley)
    " Reader is designed to "pop up" to ensure that no one uses Acrobat/Reader as "malware" to start doing unrequested silent printing on the user's computer. "

    So, then how can one do
    requested
    silent printing???
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 9, 2008 6:36 AM   in reply to (Jon_Beverley)
    What is the workflow that you envision where you need to "silent print"?

    Leonard
     
    |
    Mark as:
  • Currently Being Moderated
    Jan 17, 2008 11:36 PM   in reply to (Jon_Beverley)
    Try the following code. It is working for us..
    Const SEE_MASK_NOCLOSEPROCESS = &H40
    Const SEE_MASK_FLAG_NO_UI = &H400
    Private Type SHELLEXECUTEINFO
    cbSize As Long
    fMask As Long
    hwnd As Long
    lpVerb As String
    lpFile As String
    lpParameters As String
    lpDirectory As String
    nShow As Long
    hInstApp As Long
    lpIDList As Long
    lpClass As String
    hkeyClass As Long
    dwHotKey As Long
    hIcon As Long
    hProcess As Long
    End Type

    Declare Function ShellExecuteEx Lib "shell32.dll"Alias "ShellExecuteEx" (SEI As SHELLEXECUTEINFO) As Long
    Declare Function TerminateProcess Lib "kernel32"Alias "TerminateProcess" (Byval hProcess As Long, Byval uExitCode As Long) As Long

    Function PrintPDF() as Boolean
    On Error Goto PrintDocErrorHandle

    PrintDoc = False

    Dim SEI As SHELLEXECUTEINFO
    SEI.cbSize = Len(SEI)
    SEI.fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_FLAG_NO_UI
    SEI.lpVerb = "Print"
    ' SEI.lpVerb = "Open"
    SEI.lpFile = strFname
    SEI.lpDirectory = s.GetEnvironmentString( "Directory" , True ) & strExtractPath
    SEI.nShow = 1
    SEI.hInstApp = 0
    SEI.lpIDList = 0
    Call ShellExecuteEx(SEI)
    Sleep(3) ' file was being deleted before it could be printed.
    Call TerminateProcess(SEI.hProcess, 0)
    'Print "Return Code = " & Cstr( SEI.hInstApp )
    If SEI.hInstApp < 32 Then
    errMsg = errMsg & Chr(13) & "Error printing document: " & strFname & ". Document Subject: " & doc.subject(0) & ". Document: " & doc.UniversalID & ". Print return code: " & Cstr( SEI.hInstApp)
    Else
    successMsg = successMsg & Chr(13) & "Successfully printed document: " & strFname & " from " & doc.subject(0)
    End If

    PrintDoc = True
    exitFunctionCode:
    Exit Function

    PrintDocErrorHandle:
    flag = 1300
    errMsg = errMsg & Chr(13) & "Error printing document: " & strFname & ". " & Error() & ". Document subject: " & doc.subject(0) & ". Document: " & doc.UniversalID
    Resume exitFunctionCode
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 10, 2008 5:16 AM   in reply to (Jon_Beverley)
    I work with production printing customers and some would like to batch print PDF files; and they would like to do that in the background on their PC. "Silent" printing would be nice because they don't want a print dialog for each and every PDF being printed.
     
    |
    Mark as:
  • Currently Being Moderated
    Mar 12, 2008 7:37 PM   in reply to (Jon_Beverley)
    No method that waits for a defined period before killing the Reader process will work correctly for all PDFs and printers.

    It's much better to know for sure that print spooling is done before closing Reader.

    See pdfp8 here for a utility (with C source) that does this:

    http://www.esnips.com/web/PDFTools
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 26, 2008 6:24 AM   in reply to (Jon_Beverley)
    I have to say this is pretty bull that there is no way to stop adobe from popping up into the focus.

    I run a server program for our business which does batch printing via ole automation in vb6(among other things) and the server can print up to 1000 pdfs a day.

    Now before our company reviewed and approved adobe 8 for use I was stuck using version 6 and had to deal with the msgbox "this is a newer version of adobe, click ok to continue" for every...single...document...because Adobe does not save your settings outside of your current session with adobe(ie checking the box in the pop up that says "check here to never display this again" does nothing).

    Now I have to deal with Adobe popping up every...single...pdf... I could live with that if it did not always force itself to be the focus and interrupt what else I may be working on. I am one of the most patient people but this has me in a near rage.
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 26, 2008 6:39 AM   in reply to (Jon_Beverley)
    > I run a server program for our business which does batch printing via ole automation

    Well, there's your problem. Acrobat is not designed for server use, and it's actually expressly forbid in the EULA (Section 2.3, Server Use). Using it in a server-based automation fashion is a violation of the EULA, and since you've just publicly posted on Adobe forums that you're using it in that way it would probably be a good idea to remove it from your server before you get a call from Adobe Legal (believe me, they do follow-up on license violations).

    The OLE automation is designed to automate desktop installs of Acrobat. It is, per the EULA and documentation, required that each end-user have a licensed copy of Acrobat on their machine and that the automation software be installed locally on their machine as well. There can be no situation where multiple users are submitting requests to a single copy of Acrobat in an automated fashion.

    The reason its not working the way you expect it to is because it was expressly designed NOT to work in a server environment. That's what the LiveCycle products are for. Using Acrobat as part of any server-based workflow is illegal, so Adobe certainly don't develop it to be server-friendly.
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 26, 2008 7:00 AM   in reply to (Jon_Beverley)
    Sorry it is not run on a server. It is a stand-alone application that we call a server because it handles document management requests that are outside of adobe(ie our file structure) as well as has a lot of utilities for managing our database and files. I create the batch print jobs and manually submit them. These are by request though if that matters and if so since everyone has Adobe installed already would it be fine if we just had them run a striped down version to print? This still brings it back to the issue that adobe pops up and interrupts your workflow for anyone that prints. This is completely unacceptable for programming adobe into an end user application.

    Either way if we misread what means to be a stand alone application and not I apologize. We will gladly switch to an alternative since this is small piece of it.
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 26, 2008 7:06 AM   in reply to (Jon_Beverley)
    And by request I mean someone physically tells me they need some hardcopies sent somewhere and I select the files to print and push a button to batch print them.

    I apologize if the language I used out of habit is confusing.
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 26, 2008 7:30 AM   in reply to (Jon_Beverley)
    No, based on your more complete description of your workflow you should be within the bounds of the EULA so no problem there.

    Your best bet, since you have a full version of Acrobat, would be to create a silent print plug-in in C/C++ and then call that plug-in from your VB application. That way you can assure it is a silent, dialog-less print (and quite frankly, a simple silent print plug-in that doesn't require any advanced configuration options will not take long to build at all for an experienced developer).
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 7, 2008 11:02 PM   in reply to (Jon_Beverley)
    Thank you very much Saradhi Cheruvu... The code worked for me too by increasing the sleep time to 30 seconds...
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 22, 2008 9:03 AM   in reply to (Jon_Beverley)
    download the PDFCreator from Sourceforge - http://sourceforge.net/projects/pdfcreator/

    Set it as the default printer (can do this in the code if you want)
    Set the settings in the PDFCreator Printer options in the Auto-save section to not have pop-ups and where to save the document.

    If you want to get fancy, you can call the word, excel, or whatever with a minimized window to get NO windows popping up.

    Let it fly:

    Imports System
    Imports System.Diagnostics
    Imports System.IO

    Module Module1
    Const pdfTempFolder As String = "c:\tempPDF"
    Const pdfResultsFolder As String = "c:\tempPDF\"
    Dim DocumentName As String
    ' ------------------------------------------------------------
    Dim di As New IO.DirectoryInfo("c:\tempPDF")
    Dim aryFi As IO.FileInfo() = di.GetFiles("*.doc")
    Dim fi As IO.FileInfo

    Sub Main()
    For Each fi In aryFi
    Console.WriteLine("File Full Name: {0}", fi.FullName)
    DocumentName = fi.FullName
    Print(DocumentName)
    Next
    End Sub

    Sub Print(ByVal DocumentName)
    Dim proc As New Process
    Console.WriteLine("DocumentName Sent to Process Start is: " + DocumentName)
    proc.StartInfo.FileName = DocumentName
    proc.StartInfo.Verb = "Print"
    proc.StartInfo.CreateNoWindow = True
    proc.Start()
    End Sub
    End Module
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 22, 2008 9:04 AM   in reply to (Jon_Beverley)
    You can change this to C code or what ever your preference is. You will need to have the Ghostscript loaded with the PDFCreator program.
     
    |
    Mark as:
  • Currently Being Moderated
    Oct 21, 2008 2:58 AM   in reply to (Jon_Beverley)
    test
     
    |
    Mark as:
  • Currently Being Moderated
    Nov 29, 2008 1:23 PM   in reply to (Jon_Beverley)
    Change the sentences
    VB.NET
    Arguments = "/t """ & Filename & """"
    by
    C#
    Arguments = "/t " + path_file + " " + path_printer + ""
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 19, 2012 7:04 AM   in reply to (Jon_Beverley)

    i wrote an article how to open and show and silent print pdfs in Windows and Mac OSX with examples (using native commands):
    http://www.onyrix.com/2012/04/adobe-air-pdf-silent-print-with-acrobat- reader/

    bye
    d

    even if is for Adobe Air you can you native commands examples for any other programming language

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)