Results 1 to 12 of 12

Thread: Changing Printers in VB

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    56

    Changing Printers in VB

    I have a database with a report that needs to be printed and then saved to a file as a pdf. Can I do this in code so the user just checks a box to request that a pdf version be saved and then the application does so, after printing a hard copy?

    I have been playing with the application.printers collection but can't find a way of doing this.

    (BTW: I have downloaded a pdf distiller...)

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Changing Printers in VB

    you don't say what program you are working in, looks like maybe access, but this works in excel, prints page 1 to 1, 1 copy and sets the active printer at the same time
    VB Code:
    1. mysht.PrintOut 1, 1, 1, , "CutePDF Writer"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    56

    Re: Changing Printers in VB

    Sorry, you're right, it is Access.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Changing Printers in VB

    does access have the printout method?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    56

    Re: Changing Printers in VB

    It appears not...

  6. #6
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Changing Printers in VB

    Quote Originally Posted by neilscaplan
    (BTW: I have downloaded a pdf distiller...)
    Does this "distiller" make an entry in your printer list? What is the required input file format? (Adobe Distiller requires that you generate an intermediate PostScript file and then feed that into distiller)

    Also, I don't think PDF Writer is available anymore ... the last version that my IT department was able to find it is was (I think) version 4. Distiller is a whole new ballpark. I've done this in Excel, but you have to have a printer driver installed that is capable of generating a PostScript file.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    56

    Re: Changing Printers in VB

    Quote Originally Posted by Webtest
    Does this "distiller" make an entry in your printer list?
    Yes, it does. When you choose it a dialog box opens asking where you would like to save the document. I would prefer it if this bit could also be automated (so that the folder I will have created would be used) but just getting it working would be a start...

    Quote Originally Posted by Webtest
    What is the required input file format? (Adobe Distiller requires that you generate an intermediate PostScript file and then feed that into distiller)
    I'm not sure what you mean? To do this manually all I have to do is open the report and click print and choose the distiller as the printer...

  8. #8
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Changing Printers in VB

    Quote Originally Posted by neilscaplan
    Yes, it does. When you choose it a dialog box opens asking where you would like to save the document. I would prefer it if this bit could also be automated (so that the folder I will have created would be used) but just getting it working would be a start...
    This was the same problem I had with the Adobe Acrobat Pro v4 "Adobe Writer" "printer" when I was trying to automatically PDF 120 Word documents at a time. I tried using "SendKeys", but I never got it to work properly.

    Adobe Distiller (a part of the Acrobat package) is a "Pipe" function. You input a PostScript file into the Distiller and it creates a PDF output. You can create a user configuration file that specifies where the file is to be saved (and all of the PDF compression parameters), so there is no intermediate popup to fight with. Setting up the entire configuration is not trivial though.

    The entire "print" process is somewhat more convoluted ... print out a temporary PS file through a PostScript capable printer driver; send the PostScript file to Distiller specifying the configuration file to use; then delete the temporary PS file. However, the upside is that this process is as solid as a rock.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  9. #9

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    56

    Re: Changing Printers in VB

    Quote Originally Posted by Webtest
    This was the same problem I had with the Adobe Acrobat Pro v4 "Adobe Writer" "printer" when I was trying to automatically PDF 120 Word documents at a time. I tried using "SendKeys", but I never got it to work properly.

    Adobe Distiller (a part of the Acrobat package) is a "Pipe" function. You input a PostScript file into the Distiller and it creates a PDF output. You can create a user configuration file that specifies where the file is to be saved (and all of the PDF compression parameters), so there is no intermediate popup to fight with. Setting up the entire configuration is not trivial though.

    The entire "print" process is somewhat more convoluted ... print out a temporary PS file through a PostScript capable printer driver; send the PostScript file to Distiller specifying the configuration file to use; then delete the temporary PS file. However, the upside is that this process is as solid as a rock.
    Cheers Webtest. Can I be cheeky and ask you to let me see the code you created because most of what you wrote went right over my head! In fact if I jump.....no, not a chance!

  10. #10
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Changing Printers in VB

    I won't get to it today unfortunately, but yes, I'll share my code. I'll have to cut snippets out of a large application. (No Zip here).

    What is the name of the package you are using and where did you download it from? Can you Pipe through it? How do you like it?
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  11. #11
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: Changing Printers in VB

    I do very little in Access. Here is the most important part in Excel. I have a bunch of other stuff ... all of our printers are on the network, so I have to figure out the exact network address from any workstation (previous post) for printing the temp PostScript file.

    EDIT: Looking at the code, I think you can pass the output FileSpec to the Pipe in the Shell command. I don't remember. The information for the "Command Line" call to adobe came off the Adobe Forum/Website somewhere.

    If you have to change the output directory for your PDF files, you'll probably have to create a temporary PDF in your JobOptions file and then move it to a program selected directory. Luckily, all of my files go into the same folder.
    Code:
    '=========================================================================================================
    'Print To PDF Function
    '
    'Requires FULL File Specification (Path + Name) for Output File
    'Requires legal identifier for a Printer capable of PostScript File Output
    'Requires a "C:\temp" Directory
    'Requires a "DisplayCompliance" JobOptions file for Distiller
    '
    Public Function Print_To_PDF(OutFileSpec As String, Template_Printer As String)
        Dim ProcessID As Double
        Dim strAdobe As String
        Dim oTempFile As String
        
        'Define the Temporary POST SCRIPT Output File
        oTempFile = "C:\temp\TempPrintFile.ps"
        
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, _
            ActivePrinter:=Template_Printer, _
            PrintToFile:=True, Collate:=True, _
            PrToFileName:=oTempFile
        
        'Path to Adobe Distiller
        strAdobe = "C:\Program Files\Adobe\Acrobat 5.0\Distillr\acrodist.exe"
        'Specify the jobOptions File to use
        strAdobe = strAdobe & _
            " /J DisplayCompliance"
        'Open a NEW instance of Adobe
        strAdobe = strAdobe & " /N"
        'Specify the Output File IN QUOTATION MARKS!
        strAdobe = strAdobe & " /O " & """" & OutFileSpec & """"
        'Force Adobe to QUIT on completion
        strAdobe = strAdobe & " /Q"
        'Select the Input File
        strAdobe = strAdobe & " " & oTempFile
        
        'Give the Adobe Process Focus so it will show the overwrite warning popup
        ProcessID = Shell(strAdobe, vbMinimizedFocus)
        
    End Function
    I hope this at least shows you what can be done (well, in Excel anyway!).
    Last edited by Webtest; Oct 20th, 2006 at 10:24 AM.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  12. #12

    Thread Starter
    Member
    Join Date
    Jan 2003
    Posts
    56

    Re: Changing Printers in VB

    Cheers, i'll give it a go over the weekend...

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