PrinterLib 1.10

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PrinterLib 1.10

Post by yrreti »

Hi ABBKlaus

I have a question concerning the best way to handle the following issue. (Please See Code)
I use the value of y to position the row position of the printed lines.
I use your library to send varying amounts of data to be printed out via your library. I have it set so that when ever
the amount printed passes the y > 200 position, a Print_NewPage() is triggered, and the next data is
continued page by page until done. It works great!
If printed data is not greater than the y > 200 position, it works great too.
But,,, if y > 200 position, and a Print_NewPage() is triggered, with no more data to be printed, it either
does nothing, or locks up my printer. What is the best way to handle this or kill the Print_NewPage() that was called
when this happens? Nothing I tried seems to work once the Print_NewPage() is called. I can send blank line data
before calling Print_StopPrinting(), but having it always print out an extra blank unused page when this happens is
irritating to my clients.
Thanks for any help or ideas.
yrreti

The code below uses For x= 1 To 49, 50, 51 to simulate different data amounts being entered to show my problem.

Code: Select all

Procedure Print_This()
  ;Note: You will need to enter your own printer name for selprn$
  selprn$="EPSON WorkForce 610 Series"
  If Print_OpenPrinter(selprn$,"PAPERSIZE="+Str(#DMPAPER_LETTER)+",ORIENTATION="+Str(#DMORIENT_PORTRAIT))
    Print_StartPrinting("MyData")
    Print_Font("Lucida Console",8, #PB_Font_HighQuality)    
    y = 4; initial Y position
    
    ;Notes:
    ;For x= 1 To 49 works fine because it's not greater then 200 and Print_NewPage() is not triggered
    ;and Print_StopPrinting() is called and printer prints one blank page.
    
    ;For x= 1 To 51 works fine because it's more then 200 and Print_NewPage() is triggered,
    ;and more is printed before Print_StopPrinting() is called and printer prints two blank pages.
    
    ;For x= 1 To 50   FAILS and either does nothing or LOCKS UP the PRINTER.
    ;Because it's more then 200, a Print_NewPage() is triggered.
    ;But nothing more is printed before Print_StopPrinting() is called, and the printer either does nothing, 
    ;or locks up and prints nothing. (Obviously waiting for data for the next page.)
    
    For x= 1 To 50
      Print_Text(5,y, "     "):y=y+4 ;printing blank lines to save paper
      ;Print_Text(5,y, "Y count = "+Str(y)):y=y+4
      Debug "x count = "+Str(x)+"    Y count = "+Str(y)
      If y>200 ;setting switch to a new page when it gets above this position value of y
        Print_NewPage()
        y=4
      EndIf
    Next x
    
    ;This stops the print job.
    Print_StopPrinting() ;Ends a print job.
    
  Else
    err$=Print_GetLastError()
    MessageRequester(" Print_StartPrinting()",err$,0)
  EndIf
  
EndProcedure

Print_This()
Last edited by yrreti on Sun Jun 23, 2013 8:22 pm, edited 1 time in total.
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PrinterLib 1.10

Post by ABBKlaus »

Hi yrreti,
calling the command for a newpage and not printing anything on that page is failing Print_StopPreview() !
Its checking for success on EndPage_() api and i guess it Fails.
It is using the same command as in Print_Newpage().

Code: Select all

Procedure.l ipprint_StopPrinting()
  If EndPage_(PrintLib_DC)>0 ; Fails as its already called in Print_NewPage()
    If EndDoc_(PrintLib_DC)>0
      ProcedureReturn #True
    EndIf
  EndIf
  ProcedureReturn #False
EndProcedure
My advice for you is to check for a newpage before printing :

Code: Select all

    For x= 1 To 50
      If y>200 ;setting switch to a new page when it gets above this position value of y
        Print_NewPage()
        y=4
      EndIf
      Print_Text(5,y, "     "):y=y+4 ;printing blank lines to save paper
      ;Print_Text(5,y, "Y count = "+Str(y)):y=y+4
      Print_Font("Lucida Console",8, #PB_Font_HighQuality)
      Debug "x count = "+Str(x)+"    Y count = "+Str(y)
    Next x
BR Klaus
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PrinterLib 1.10

Post by yrreti »

Hi ABBKlaus

That's what I kind of figured. That is exactly what I did in one program I wrote. I ran the data first through
a different Procedure first, using the same code with the Print_ parts removed, to count the number of lines
that would be printed. This had to be done because manipulating code I used in that procedure can affect the
actual lines to be printed from the data sent to it. For example, a data line is too long and needs to be split.
Then I ran it through the printing Procedure and count down from that line count with each line printed.
That way when ever a Print_NewPage() would be triggered to be called, it will only be called if the line count left is
still greater than 0. This takes care of the problem, but requires a lot of extra code. I was just wondering if there
was already a better, simpler way to do it that I was not aware of, to avoid having to use all this extra code.
Some of your other Print_ commands looked like they could be possibly used to do it, but I wasn't sure if I was using
them right, because what ever I tried didn't work.
It's kind of funny in a way, because the odds of having that 'exact line number' that causes that problem in my code
is pretty high against. But then again the quirk of it happening close again can happen. Adding an extra
Print_Text(5,y, "blank line data") before calling Print_StopPrinting(), stops the lock up problem, and the seldom extra
blank unused page that is printed when this happens, really isn't going to hurt them. If they really start complaining
about it, I'll just use the extra code.

Thanks very much for your input and explanation.
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PrinterLib 1.10

Post by yrreti »

Hi ABBKlaus

I'm sorry to bother you with this problem, but I need your help.
I tried to switch to using PB5.2 b5, and found out that they removed the misc lib in the Purelibraries
directory.
http://www.purebasic.fr/english/viewtop ... 13&t=55120
The printer_lib does not work with out the misc file. Is it possible to fix it and
recompile it for use with PB 5.2 ?
I did try the source code method after correcting all the Native types can't be used with pointers,
and added:

Code: Select all

#PrinterLib_Include=1
XIncludeFile #PB_Compiler_Home +"Examples\Printer_Lib\Printer_Lib.pb"
in my main source code. Then it runs and even sends something to the printer.
But the printer just locks up like it's looking for more data and never prints.

I sent you two pm's with the source code after correcting all the Native types can't be used with pointers,
if that can be of some help to you.

Thanks for any help.
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: PrinterLib 1.10

Post by ABBKlaus »

Hi yrreti,

here is the recompiled Version for PB5.20 : http://www.purebasicpower.de/downloads/ ... B52X86.ZIP

But i would consider using the PrinterLib as includefile ;-)

BR Klaus
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: PrinterLib 1.10

Post by yrreti »

Hi ABBKlaus

I can't thank you enough for doing this!
I really appreciate your very useful lib's that you share with others on the forum.
Again, thank you very much!

yrreti
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 »

Got a tricky problem when using Print_DrawText()

For most situations, using Print_DrawText() to get the bounding box first, then using those values to place the text, works absolutely fine. However, I have an odd requirement where the bounding box and text height must not be changed. This sometimes results in a word 'overflow', and that is deemed to be OK, having only the text that fits in the box is the overall requirement. Snag is, Print_DrawText() will clip overflowing text instead of culling it (clip - can be partially seen; cull - cannot be seen). Here is a screenshot:

Image

Print_DrawText(dX, dY, dW, dH, sText, #DT_LEFT | #DT_WORDBREAK)
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 »

....So it was tricky, but I had run out of coffee.... The solution is to compare the required bounding with the text bounding box - if the latter is bigger than the former, remove one line of text and test again. Doh!
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 »

You could Experiment with the following constansts :

Code: Select all

#DT_END_ELLIPSIS | #DT_PATH_ELLIPSIS | #DT_WORD_ELLIPSIS | #DT_EDITCONTROL
http://msdn.microsoft.com/en-us/library ... s.85).aspx
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 »

DT_EDITCONTROL looks interesting......
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 »

There is a significant difference in text height between the PB Font height and the Printer Lib version of the same:
Image

In the lib, Procedure ipprint_Font(), we see this:

Code: Select all

  ;http://msdn.microsoft.com/library/en-us/gdi/fontext_4rw4.asp
  font\lfHeight=(Height*ipprint_GetDeviceCaps(#LOGPIXELSY))/72
MS give a different method here, with reference to the LOGFONT structure

Code: Select all

;http://msdn.microsoft.com/en-us/library/windows/desktop/dd145037%28v=vs.85%29.aspx
lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: PrinterLib 1.10

Post by srod »

Yes without the negative on Windows, the font mapper will include the font's internal leading space in the calculations and thus you will typically end up with an actual font with a somewhat smaller character height than you intended.

Mind you, you are not comparing printed output with screen output are you? Logical inches on large screens are usually always larger than physical inches unless the user has made some weird changes to the display settings. :)
I may look like a mule, but I'm not a complete ass.
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 »

you are not comparing printed output with screen output are you?
Hi sRod - what I have there is the Text at 1:1 in the App, and printed to PDF - The PDF displayed 1:1 on screen too. What minefield printing is!
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 Issue. Print_DrawText() does not take into account the overhang of Italic and/or Bold Font effects (which it could do with Print_GetTextMetrics(#TM_OVERHANG)?)

Code: Select all

        Print_Font("Microsoft Sans Serif", 12, #PB_Font_Bold | #PB_Font_Italic | #PB_Font_HighQuality)
Print_SetTextColor(#Blue)
    Print_DrawText(0, 0, 85.5, 36.8, sMyText, #DT_RIGHT)  ; | #DT_EDITCONTROL)
Print_SetLineColor(#Red)
         Print_Box(0, 0, 85.5, 36.8)
Image

Edit: A good work-around is to add a space char at the end of each line.
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 have a question concerning the best way to handle the following issue.
As an example. I can use your code to print 50 copies of some info, and it sends it to the printer and it works great.
The problem is that after it is sent to the printer, and I realize that I made a mistake in the info I was printing,
is there a way to cancel the print job instead of wasting all 50 sheets?
Maybe the wrong use here, but Print_StopPrinting() or Print_EndDocPrinter() don't work I believe, because it's running
from the printers memory at that point.
I know that you can cancel an on going job in the printer from 'Windows' Printer screen menu, but do you have any suggestions
on how I could do it using your very useful code?
Thanks for any help or ideas.
Post Reply