PrinterLib 1.10

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

The image needs to be around 2mm smaller (Width and Height) than the page (approx 9pix smaller). Strange but true - even if I could ask Adobe for the logic behind that, I probably would not want to :)

Thank you again for your help ABBKlaus.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

....another odd thing though is that 32bit images fail. 24bit is fine and that is all I need anyway, no doubt useful info for others though.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Re: PrinterLib 1.10

Post by Polo »

Any chance for a cross platform version of this? :)
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

Any chance for a cross platform version of this?
It is using a Windows API, so that is unlikely.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PrinterLib 1.10

Post by yrreti »

Hi ABBKlaus
I really appreciate your library, and use it a lot in my programs.
But recently I saw need to be able to check the status of the list of installed printers,
so as to indicate any that were not available for use in the selection.
For example: printer is turned off, out of paper, paper jammed, out of ink, etc.
I tried using your Print_GetStatus(#PRINT_STATUS) to try to get that info, but all I get is
status = 0,
and Debug Print_GetLastError() always gives the message:
"The data area passed to a system call is too small" , even on valid online printers.
When I use the #PRINT_ATTRIBUTES type, it works fine. Different attributes are listed.
(I'm using PB4.61 on XP Pro)

I think I'm using the command right, but if not, could you please correct me as to
what I'm doing wrong? Thank you very much for any help or ideas.

I used the following code for trying to get this info.
I select the test printer by commenting or un commenting out.

Code: Select all

selprn$="Canon i550"  ;valid printer  but turned off
;selprn$="WorkForce 610(Network)"  ;valid network printer  online and working
;selprn$="Brother HL-1440 series"  ;valid network printer  out of paper
;selprn$="false printer test"

If Print_OpenPrinter(selprn$,"PAPERSIZE="+Str(#DMPAPER_LETTER)+",ORIENTATION="+Str(#DMORIENT_PORTRAIT),#PRINTER_ALL_ACCESS)
  status=Print_GetStatus(#PRINT_STATUS)
  If status<>0
    If status & #PRINTER_STATUS_BUSY
      Debug "#PRINTER_STATUS_BUSY"
    EndIf
    If status & #PRINTER_STATUS_DOOR_OPEN
      Debug "#PRINTER_STATUS_DOOR_OPEN"
    EndIf
    If status & #PRINTER_STATUS_ERROR
      Debug "#PRINTER_STATUS_ERROR"
    EndIf
    If status & #PRINTER_STATUS_INITIALIZING
      Debug "#PRINTER_STATUS_INITIALIZING"
    EndIf
    If status & #PRINTER_STATUS_IO_ACTIVE
      Debug "#PRINTER_STATUS_IO_ACTIVE"
    EndIf
    If status & #PRINTER_STATUS_MANUAL_FEED
      Debug "#PRINTER_STATUS_MANUAL_FEED"
    EndIf
    If status & #PRINTER_STATUS_NO_TONER
      Debug "#PRINTER_STATUS_NO_TONER"
    EndIf
    If status & #PRINTER_STATUS_NOT_AVAILABLE
      Debug "#PRINTER_STATUS_NOT_AVAILABLE"
    EndIf
    If status & #PRINTER_STATUS_OFFLINE
      Debug "#PRINTER_STATUS_OFFLINE"
    EndIf
    If status & #PRINTER_STATUS_OUT_OF_MEMORY
      Debug "#PRINTER_STATUS_OUT_OF_MEMORY"
    EndIf
    If status & #PRINTER_STATUS_OUTPUT_BIN_FULL
      Debug "#PRINTER_STATUS_OUTPUT_BIN_FULL"
    EndIf
    If status & #PRINTER_STATUS_PAGE_PUNT
      Debug "#PRINTER_STATUS_PAGE_PUNT"
    EndIf
    If status & #PRINTER_STATUS_PAPER_JAM
      Debug "#PRINTER_STATUS_PAPER_JAM"
    EndIf
    If status & #PRINTER_STATUS_PAPER_OUT
      Debug "#PRINTER_STATUS_PAPER_OUT"
    EndIf
    If status & #PRINTER_STATUS_PAPER_PROBLEM
      Debug "#PRINTER_STATUS_PAPER_PROBLEM"
    EndIf
    If status & #PRINTER_STATUS_PAUSED
      Debug "#PRINTER_STATUS_PAUSED"
    EndIf
    If status & #PRINTER_STATUS_PENDING_DELETION
      Debug "#PRINTER_STATUS_PENDING_DELETION"
    EndIf
    If status & #PRINTER_STATUS_POWER_SAVE
      Debug "#PRINTER_STATUS_POWER_SAVE"
    EndIf
    If status & #PRINTER_STATUS_PRINTING
      Debug "#PRINTER_STATUS_PRINTING"
    EndIf
    If status & #PRINTER_STATUS_PROCESSING
      Debug "#PRINTER_STATUS_PROCESSING"
    EndIf
    If status & #PRINTER_STATUS_SERVER_UNKNOWN
      Debug "#PRINTER_STATUS_SERVER_UNKNOWN"
    EndIf
    If status & #PRINTER_STATUS_TONER_LOW
      Debug "#PRINTER_STATUS_TONER_LOW"
    EndIf
    If status & #PRINTER_STATUS_USER_INTERVENTION
      Debug "#PRINTER_STATUS_USER_INTERVENTION"
    EndIf
    If status & #PRINTER_STATUS_WAITING
      Debug "#PRINTER_STATUS_WAITING"
    EndIf
    If status & #PRINTER_STATUS_WARMING_UP
      Debug "#PRINTER_STATUS_WARMING_UP"
    EndIf
  Else    
    Debug Print_GetLastError()
    ;I always get the message:    The data area passed to a system call is too small.
  EndIf 
Else
  Debug Print_GetLastError()
EndIf

ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PrinterLib 1.10

Post by ABBKlaus »

yrreti wrote:Hi ABBKlaus
I really appreciate your library, and use it a lot in my programs.
But recently I saw need to be able to check the status of the list of installed printers,
so as to indicate any that were not available for use in the selection.
For example: printer is turned off, out of paper, paper jammed, out of ink, etc.
I tried using your Print_GetStatus(#PRINT_STATUS) to try to get that info, but all I get is
status = 0,
and Debug Print_GetLastError() always gives the message:
"The data area passed to a system call is too small" , even on valid online printers.
When I use the #PRINT_ATTRIBUTES type, it works fine. Different attributes are listed.
(I'm using PB4.61 on XP Pro)

I think I'm using the command right, but if not, could you please correct me as to
what I'm doing wrong? Thank you very much for any help or ideas.
Hi yrreti,
you are doing nothing wrong, status = 0 means there is no status available (offline or virtual printer).
The errormessage you are retrieving is normal because i do not reset the last error, it comes from the call to GetPrinter_() to get the correct buffersize.

I think you should have a look into "Example07 Get Printer Status.pb", it works here perfectly with a "HP Officejet Pro 8500 A910".

Code: Select all

Printer-Lib Version V1.10
PureBasic Version 461
Printer : HPD134CF (HP Officejet Pro 8500 A910)
OpenPrinter_()=1
Print_SetTextAlign(0)
SetTextAlign_(4211253,0)=0
Print_SetBkMode(1)
SetBkMode_(4211253,1)=2
Print_SetLineColor(0)
Print_CreatePen(12200,0,0,0,0)
ExtCreatePen_(12200,5,18FEFC,0,0)=EE501649
Print_CreateBrush(0)
CreateSolidBrush_(0)=FF101451
Print_CreatePen(12200,0,0,0,0)
ExtCreatePen_(12200,5,18FF04,0,0)=835013CC
Status=16
Attribute=2624
#PRINTER_STATUS_PAPER_OUT
#PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST
#PRINTER_ATTRIBUTE_ENABLE_BIDI
#PRINTER_ATTRIBUTE_LOCAL
BR Klaus
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PrinterLib 1.10

Post by yrreti »

Thanks for the reply and the explanation about the error message.
I saw in your comments, that you do have a status message listed.
But I am puzzled? I am using the code from your "Example07 Get Printer Status.pb"
I just added the printer name in selprn$ so I could test my different printers, and didn't use the
attr=Print_GetStatus(#PRINT_ATTRIBUTES) part of the code, also to make the pasted code
here smaller. But even when I use the complete Example07, except for adding the printer names,
I still don't get any status? I do get the attribute messages fine, just no status messages?
Closer examination revealed that I'm using a Virtual printer port for usb for the Canon printer,
with printer pooling unchecked.
One thing I did notice though, is that with the Canon printer turned off, I get the attr message:
[07:09:54] #PRINTER_ATTRIBUTE_WORK_OFFLINE . So I thought that maybe I could just use
that. But with the Brother printer turned off, I get no change? It is connected with a lan server.
The WorkForce printer is connected by wifi, and shows no change either?
Is there anything I could possibly check? Why it works with your printer and not mine is really
puzzling. I did try reinstalling and using your latest Printer_lib1.10 to eliminate problems there,
but there was no change. If there is a problem with the code somewhere, it definitely would be
nice to get this part fixed if possible, but even if not, I really do like your programs!
Thanks for your help and reply.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

Hi
Still having issues getting the info set by the User via the printer dialog:

Code: Select all

#Win = 0

   sOpt1.s = "ORIENTATION=" + Str(#DMORIENT_PORTRAIT) + Chr(44) + "PAPERSIZE=" + Str(#DMPAPER_A4) + Chr(44) + "PAPERLENGTH=297" + Chr(44) + "PAPERWIDTH=210" + Chr(44) + "SCALE=1" + Chr(44) + "COPIES=1" + Chr(44) + "DEFAULTSOURCE=" + Str(#DMBIN_AUTO) + Chr(44) + "PRINTQUALITY=" + Str(#DMRES_HIGH) + Chr(44) + "COLOR=" + Str(#DMCOLOR_COLOR) + Chr(44) + "COLLATE=" + Str(#DMCOLLATE_TRUE)
   sOpt2.s = "FLAGS=" + "NFROMPAGE=1" + Chr(44) + "NTOPAGE=" + Str(igPageCnt) + Chr(44) + "NMINPAGE=1" + Chr(44) + "NMAXPAGE=999" + Chr(44) + "NCOPIES=1"
sJobName.s = "PP_" + Str(Date())

        hDC = Print_PrintDlg(#Win,Print_GetDefaultPrinter(),sOpt1,sOpt2)

                 *PrintInfo.PRINTDLG = Print_GetPrintDlg()
                 Debug *PrintInfo\nFromPage
                 Debug *PrintInfo\nToPage
                 Debug *PrintInfo\nCopies
                 Debug Print_GetPrinterName()
                 Debug GetDeviceCaps_(hDC,#HORZRES)
                 Debug GetDeviceCaps_(hDC,#VERTRES)
                 Debug Print_GetDeviceCaps(#HORZRES)
                 Debug Print_GetDeviceCaps(#VERTRES)

End
In the above example, *PrintInfo\nCopies always returns 1 and Print_GetPrinterName() always returns the default printer, not the printer selected in the dialog? Also GetDeviceCaps always returns 0.
I see from your website that you have made a non-tail-bitten version available, but that does not have Print_GetPrintDlg(). As only an occasional user of the PrinterLib, I get myself horribly confused!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

Still can't get the selected printer, but I can get the DC vals:

Code: Select all

#Win = 0
#Prt = 1

If OpenWindow(#Win,0,0,200,200,"Test",#PB_Window_SystemMenu|#PB_Window_TitleBar)

         sOpt1.s = "ORIENTATION=" + Str(#DMORIENT_PORTRAIT) + Chr(44) + "PAPERSIZE=" + Str(#DMPAPER_A4) + Chr(44) + "PAPERLENGTH=297" + Chr(44) + "PAPERWIDTH=210" + Chr(44) + "SCALE=1" + Chr(44) + "COPIES=1" + Chr(44) + "DEFAULTSOURCE=" + Str(#DMBIN_AUTO) + Chr(44) + "PRINTQUALITY=" + Str(#DMRES_HIGH) + Chr(44) + "COLOR=" + Str(#DMCOLOR_COLOR) + Chr(44) + "COLLATE=" + Str(#DMCOLLATE_TRUE)
         sOpt2.s = "FLAGS=" + "NFROMPAGE=1" + Chr(44) + "NTOPAGE=" + Str(igPageCnt) + Chr(44) + "NMINPAGE=1" + Chr(44) + "NMAXPAGE=999" + Chr(44) + "NCOPIES=1"
      sJobName.s = "PP_" + Str(Date())

             hDC = Print_PrintDlg(#Prt,Print_GetDefaultPrinter(),sOpt1,sOpt2)

                 *PrintInfo.PRINTDLG = Print_GetPrintDlg()
                 Debug *PrintInfo\nFromPage
                 Debug *PrintInfo\nToPage
                 Debug *PrintInfo\nCopies
                 Debug Print_GetPrinterName()

                 hDC = Print_OpenPrinter(Print_GetPrinterName())
                 Debug Print_GetPrinterName()
                 Debug GetDeviceCaps_(hDC,#HORZRES)
                 Debug GetDeviceCaps_(hDC,#VERTRES)
                 Debug Print_GetDeviceCaps(#HORZRES)
                 Debug Print_GetDeviceCaps(#VERTRES)

EndIf

End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

If you Google it, you will find there are a number of discussions about the MS PrintDlg() function. MSDN itself recommends using PrintDlgEx or PageSetupDialog(). According to the various discussions, it seems that the example published by MS does not work correctly - certainly sounds plausible since the example is no longer available.

Concerning the number of printed copies thing, this is a known issue: If PD_RETURNDC is set but PD_USEDEVMODECOPIESANDCOLLATE flag is not set, the PrintDlgEx and PrintDlg functions return an incorrect number of copies. To get the correct number of copies, ensure that the calling application always uses PD_USEDEVMODECOPIESANDCOLLATE with PD_RETURNDC. I suspect that maybe the printer lib does not use the flag PD_USEDEVMODECOPIESANDCOLLATE, for two reasons - firstly, it is listed in some places as having the same value as PD_USEDEVMODECOPIES, and secondly it's not recognized by PB.

Edit: nCopies contains the number of copies if the printer driver does not support multiple copies. Otherwise it is set to one. So in fact it is working correctly - if the driver handles multiple copies, nCopies = 1 and the app just needs to send the document once. If the driver does not support multi-copies, nCopies returns the number of copies selected by the User and the app must send the document n times to make copies.

So, I am nearing to the conclusion that I may have to write my own dialog instead, though I really don't want to! I'm wondering if that should be as a separate app, because if it were coded in another language it could be cross-platform. I wonder how Adobe does it for PDF for example.... up till now, my use of PrintLib had been for my work only when printing to a device, else I have been printing to a PDF engine and that works well on my machine because the engine is the default printer and I am only printing images.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

Print_GetPrinterName() always fails on my PC, but the following procedure by netmaestro works perfectly:

Code: Select all

Procedure.s GetSelectedPrinter()
;-------------------------------
  Protected sPrinterName.s, PrintDlg.PRINTDLG, *DEVNAMES.DEVNAMES

  With PrintDlg

          \lStructSize = SizeOf(PRINTDLG)
                \Flags = #PD_ALLPAGES 
  EndWith

  PrintDlg_(PrintDlg)

  *DEVNAMES = GlobalLock_(PrintDlg\hDevNames)
  sPrinterName = PeekS(*DEVNAMES + (*DEVNAMES\wDeviceOffset * SizeOf(Character))) ;wDeviceOffset is in characters, not bytes

  GlobalUnlock_(PrintDlg\hDevNames)
    GlobalFree_(PrintDlg\hDevNames)

  ProcedureReturn sPrinterName

EndProcedure
Edit: The cause of Print_GetPrinterName() failing is Compiler Unicode Mode :?
Last edited by IdeasVacuum on Sat Sep 15, 2012 1:46 am, edited 1 time in total.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

IMA:

Print_AdvancedProperties(Win.i) pops-up the current printer's advanced properties panel correctly, but if the User clicks the OK button on that form, it crashes.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

Hi ABBKlaus

Quick question:

Print_Image(Imagenr.l, x.f, y.f [, w.f, h.f])

What units of measure are those float values meant to be in?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PrinterLib 1.10

Post by ABBKlaus »

If i remember correctly it defaults to mm, if you havent used Print_SetUnit() before.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PrinterLib 1.10

Post by IdeasVacuum »

Thanks ABBKlaus, your memory is indeed in good working order!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply