PureLPRINT library : LPRINT functions (direct LPT access)

All PureFORM, JaPBe, Libs and useful code maintained by gnozal

Moderator: gnozal

gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

PureLPRINT library : LPRINT functions (direct LPT access)

Post by gnozal »

PureLPRINT Library

Purpose :

Code: Select all

Provide LPRINT functions with direct access to printer, just like good old BASIC ! (It won't work with GDI only / POSTSCRIPT printers)
Functions :
PB3.94 : http://gnozal.ucoz.com/PureLPRINT.htm
PB4.0x : http://gnozal.ucoz.com/PureLPRINT_.htm

Example :

Code: Select all

OpenConsole()
MyPrinter.s = LPRINT_GetDefaultPrinter()
If LPRINT_OpenPrinter(MyPrinter)
  Debug "Open " + MyPrinter
  If LPRINT_StartDoc("Job")
    LPRINT_Print(Chr(27) + "E") ; PCL reset for HP Printers
    LPRINT_Print("Line 1")
    LPRINT_PrintN("Same Line")
    LPRINT_PrintN("Line 2")
    LPRINT_PrintN("")
    LPRINT_PrintN("Line 4")
    LPRINT_NewPage ; Form feed
    LPRINT_PrintN("Line 1 (Page 2)")
    LPRINT_EndDoc()
  Else
    Debug "Could not start job"
    PrintN("Could not start job")
  EndIf
  LPRINT_ClosePrinter()
  Debug "Done"
  PrintN("Done")
Else
  Debug "Printer " + MyPrinter + " not found"
  PrintN("Printer " + MyPrinter + " not found")
EndIf
Maybe it sounds strange, but I find it usefull to translate some old QuickBasic or Powerbasic console stuff. Works for me.

Download :
Only available for Purebasic Windows x86
PB3.94 : http://gnozal.ucoz.com/PureLPRINT.zip
PB4.0x : http://gnozal.ucoz.com/PureLPRINT_.zip
PB4.1x : http://gnozal.ucoz.com/PureLPRINT__.zip
PB4.2x : http://gnozal.ucoz.com/PureLPRINT___.zip
PB4.3x : http://gnozal.ucoz.com/PureLPRINT_430.zip
PB4.4x : http://gnozal.ucoz.com/PureLPRINT_440.zip
PB4.5x : http://gnozal.ucoz.com/PureLPRINT_450.zip
PB4.6x : http://gnozal.ucoz.com/PureLPRINT_460.zip
PB5.0x : http://gnozal.ucoz.com/PureLPRINT_500.zip

Other libs and tools at http://gnozal.ucoz.com/
Last edited by gnozal on Tue Aug 18, 2009 11:54 am, edited 14 times in total.
PWS32
User
User
Posts: 85
Joined: Sat May 10, 2003 1:02 pm
Location: Germany

Post by PWS32 »

Hi,

cant print to FreePDF and Canon PIXMA iP3000
hpdeskjet 995 is OK

Best regards,
Peter
User avatar
Rings
Moderator
Moderator
Posts: 1427
Joined: Sat Apr 26, 2003 1:11 am

Post by Rings »

PWS32 wrote:Hi,

cant print to FreePDF and Canon PIXMA iP3000
hpdeskjet 995 is OK

Best regards,
Peter
i think thats ok, coz its prints directly to the LPT-port.
SPAMINATOR NR.1
Num3
PureBasic Expert
PureBasic Expert
Posts: 2810
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Works just fine on Epson printers too...
And Xerox 440 LaserJet
PWS32
User
User
Posts: 85
Joined: Sat May 10, 2003 1:02 pm
Location: Germany

Post by PWS32 »

Hi,
i think thats ok, coz its prints directly to the LPT-port.
im have no LPT Printers im have only USB Printers
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> im have no LPT Printers im have only USB Printers

I think most of today's printers are USB-only.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Just for information : I have only tested it under Win98/95 and WinNT4, and only with HP printers (LPT or Network). I don't have WinXP or any USB device.
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

@gnozal

Found this library very useful today.

Here is a pseudo LPRINT Requester procedure. Maybe you can add this
to this useful library.
Edited Dec 18 2004
Note: gnozal has updated his library with his own LPRINT_Requester. Thanks gnozal!

This code in this message has been revised so it remains compatible with the library.

Code: Select all

; LPrint_Requester - TerryHough Dec 16, 2004
; 
; Requires the PureLPRINT Library from gnozal
; See PB Forum topic http://jconserv.net/purebasic/viewtopic.php?t=12537
;
Procedure.s LPRINT_RequesterM(ParentWindow)
  SelectWindow = OpenWindow(#PB_Any,0,0,400,200,#PB_Window_WindowCentered,"LPrint Selecter",ParentWindow)
  If SelectWindow
    CreateGadgetList(WindowID())
    LI = ListIconGadget(#PB_Any,10,10,380,150,"Installed Printers (default printer is highlighted)",360,#PB_ListIcon_CheckBoxes )
    TG = TextGadget(#PB_Any,20,172,350,30,"Click the check box beside the desired printer in the list above.",#PB_Text_Center)
    Work$ = LPRINT_GetInstalledPrinters()
    While Work$
      Prt$ = StringField(Work$,1,";")
      AddGadgetItem(LI,-1,Prt$)
      Work$ = RemoveString(Work$,Prt$)
      If Mid(Work$,1,1) = ";"
        Work$ = Mid(Work$,2,Len(Work$))
      EndIf
    Wend
    SelectedPrinter.s = LPRINT_GetDefaultPrinter()
    For I= 0 To CountGadgetItems(LI) -1
      If GetGadgetItemText(LI,I,0) = SelectedPrinter
        SetGadgetItemState(LI,I,#PB_ListIcon_Selected)
        ActivateGadget(LI)
        Break
      EndIf
    Next
    Repeat
      EventID = WaitWindowEvent()
      Select EventID
      Case #PB_Event_Gadget
        Select EventGadgetID()
        Case Li       ; Chckbox clicked
          SetGadgetItemState(LI,I, 0)
          While WindowEvent() : Wend 
          Break
        EndSelect
      EndSelect
    Until EventID = #PB_EventCloseWindow
    For i= 0 To CountGadgetItems(LI) -1
      If GetGadgetItemState(LI,I) = #PB_ListIcon_Checked
        SelectedPrinter = GetGadgetItemText(LI,I,0)
        Break
      EndIf
    Next
    SetGadgetText(TG,"Attmpting to open the " + SelectedPrinter + " printer.")
    Delay(1000)
    If LPRINT_OpenPrinter(SelectedPrinter)
      ; MessageRequester("DEbug","Opened " + SelectedPrinter,#MB_ICONINFOrMATION)
      CloseWindow(SelectWindow)
      ProcedureReturn SelectedPrinter
    Else
      MessageRequester("ERROR - LPRINT", "Printer " + SelectedPrinter + " not found", #MB_ICONERROR)
      CloseWindow(SelectWindow)
      ProcedureReturn ""
    EndIf
  Else
    MessageRequester("ERROR - LPRINT", "LPRINT Selection could not be started.", #MB_ICONERROR)
  EndIf
EndProcedure

;- Example of usage <-----------------------------------------------------------------

#Window_Main = 100
If OpenWindow(#Window_Main,0,0,500,500,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"LPrint Job")
  CreateGadgetList(WindowID())
  EditorGadget(#PB_Any,10,10,480,480)
  While WindowEvent(): Wend
  ; Use the LPRINT_Requester procedure passing the WindowID of the calling window ----
  ; The procedure returns the name of the selected printer in a string. If the    ----
  ; procedure fails to open the selected printer, it returns a null string.       ---- 
  MyPrinter.s = LPRINT_RequesterM(WindowID())
  If MyPrinter
    If LPRINT_StartDoc("MyJob")
      ; Print here as desired --------------------------------------------------------
      ; LPRINT_Print(Chr(27) + "E") ; PCL reset for HP Printers
      ; LPRINT_Print("Line 1")
      ; LPRINT_PrintN("Same Line")
      ; LPRINT_PrintN("Line 2")
      ; LPRINT_PrintN("")
      ; LPRINT_PrintN("Line 4")
      ; LPRINT_NewPage() ; Form feed
      ; LPRINT_Print("Line 1 (Page 2)")
      LPRINT_EndDoc()
      ; End of printing --------------------------------------------------------------
    Else
      MessageRequester("ERROR - LPRINT", "Could not start job", #MB_ICONERROR)
    EndIf
    LPRINT_ClosePrinter()
  EndIf
Else
  MessageRequester("ERROR - LPRINT", "Could not open the main window.", #MB_ICONERROR)
EndIf

Repeat
  ev=WaitWindowEvent()
Until ev=#PB_EventCloseWindow
End
I found this very handy to use with a laser printer and PCL language
files.

Need a way to send PCL files in excess of 64Kb such as font files, etc.
Any ideas would be appreciated.

Thanks,
Terry
Last edited by TerryHough on Sat Dec 18, 2004 3:05 pm, edited 1 time in total.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Thanks Terry, I will take a look.
The requester : why do you need the ParentWindowID ? I think you can also get a modal like window without (and save a parameter).
The 64k : are you talking about the string size limit ? It seems to not exist anymore viewtopic.php?t=13271. I never thought about this (I never needed to send big files directly to my HP printers). Maybe I can fix something with pointers to memory banks instead of strings. When I have some time ...
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

gnozal wrote:Thanks Terry, I will take a look.
The requester : why do you need the ParentWindowID ? I think you can also get a modal like window without (and save a parameter).
Probably could, that is just the way I did it.
The 64k : are you talking about the string size limit ? It seems to not exist anymore viewtopic.php?t=13271. I never thought about this (I never needed to send big files directly to my HP printers). Maybe I can fix something with pointers to memory banks instead of strings. When I have some time ...
Actually, the 64k limit isn't my problem. I can/could get around that.

The problem is I am trying to download a PCL font to the printer and I
cannot get the entire file to go. Font files can (usually) contain null
character(s). I was putting the file into a string, and then sending it with
LPRINT_Print(Text$). It appears that hits the null and stops sending
(typical PB string handling).

What I need is more like a
LPRINT_Data(*buffer, length)
to send an entire block of memory regardless of the contents. (Simlar
to the WriteData(*buffer,length) memory command.)

So, yes, you are correct. I need something with pointers to memory
banks instead of strings.
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Library update

- added new function : LPRINT_Requester()

Description :
LPRINT_Requester([RequesterTitle.s, [RequesterText.s, [ButtonOkText.s, [ButtonCancelText.s]]]])
Returns chosen printer - the string is empty if no printer is available or the user has cancelled the requester
Default values :
RequesterTitle = "Printer selection"
RequesterText = "Please select a printer :"
ButtonOkText = "Ok"
ButtonCancelText = "Cancel"

NB : thank you Terry for the idea but I didn't use your code :
- no ParentWindow
- ComboBox instead of ListIconGadget
- 'Ok' and 'Cancel' buttons
- returns PrinterName without testing the connection
- multilanguage : optional parameters RequesterTitle / RequesterText / ButtonOkText / ButtonCancelText

Here is Terry's modified example :

Code: Select all

;
#Window_Main = 100
If OpenWindow(#Window_Main,0,0,500,500,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"LPrint Job")
  CreateGadgetList(WindowID())
  EditorGadget(#PB_Any,10,10,480,480)
  While WindowEvent(): Wend
  MyPrinter.s = LPRINT_Requester()   ; / modified requester
  If LPRINT_OpenPrinter(MyPrinter)   ; / and handling
    If LPRINT_StartDoc("MyJob")
      ; Print here as desired --------------------------------------------------------
      ; LPRINT_Print(Chr(27) + "E") ; PCL reset for HP Printers
      ; LPRINT_Print("Line 1")
      ; LPRINT_PrintN("Same Line")
      ; LPRINT_PrintN("Line 2")
      ; LPRINT_PrintN("")
      ; LPRINT_PrintN("Line 4")
      ; LPRINT_NewPage() ; Form feed
      ; LPRINT_Print("Line 1 (Page 2)")
      LPRINT_EndDoc()
      ; End of printing --------------------------------------------------------------
    Else
      MessageRequester("ERROR - LPRINT", "Could not start job", #MB_ICONERROR)
    EndIf
    LPRINT_ClosePrinter()
  EndIf
Else
  MessageRequester("ERROR - LPRINT", "Could not open the main window.", #MB_ICONERROR)
EndIf

Repeat
  ev=WaitWindowEvent()
Until ev=#PB_EventCloseWindow
End
So, yes, you are correct. I need something with pointers to memory banks instead of strings
Ok, I will see what I can do.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

@gnozal

Thanks for the addition of the LPRINT_Requester() in the library. My code
was just a prompt of the idea anyhow.

I hope you can get something going with the memory approach. That
would make the PureLPRINT library very useful for those of us who must
deal with laser printers and the PCL language that controls them.

Thanks,
Terry
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Library update

- new function : LPRINT_PrintData()
- help is now CHM (have a look at my new PureHELPMaker tool viewtopic.php?t=13497 :wink:)

Description :
LPRINT_PrintData(*MemoryBank, DataLength.l) : Send data to printer - Returns 0 if failed

Could you test it, Terry ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post by TerryHough »

gnozal wrote:Library update

- new function : LPRINT_PrintData()
- help is now CHM (have a look at my new PureHELPMaker tool viewtopic.php?t=13497 :wink:)

Could you test it, Terry ?
Thanks gnozal, the new LPRINT_PrintData() works perfectly for me
as described in previous posts. It is quick!

And I am glad to see the CHM help file. May I suggest you include a
graphic example of the LPRINT_Requester() window to better clarify
the usage of the command.

I am sure many PB users will find your library extremely userful. Thanks
for your effort and contribution to the community.

Terry
NOTE to those interested...
The PureLPRINT library has proved very useful in one of my apps.

I use laser printers to draw literally hundreds of business forms on
demand. These forms require the use of specific fonts that are not
native to the printer and are not readily available as TTF fonts.

The LPRINT_PrintData(*Buffer, Length) made it possible to send the
entire set of 11 fonts to the printer in one brief routine. This overcame
a previous restriction where the fonts could not be sent intact since
they contain NUL characters. Therefore, normal string printing functions
all failed.

Now I can drop the fonts to the selected printer easily. Then I can send
any PCL language based form, follow that with normal data to populate
the form, and print the completed form in an instant.

The PCL code for a particular form could be sent previously using string
based functions. However, since they could easily exceed 64K, the
print routine had to handle them carefully. With the new
LPRINT_PrintData(*Buffer, Length) functions, I can just read the PCL form
file into memory and send it right on to the printer in just a few lines of
code. No reason to break the file into to pieces, so it is MUCH faster.

Thanks to gnozal for his great work with the PureLPRINT library.

TerryHough
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Thanks, glad you find it usefull :D
I use it mostly to convert some old DOS or Powerbasic console (PB/CC) apps where I used LPRINT commands.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Post Reply