It is currently Sun Jul 22, 2018 9:31 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 43 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: PureLPRINT library : LPRINT functions (direct LPT access)
PostPosted: Tue Sep 21, 2004 8:11 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
PureLPRINT Library

Purpose :
Code:
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:
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.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Sep 23, 2004 11:32 pm 
Offline
User
User

Joined: Sat May 10, 2003 1:02 pm
Posts: 85
Location: Germany
Hi,

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

Best regards,
Peter


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Sep 24, 2004 7:59 am 
Offline
Moderator
Moderator
User avatar

Joined: Sat Apr 26, 2003 1:11 am
Posts: 1385
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Sep 24, 2004 10:41 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:51 pm
Posts: 2808
Location: Portugal, Lisbon
Works just fine on Epson printers too...
And Xerox 440 LaserJet

_________________
Software: http://xipa.org
Elevator Maintenance: http://central-elevadores.pt
Good web hosting!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Sep 24, 2004 9:02 pm 
Offline
User
User

Joined: Sat May 10, 2003 1:02 pm
Posts: 85
Location: Germany
Hi,

Quote:
i think thats ok, coz its prints directly to the LPT-port.


im have no LPT Printers im have only USB Printers


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Sep 24, 2004 11:30 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> 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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Sep 25, 2004 10:12 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 17, 2004 3:40 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 6:51 pm
Posts: 778
Location: NC, USA
@gnozal

Found this library very useful today.

Here is a pseudo LPRINT Requester procedure. Maybe you can add this
to this useful library.

Quote:
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:
; 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.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 17, 2004 8:38 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
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 http://forums.purebasic.com/english/vie ... hp?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).


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Dec 17, 2004 9:16 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 6:51 pm
Posts: 778
Location: NC, USA
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.

Quote:
The 64k : are you talking about the string size limit ? It seems to not exist anymore http://forums.purebasic.com/english/vie ... hp?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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Dec 18, 2004 8:38 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
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:
;
#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


Quote:
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).


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Dec 18, 2004 3:14 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 6:51 pm
Posts: 778
Location: NC, USA
@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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 27, 2004 8:49 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
Library update

- new function : LPRINT_PrintData()
- help is now CHM (have a look at my new PureHELPMaker tool http://forums.purebasic.com/english/vie ... hp?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).


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 27, 2004 3:38 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 6:51 pm
Posts: 778
Location: NC, USA
gnozal wrote:
Library update

- new function : LPRINT_PrintData()
- help is now CHM (have a look at my new PureHELPMaker tool http://forums.purebasic.com/english/vie ... hp?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

Quote:
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Dec 27, 2004 3:47 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 8:27 am
Posts: 4229
Location: Strasbourg / France
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).


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 43 posts ]  Go to page 1, 2, 3  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye