April 25, 2024, 08:40:05 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Printing

Started by Andy, May 23, 2017, 11:56:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Egil

Quote from: Andy on May 28, 2017, 04:34:30 AM
I'd never heard of twips before,

It's a typographical term, very often used when setting up printers. Maybe Brian know more about that.
Here is what Wikipedia says: https://en.wikipedia.org/wiki/Twip.


Egil
Support Amateur Radio  -  Have a ham  for dinner!

billhsln

Just a thought, you could set up your output in an RTF document and then print from Word.  Using CreateComObject, you should be able to adjust margins and other stuff and then print the RTF.

I have used the CreateComObject to read an Excel spread sheet and I know there is a way to work with Word files using this.

Of course, this brings up another question from me, can you put a picture in an RTF directly?

Bill
When all else fails, get a bigger hammer.

Andy

Bill,

Thanks for that, already had a button to open it in notepad but the person wanted it printing directly from the program I wrote for him.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Egil

Andy,

Must be getting old here. Was out walking the dog, and all the fresh air usually clears my mind...

Many years ago I struggled when trying to make a print routine with EB, very similar to the printing job you are doing. Now I remember that it was solved by importing readings from an external sensor into a RichEdit Control, and  sending the resulting list to a printer using @RTPRINT.

Can't find that source code, but look up @RTPRINT in the IWB user manual and use the example shown there when your "Print" button is clicked.


Egil
Support Amateur Radio  -  Have a ham  for dinner!

LarryMc

Andy
There is a way to get they x,y offsets of a printer without knowing the type of printer in advance.
Here is the subroutine I wrote for the IWBasic IDE that gets the User's default (selected) printer's info  for setting of the print preview and printout  functions.  You might be able to study and use this.

TYPE SPRINTDLG,1
    DEF lStructSize as UINT
    DEF hwndOwner as UINT
    DEF hDevMode as UINT
    DEF hDevNames as UINT
    DEF hDC as UINT
    DEF Flags as UINT
    DEF nFromPage as WORD
    DEF nToPage as WORD
    DEF nMinPage as WORD
    DEF nMaxPage as WORD
    DEF nCopies as WORD
    DEF hInstance as UINT
    DEF lCustData as UINT
    DEF lpfnPrintHook as POINTER
    DEF lpfnSetupHook as POINTER
    DEF lpPrintTemplateName as POINTER
    DEF lpSetupTemplateName as POINTER
    DEF hPrintTemplate as UINT
    DEF hSetupTemplate as UINT
ENDTYPE


sub getprinterdefault()
DEF strPrinter[32] as ISTRING
strPrinter[0] = NULL
SPRINTDLG pd
ZeroMemory(pd,LEN(SPRINTDLG))
pd.lStructSize = LEN(SPRINTDLG)
pd.nCopies=1
pd.Flags = PD_RETURNDC|PD_RETURNDEFAULT
PrintDlg(pd)
_fpreset()
IF pd.hDevNames
ppDZL = GetDeviceCaps(pd.hdc,PHYSICALOFFSETX)     ' this is x offset - set to left margin
ppDZR = ppDZL                                                               ' set right margin to same as left
ppDZT = GetDeviceCaps(pd.hdc,PHYSICALOFFSETY)     ' this is y offset - top margin
ppDZB = ppDZT                                                               ' set bottom margin to same as top
ppPrnPPI_x = GetDeviceCaps(pd.hdc,LOGPIXELSX)       ' this is x pixels per inch
ppPrnPPI_y = GetDeviceCaps(pd.hdc,LOGPIXELSY)       ' this is y pixels per inch
/* you don't need this part
pointer pString = GlobalLock(pd.hDevNames)
pointer pTemp = pString
pString += #<DEVNAMES>pString.wOutputOffset
strPrinter = #<STRING>pString
if(strPrinter[0] <> "\\")
pTemp += #<DEVNAMES>pTemp.wDeviceOffset
strPrinter = #<STRING>pTemp
endif
setcontroltext ppwin,ppwin_eSelectedPrinter,strPrinter
GlobalFree(pd.hDevNames)
*/
ENDIF
ENDSUB
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Larry,

Got my head around the code - thanks.

I'm now trying to work out how many printable lines on an A4 page.

That is, for each line the font could be say.... 12.

Given the printable width and height (in inches) and the font (in points), how do you calculate how many lines you could actually print?

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Egil

May 29, 2017, 08:04:58 AM #31 Last Edit: May 29, 2017, 08:13:25 AM by Egil
Quote from: Andy on May 29, 2017, 06:49:01 AM
how do you calculate how many lines you could actually print?

The easiest way will be to use GETTEXTSIZE to get the height of the characters and divide available height with it.

Egil
Support Amateur Radio  -  Have a ham  for dinner!

LarryMc

Egil is right.
But you'll have to address word wrap.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy


I've used gettextsize and it returns a value of 22 pixels in height when using the same size font as printing.

The page height in inches is 11
In pixels the height is 6,600   
Printable lines 300? - I could go for 30 but not 300?  ???

Inches:
pphmm * 0.0393701   (where pphmm is height in millimeters)

Inches to pixels:
(pphmm * 0.0393701) * ydpi  (where ydpi = 600)

Printable lines:
((pphmm * 0.0393701) * ydpi) / tHeight  (where tHeight is 22)

I must be going wrong somewhere!



Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

Have a look at this code - it's from the  master, Sapero. It might help you, or just confuse you!

The resulting box is the right dimension on my screen

Brian

Andy

Biran,

Thanks for finding the code - he was indeed the master.

Actually, I find it rather easy to understand - for once!

I'll play around with it.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

Well, still working on some aspects of printing.

With the code Brian and Larry have posted, I've cobbled together a library file called:

PrinterDetails.

Copy the lib file to the IWBDev\Libs folder and compile the iwb code.

Does anyone think this could be useful?

It may take a second or so to return some details.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

It's "Jobs in the Garden" day today, so I will look at your lib later, but a SepFile is a string that specifies the name of the file used to create the separator page. This page is used to separate print jobs sent to the printer

Brian

ckoehn

Andy,

I haven't looked at your library, but IWBasic needs a printer library.  Including a printer graphics library. All this could be included if there is a printer DC that is available, which it looks like there is.  I would work on it, but the chemo messed my nerve endings up and its hurts to type very much.  Can't tell when I'm pressing a key either so there is a lot of back spacing.

Later,
Clint

Andy

Brian,
Don't let those weeds grow too much.

Clint,
Glad to hear from you, take it easy!

I will look at adding more in tomorrow when l'll have more time including the DC.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

Here's a way of enumerating all printers, posted by Michael Hartlef about 10 years ago, I've tidied it up for use with IWB, and changed a few things

I've also added in the method of getting your Default Printer, as well, so you could ask for the default printer, and use the return string when setting up the printer DC

Brian

(Lawns cut, edges strimmed, weedkiller down, car vacuumed, tomato plants watered - Good boy!)

Andy

Brian,

All that and the gardening done, someone's going to get brownie points at home.

Enumerating printers begs the question - should we only be looking for physical printers?

In Devices and Printers (Control Panel) I have 4 printers listed, but only one is a physical printer, the HP, the others are:

Fax,
Microsoft print to PDF
Microsoft XPS document writer

Should we ignore these others?

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

I suppose the quick answer is: Depends where you want to print to!

I've been using the PDF driver lately

Brian

Andy

Well, I've got this far up to now....



OpenThePrinter("MyDocument") 'Also returns uint of printer DC

PrintLine(1000,800,"This is a line - Page 1","")
PrintLine(1000,900,"This is second line","")

   NewPage()

PrintLine(1000,800,"This is first line - Page 2","")
PrintLine(1000,900,"And this is second line","")

CloseThePrinter()


Working on the fonts and sizes next.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

June 04, 2017, 06:20:29 AM #44 Last Edit: June 04, 2017, 07:28:16 AM by Andy
Here is the next part.

Copy the lib folder to the IWBDev\libs folder.

In the IWB source file, read from ***** Part 2 *********

This is giving some basic line printing, and able to set fonts, and sizes.

You may have to play around with the X and Y's:

PrintLine(1000,800,"This is a line - Page 1","")

Where PrintLine is (X across, Y down, Text to print,"")

Again, I would suggest you print to PDF to save ink.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

ckoehn

Keep up the good work Andy.  The "lib" include and "External" lines could be put in an "inc" file.  Then all you would have to do is "#include "Printer.inc".

Later,
Clint

Andy

Thanks for that Clint.

Yes I forgot about an include file, so that will be next on the list.

Cheers.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

Just been messing with changing font names, and I can't get it to change at all, even to common fonts like Times New Roman or Arial

Going out for the afternoon now - sorry

Brian

Andy

Enjoy the afternoon!

I will look at the font issue tomorrow.

Thanks for having a look.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

I found the font problem.

1. I needed to return a UINT value instead of an INT.

2. The LOGFONT define is wrong!

I looked at all the examples and they all say:
CHAR lfFaceName[LF_FACESIZE]

I changed it to a string:
STRING lfFaceName

Now the fonts work.

So LOGFONT should look like this (just in case you use it):

TYPE LOGFONT
INT lfHeight
INT lfWidth
INT lfEscapement
INT lfOrientation
INT lfWeight
CHAR lfItalic
CHAR lfUnderline
CHAR lfStrikeOut
CHAR lfCharSet
CHAR lfOutPrecision
CHAR lfClipPrecision
CHAR lfQuality
CHAR lfPitchAndFamily
string lfFaceName
ENDTYPE



Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.