April 25, 2024, 12:01:59 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Printing

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

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

May 23, 2017, 11:56:26 PM Last Edit: May 24, 2017, 12:07:37 AM by Andy
I'm sure this has been raised before, but this is the first time I have tried printing from IWB!

My printer is an HP Desktop 2130, and it is set to default printer, and yet I cannot use the
WRITEPRINTER command.

I open the printer like this:

   prtname = GETDEFAULTPRINTER
   hPrinter = OPENPRINTER(prtname, "Job 1", "TEXT")

   IF hPrinter

It's reading a simple text file, which I can confirm on screen, and yet nothing is printed, hPrinter returns 0 (zero) which means it failed to open the printer - does that mean my printer is not supported?

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

Hi Andy

Struggling with a similar problem here. The only difference is that I am using a HP1210 printer.
I finally  managed to print out plain text with the code below, but still have to find a way to set the margins.
The sub is coded with CB (a modified version of an example found in the old IB Std Archive). Just put an ENDSUB at  the end, and it will work with IWB.

Maybe this can help you a little step further?


Egil


'
SUB PrintItem(wnd:window,ID:int)
'-------------------------------------------------------------------------------------
' Print selected Item
' ID = The Edit Control containing the text to print
'-------------------------------------------------------------------------------------
DEF buffer2[32766]:ISTRING
DEF printer:STRING
DEF startpg,endpg,copies,collate,hprinter:INT
startpg = 1 : endpg = 1 : copies = 1 : collate = 1

printer = PRTDIALOG(wnd,startpg,endpg,copies,collate)
hprinter = OPENPRINTER(printer,"Document","TEXT")

if(hprinter)
buffer2 = getcontroltext(wnd,ID)
WRITEPRINTER hprinter, buffer2
CLOSEPRINTER hprinter
endif

RETURN




Support Amateur Radio  -  Have a ham  for dinner!

LarryMc

Quote from: Andy on May 23, 2017, 11:56:26 PM
yet nothing is printed, hPrinter returns 0 (zero) which means it failed to open the printer - does that mean my printer is not supported?


It could mean your printer is configured for printing directly to the printer.  That will cause the same thing.   I duplicated that on my printer.
When I set it up to use the printers buffer then it returned the printers name and the printer command worked.
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,

Thanks for that, so is it a windows / printer setting somewhere? how do I change this?

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

LarryMc

It COULD be a printer SETTING - in win7 it would be found START/Devices and Printers then select your printer.  On my HP is was under the Advanced tab.
If it is not a SETTING it COULD be the DESIGN of your printer and you are just out of luck as for as I know.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Thanks Larry,

I will have a look now.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

@Egil
When I was working on the module to to allow the IWBasic IDE user to printout code and preview it first and set the font, color, and margins I had to jump through all kinds of hoops to get it to work.  I had to print it to hidden windows and use Listviews and such and it took around 1300 lines of code in one module(multiple subroutines) and there's probably some support routines scattered around outside that module.
It was so complicated and I haven't looked at it in so long I don't even know if I could figure out how it works right now. LOL.
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,

I found some of your code from this thread:
http://www.ionicwind.com/forums/index.php?topic=3044.msg25070#msg25070

It does indeed see my printer but there are 2 differences:

1. Does not return the printer's status.
2. On the output screen I get PrintProcessor as winprint not a hp one.

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

Egil

Quote from: LarryMc on May 24, 2017, 10:06:33 PM
@Egil
When I was working on the module to to allow the IWBasic IDE user to printout code and preview it first and set the font, color, and margins I had to jump through all kinds of hoops to get it to work.  I had to print it to hidden windows and use Listviews and such and it took around 1300 lines of code in one module(multiple subroutines) and there's probably some support routines scattered around outside that module.
It was so complicated and I haven't looked at it in so long I don't even know if I could figure out how it works right now. LOL.

LarryMc,
That really sounds complicated. But at least the CB code I posted, prints to my rather cheap printer. The only thing I miss is being able to specify margins. But that is something I'll try to figure out.



Support Amateur Radio  -  Have a ham  for dinner!

Andy

On my machine the printer driver is winprint not HP's.

Done the usual things such as trying to change the driver to HP Deskjet 2130 - no joy.
Downloaded the HP driver for it (which is an exe file by the way), but when I browse to what I think is the USB driver for it, it says it's not for 32 bit machines - although you do not get an option for 32 bit machines.

Help / suggestions anyone please!
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 you read the WRITEPRINTER page in the help file? WRITEPRINTER doesn't work with GDI-only printers

Brian

Andy

May 25, 2017, 07:42:05 AM #11 Last Edit: May 25, 2017, 07:43:52 AM by Andy
Hi Brian,

Yes I read that, maybe this one is a GDI only printer?, just thought I would try as LarryMc's example on this post was also a HP.

Notepad prints, the example editor program sees the printer so you can select it - but no joy.

But I can print from the IWB IDE!
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Brian

Andy,

This example from peterpuk works for me. I'm printing the output to a PDF printer, to save ink and paper

Brian

Andy

Brian,

Thanks for the code, it actually printed! - shows up in the printer job queue and of it goes!

I'm going to have to study this one, but thanks again.

Andy. :)


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

Brian

I agree with that - it DOES need a lot of studying! How practical the code is in the
real world is debatable, but it does prove your printer works, I guess

Brian

Egil

May 26, 2017, 04:27:44 AM #15 Last Edit: May 26, 2017, 04:30:00 AM by Egil
Quote from: Brian Pugh on May 26, 2017, 02:27:24 AM
How practical the code is in the real world is debatable, but it does prove your printer works, I guess

Brian,

That code is full of  good ideas, that ought to be be practical enough for most of us!
I have used most of my time this week trying to figure out how to set margins when printing text my own printer, and the code you posted showed me how. The API calls to GetDeviceCaps produce exactly what I want!

Thanks for sharing.


Egil
Support Amateur Radio  -  Have a ham  for dinner!

Andy

May 27, 2017, 04:58:27 AM #16 Last Edit: May 27, 2017, 05:00:01 AM by Andy
I've made a few changes to the program Brian shipped over.

1. I've put the printing section into a sub routine PrintTheDoc.
2. The MakeFont sub routine has an optional value for italics.

That is:

bigfont=MakeFont("Arial",30,1) - where the 1 specifies use italics, otherwise use
bigfont=MakeFont("Arial",30) - no italics.

This program reads a text file, and prints the data line by line.

I would suggest you print to pdf and then open it to check how it's come out.

Please let me know how it looks on your machine - if the lines of data are not correct, change the
myx value to something else - the bigger the number, the further across the page it goes.

Attached is the program and the text file it reads.

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

Andy

May 28, 2017, 12:13:37 AM #17 Last Edit: May 28, 2017, 01:39:20 AM by Andy
I noticed when playing around with this printing program that sometimes (for no reason) the output
could be printed at an angle, sometimes underlined, even upside down!

Then I spotted this line:
def fnt:logfont

It was buried inside a sub routine, so I moved it to just after logfont is declared (at the top of the code).

As far as I can see (on my PC) the printing is now behaving itself.

Would someone please test it for me!
Send the output to PDF to save ink.
Attached are the files.

Thanks.


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

Egil

Hi Andy,

This is how it prints here.


Egil

Support Amateur Radio  -  Have a ham  for dinner!

Andy

May 28, 2017, 02:28:26 AM #19 Last Edit: May 28, 2017, 02:37:33 AM by Andy
Egil,

Thanks for trying it, it's okay on my pc, but it looks like there is some difference between yours and mine.

Wonder why printing to a pdf would show a difference?

Anyway, in the PrintTheDoc sub routine - line 195, if you change the value of myx i.e. increase the value to say 800 or 1000 it should move the lines across the page.

Also, you could change the number of data lines per page say from 27 to 20?

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,

Been experimenting with the x and y values to see what happened with the positioning of the printed text. Also used another textfile for testing.
It then appeared that all printed text was senter aligned, regardless of what alignment the original text had. Also  printed to paper a couple of times, and the result was the same as with the PDF driver. (Bullzip PDF Printer).

I am also a little confused about the units used for the x and y values ( pixels or twips). I assume you mean pixels???

You posted while I was writing the above text. And your suggestions was exactly what I did for my experiments.
If I remember it right 1440 twips = 1 inch. So I'll experiment a little assuming the units should be i twips.



Egil
Support Amateur Radio  -  Have a ham  for dinner!

Egil

Copied my last post into NotePad to make a new test file.
Then I changed the x value and the font size before compiling and printing. The result is shown below.

Suggest that a variable specifying the maximum allowed length of any line, when considering the margins, and then fill the line with as many words there is room for, then print the line, and repeat this until the whole document is printed.

In MiniBasic the RichEdit controll class has a member doing just that. It is called with the margin value in twips. Very easy for the users.... ::)
Support Amateur Radio  -  Have a ham  for dinner!

Andy

Hi Egil,

Thanks again for testing!

I'd never heard of twips before, this printing business came about because the person who wanted the login program for the school wanted a print button on the screen so he could print off a log file.

In this instance, each line is short, but in view of the differences we are seeing, I've put in some fields so he can change the X offset, font sizes, and number of lines per page.

I will have to guide him with these values, and wait to see how he gets on with printing as I do not know what printers they have at the school.

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

Egil

OK Andy,

Have you received the emails I sent you?

Egil
Support Amateur Radio  -  Have a ham  for dinner!

Andy

May 28, 2017, 05:16:42 AM #24 Last Edit: May 28, 2017, 05:22:12 AM by Andy
Hi Egil,

Partly my fault, forgot to tell you my new email address!

If you click on my name it shows the new one, however gone into the old ones and just reading them now.

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