Alpha Video Training
Results 1 to 25 of 25

Thread: Print a file

  1. #1
    Member
    Real Name
    Terry Morgan
    Join Date
    Nov 2014
    Location
    Essex, England
    Posts
    272

    Default Print a file

    I want to be able to print certain files, typically pdf or docx & set the printer options at the time of the print via xbasic.
    Does anyone know the code for this, as I am sure it is within Alpha's capabilities.
    Thanks
    Terry

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Print a file

    You can use the ole methods in Alpha to open and print a document whose associated executable supports ole. The code would be document type specific.
    There can be only one.

  3. #3
    Member
    Real Name
    Terry Morgan
    Join Date
    Nov 2014
    Location
    Essex, England
    Posts
    272

    Default Re: Print a file

    I was trying to avoid opening the file / document rather just print a file (name stored in a variable) & be able to set the printer settings all via xbasic.
    Thanks

  4. #4
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Print a file

    I meant "open" the file as in make a connection to it via ole.

    The following prints a Word document to a pdf print driver, for example. The document is never visible.

    Code:
    FUNCTION Word_Conv_Document AS L (docName AS C )
    	Dim wordApp As p
    	Dim wordDoc As p
    	
    	wordApp = ole.Create("Word.Application")
    	wordApp.WindowState = 1 'wdWindowStateMaximize
    	wordApp.Documents.Open(docname)
    	wordApp.ActivePrinter = "Bullzip PDF Printer"
    	wordApp.Application.PrintOut()
    	WordApp.Quit()
    	
    	Word_Conv_Document = .T.
    	
    	delete wordDoc
    	delete wordApp
    	
    END FUNCTION
    Last edited by Stan Mathews; 03-11-2015 at 12:39 PM.
    There can be only one.

  5. #5
    Member
    Real Name
    Terry Morgan
    Join Date
    Nov 2014
    Location
    Essex, England
    Posts
    272

    Default Re: Print a file

    I am still struggling with this one - not really used to the FUNCTION programming

    I am trying to print a pdf file to a named printer & be able to set the printer tray / duplex & paper size at the same time

    Any help?

    Thanks
    Terry

  6. #6
    "Certified" Alphaholic Tom Henkel's Avatar
    Real Name
    Tom Henkel
    Join Date
    May 2002
    Location
    New Jersey, USA
    Posts
    1,875

    Default Re: Print a file

    I think you're looking for report.printer_override(). We use it to redirect printing to a specific printer and to set paper size.
    ...from the Help file:

    "REPORT.PRINTER_OVERRIDE()

    Syntax

    Last_Printer as C = :REPORT.PRINTER_OVERRIDE( Printer_Name as C [, Printer_Options as P [, Save_Old_Options as P ]] )

    Argument
    Description

    Printer_Name
    The printer’s name (as it appears in the Control Panel ) followed optionally by "on port:", where port is the port on which you want to print. If Printer_Name is equal to a NULL string (""), then Alpha Five will use the Default Windows printer.

    Printer_Options
    Optional. A dot variable specifying the new options to set. The options that will be available depend on the printer you select. The following options appear for a Compaq laser printer. For a view of your printer's options:

    Create a new Action Script.

    Select Reports > Print a Layout.

    Display the Options tab.

    Click Override printer settings.

    Option
    Description

    papersize
    "Letter", "Legal", "Tabloid", etc.

    orientation
    "Portrait" or "Landscape"

    paperlength
    A positive number (e.g. 11).

    paperwidth
    A positive number (e.g. 8.5).

    scale
    A positive number

    copies
    An integer number greater than or equal to 1.

    quality
    "High", "Medium", "Low", or "Draft".

    color
    "Color" or "Monochrome".

    duplex
    "Simplex", "Horizontal", "Vertical

    truetype
    "Bitmap", "Download", "Substitute"

    collate
    .T. or .F.

    defaultsource
    "Automatically Select", "Manual Paper Feed", "Tray 1", etc.

    Save_Old_Options
    Optional. A dot variable to hold the previous set of options.


    Description

    The REPORT.PRINTER_OVERRIDE() method sets the printer to Printer_Name for all subsequent print operations. Alpha Five will use Printer_Name regardless of whether the layout specifies an explicit printer name, or the default printer. In addition, Alpha Five will not display the Printer Selection dialog box even if you checked the "Show printer setup on print" check box in the layout.

    Last_Printer is the name of the printer that Alpha Five was previously set to use. This allows you to restore the previously set printer driver.

    Printer_Name should be the printer’s name (as it appears in the Control Panel ) followed optionally by "on port:", where port is the port on which you want to print. For example:"

    Tom

  7. #7
    Member
    Real Name
    Terry Morgan
    Join Date
    Nov 2014
    Location
    Essex, England
    Posts
    272

    Default Re: Print a file

    I am very familiar with REPORT.PRINTER_OVERRIDE() as I use this a lot, however this appears to work only with <<an Alpha Layout>>.PRINTER_OVERRIDE() whereas I am trying to print a pdf file.
    I would need something like FILE.PRINTER_OVERRIDE() but this does not exist.
    Thanks
    Terry

  8. #8
    Member
    Real Name
    Terry Morgan
    Join Date
    Nov 2014
    Location
    Essex, England
    Posts
    272

    Default Re: Print a file

    I think I have got it now
    I will need to use REPORT.PRINTER_OVERRIDE() and then a version of the FUNCTION from Stan.
    Will let you know if I crack it.
    Thanks
    Terry

  9. #9
    "Certified" Alphaholic Tom Henkel's Avatar
    Real Name
    Tom Henkel
    Join Date
    May 2002
    Location
    New Jersey, USA
    Posts
    1,875

    Default Re: Print a file

    I'm home now, but tomorrow I'll post a copy of my script.

    Hopefully it will help.

    Tom

  10. #10
    Member
    Real Name
    Terry Morgan
    Join Date
    Nov 2014
    Location
    Essex, England
    Posts
    272

    Default Re: Print a file

    Thanks Tom as I haven't even been able to create a FUNCTION to print a pdf file yet, let alone set the printer settings.
    Look forward to your script.
    Terry

  11. #11
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Print a file

    I will need to use REPORT.PRINTER_OVERRIDE() and then a version of the FUNCTION from Stan.
    The function I provided made use of ole commands available in Word. I don't see the same as available in Reader.

    If you think using report.printer_override() will do what you want (don't know, haven't tried it) the you can use sys_print() to actually print the file.
    There can be only one.

  12. #12
    Member
    Real Name
    Terry Morgan
    Join Date
    Nov 2014
    Location
    Essex, England
    Posts
    272

    Default Re: Print a file

    I have been unsuccessful so far
    Unable to create a working FUNCTION to print a pdf file
    sys_print() does print a pdf file, but only to the default printer
    report.printer_override() only seems to work when printing an Alpha Form, Report, Letter etc.
    Any more suggestions out there?
    Thanks
    Terry

  13. #13
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Print a file

    You can get the current default printer with

    ui_printer_default_get()

    and you can set the default printer to another known name with

    sys_shell("rundll32 printui.dll,PrintUIEntry /y /n \"Lexmark MS71 Series XL\"")

    and you can get a list of currently attached printers with

    UI_PRINTERS_GET()

    Setting the printer options Is a different matter.
    There can be only one.

  14. #14
    "Certified" Alphaholic Tom Henkel's Avatar
    Real Name
    Tom Henkel
    Join Date
    May 2002
    Location
    New Jersey, USA
    Posts
    1,875

    Default Re: Print a file

    Terry,

    We use this code in a script to redirect printing to a specific printer. We have file rooms(2) with case folders in them. our workers would use this script (under a buttonon a screen) to send a request (report) to one of the file rooms, then redirect their default printer back to default. Hopefully it helps you. Ignore the aa.bcbss.agency thing, it is one of our addin variables. the variable vcprinter must be a named printer in the windows control panel printer list.

    Code:
    on error goto errors2
    DIM vcprinter as C = ""
    'vcprinter should never be blank Code makes sure we dont send of a blank request
    IF FLOR="3" .and. close3<>"X" THEN
    	vcprinter = "FileRoom3"
      elseif FLOR="4"
    	vcprinter = "FileRoom4"
      elseif FLOR ="3" .and. close3 = "X"
      	vcprinter = "FileRoom4"  'print 3rd floor requests to 4th floor when 3 is closed
      else
    	ui_msg_box(aa.bcbss.agency+" File Room System","No Valid File Room Printer Specified, "+chr(13)+"File Room "+FLOR +" Specified - Cannot Print Request")
      	end
    end if
    a5_previous_printer_name=ui_printer_default_get()
    delete options
    dim options as p
    options.dummy=1
    options_text=<<%str%
    <papersize="Letter 8 1/2 x 11 in">
    
    %str%
    property_from_string(options,options_text)
    delete options.dummy
    delete oldOptions
    dim oldOptions as p
    oldOptions.dummy = 1
    old_printer_name = report.Printer_override(a5_previous_printer_name,options,oldOptions)
    delete oldOptions.dummy
    
    on error goto errors2 'if they cannot communicate with the printer will error, and this restores the default if so
    temp=ui_printers_get()
    'Select the correct printer name this should work for any OS
    ans = alltrim(*for_each(foo,if((vcprinter $ word(temp,*counter(),crlf())),word(temp,*counter(),crlf()),""),temp))
    if ans =""
    ui_msg_box("ERROR","No printer named")
    end
    end if 
    if w_count(ans,crlf())>1
    ui_msg_box("ERROR","Duplicate printer names print job will be canceled")
    end
    end if
    :report.printer_override(ans)
    
    ':Report.Print("case Request Card@fileroom.set",query.filter,query.order)
    'after printing we must reset the printer back to the way it was when we started
    :Report.Print("case Request Card@fileroom.set",query.filter,query.order)
    :report.printer_override("")
    
    'error routine
    errors2: 
    err_msg = error_text_get(error_code_get())
    line = error_line_number_get()
    script = error_script_get()
    ui_msg_box("Error", err_msg+" Error occurred at line "+alltrim(str(line,4,0))+ " in script: "+script)
    errors: 
    report.printer_override("")
    end
    Tom

  15. #15
    Member
    Real Name
    Terry Morgan
    Join Date
    Nov 2014
    Location
    Essex, England
    Posts
    272

    Default Re: Print a file

    Unfortunately the Report.printer_override(), used in this script, does not seem to work unless you are printing an alpha layout (Form, Report etc)
    As I have tried sys_print() following this & the file still prints to the default printer.
    sys_shell("rundll32 printui.dll,PrintUIEntry /y /n \"Lexmark MS71 Series XL\"") helps to change the printer, but doesn't give the control of printer settings.
    Is there a way of creating an unbound form - as my thought is to embed the pdf file & then print the form using the override()
    Thanks
    Terry

  16. #16
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Print a file

    my thought is to embed the pdf file
    Which object type did you have in mind to hold the pdf.
    There can be only one.

  17. #17
    Member
    Real Name
    Terry Morgan
    Join Date
    Nov 2014
    Location
    Essex, England
    Posts
    272

    Default Re: Print a file

    A super control enmbedded in a form
    I have tried this already but whilst the form prints, the pdf does not

  18. #18
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Print a file

    I experimented with the same but it is actually a pdf viewer supercontrol if I'm not mistaken. The capability to print the pdf itself is built into the supercontrol and leads one to set the print options via the printer driver dialog of the chosen printer. Much the same if an activex object is used. I haven't had any success getting an ole object to work.

    Did a search and found some advice on using an ole object and a pdf.

    You need to disable Adobe reader version X enhanced security in two places. Under Preferences - uncheck enable protected mode at startup, and under Security (Enhanced) uncheck enable enhanced security.
    Not sure this will give you what you need but it's embedded in the form, not just in a viewer control.

    You can also embed the ole object in a report.
    Last edited by Stan Mathews; 03-20-2015 at 10:39 AM.
    There can be only one.

  19. #19
    Member
    Real Name
    Terry Morgan
    Join Date
    Nov 2014
    Location
    Essex, England
    Posts
    272

    Default Re: Print a file

    Still no luck so far, any other suggestions out there?
    Thanks
    Terry

  20. #20
    "Certified" Alphaholic DaveM's Avatar
    Real Name
    Dave Mason
    Join Date
    Jul 2000
    Location
    Hudson, FL
    Posts
    6,026

    Default Re: Print a file

    Use a batch file to print.

    I don't remember all the syntax, but I believe it might work. You can change the name of the file by writing into the bat file from alpha, the run the bat file.

    It has been a number of years since I did similar.
    Dave Mason
    dave@aldausa.com
    Skype is dave.mason46

  21. #21
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: Print a file

    & set the printer options at the time of the print via xbasic
    Not sure that's supported in a batch file.
    There can be only one.

  22. #22
    "Certified" Alphaholic DaveM's Avatar
    Real Name
    Dave Mason
    Join Date
    Jul 2000
    Location
    Hudson, FL
    Posts
    6,026

    Default Re: Print a file

    I am not sure either stan. Like I said, it has been a long time since I did it.
    Seemed like Terry was running out of options.
    Dave Mason
    dave@aldausa.com
    Skype is dave.mason46

  23. #23
    Member
    Real Name
    Terry Morgan
    Join Date
    Nov 2014
    Location
    Essex, England
    Posts
    272

    Default Re: Print a file

    I think I need 2 new functions
    :FILE.PRINTER_OVERRIDE( Printer_Name as C [, Printer_Options as P [, Save_Old_Options as P ]] )

    :FILE.PRINT( File Name as C )

    If anyone is able to work these out for me as I seem to be stuck.

    Thanks
    Terry

  24. #24
    Member
    Real Name
    Jon Moody
    Join Date
    Sep 2010
    Location
    Brackley, UK
    Posts
    222

    Default Re: Print a file

    Terry, if you simply wish to set a specific printer option such as duplex and/or landscape for specific jobs I think it would be a lot easier to just install a second copy of the printer and set it up as required. I've just tested this in Windows 8 on a network attached printer, setting the 2nd copy to landscape and it took me about 5 minutes from start to finish.

    Use this method along with some of the previously suggested options to select the correct printer and problem (with a little testing) solved.

  25. #25
    Member
    Real Name
    Terry Morgan
    Join Date
    Nov 2014
    Location
    Essex, England
    Posts
    272

    Default Re: Print a file

    or even one

    :FILE.PRINT( File Name as C [,Printer_Name as C [, Printer_Options as P ]] )

    Thanks
    Terry

Similar Threads

  1. Help - setting the file name for "Print Report as PDF File" action
    By TheSmitchell in forum Application Server Version 11 - Web/Browser Applications
    Replies: 8
    Last Post: 08-14-2015, 07:50 PM
  2. Print to File
    By djones092 in forum Alpha Four Versions 7 and 8
    Replies: 2
    Last Post: 09-25-2003, 06:43 AM
  3. Print to file ???
    By Paul Wehr in forum Alpha Four Version 6 and Prior
    Replies: 8
    Last Post: 04-19-2002, 02:04 PM
  4. Print To File
    By Ken L Herrold in forum Alpha Four Version 6 and Prior
    Replies: 3
    Last Post: 12-05-2001, 03:50 PM
  5. Print to File
    By Peter Lear in forum Alpha Five Version 4
    Replies: 10
    Last Post: 01-22-2001, 04:38 AM

Bookmarks

Posting Permissions

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