Which FPC are you using on windows 7? Could be one of the following three
editions: go32v2/win32/win64 ?
Note that go32v2(dos) is not supported/recommended on NT based windowses
(NT4/2k/2k3/xp/vista/w2k8/w7).
Make sure the printer is shared, and then use the following command to
redirect LPT2 to the printer:
net use LPT2: \\computername\printername /persistent:yes
Replace 'computername' with your computer name, and 'printername' with
the share name of your printer. After you've run the command, you
should be able to use InitPrinter('LPT2') in your program.
BTW, you want to use LPT2 since from what I've read, if the printer
port actually exists, Vista and Windows 7 won't let you redirect to
it.
Hope this helps.
--
Zaphod
Arthur Dent, speaking to Trillian about Zaphod:
"So, two heads is what does it for a girl?"
"...Anything else he's got two of?"
There is no local network involved. My printer is connected directly
to my PC. I tried that NET command, but it was not recognized.
The one for Dos, or the win32 one?
You don't need a local network for that approach to function (but you
do need file and printer sharing turned on), and the it was designed
for printers connected directly to a PC so it should work for your
situation. That said, I would have expected the NET command to give
an error rather than not being recognized (unless it gets installed
when file and printer sharing is enabled or some such). I don't have
a Windows 7 computer immediately available to check, so I can't really
say what might be happening. In XP and Vista, it "just works" for me.
--
Zaphod
Arthur: All my life I've had this strange feeling that there's
something big and sinister going on in the world.
Slartibartfast: No, that's perfectly normal paranoia. Everyone in the
universe gets that.
I am a little mystified by all of this. Printing works from every
other program, from Notebook, PE32, Internet Explorer, Microsoft
Office, and FTPrint. It is only my FPC programs that can't print. I
would have thought that if the problem was with my home network then
nothing would print.
I found out what my computername is, but I don't know where or how to
find out or to assign the printername
They don't try to print through a legacy TP Dos interface.
> It is only my FPC programs that can't print. I
> would have thought that if the problem was with my home network then
> nothing would print.
How did you get the USB001 name? Because for this to work, a USB001 dos
compatibility device must have been created.
> I found out what my computername is, but I don't know where or how to
> find out or to assign the printername
Windows Start > Control Panel > Printers and Faxes
--
Chris Burrows
CFB Software
http://www.cfbsoftware.com
I went to Control Panel, Dwevices and Printers, (my printer),
Customize Your Printer, and then clicked on the Ports tab. It had a
list of LPT1, LPT2, LPT3, COM1, etc, but none of those were associated
with any printer, then it had USB0001 marked "Virtual port for (my
printer)" Since that was the only port associated with a printer, I
selected that one.
I tried running a test program without InitPrinter and with InitPrinter
('LPTx') and InitPrinter('COMx') for all the possible values of x, but
every one of those runs bombed. The only value I found that did not
crash the program was 'USB001'. That caused the output to go to a
file named USB001.
That tells me the make and model of my printer. I already know that
information from the decals on the front of the printer. I thought
the printername needed in the NET command is its virtual name within
the local network. Or am I making a wrong assumption?
> That tells me the make and model of my printer. I already know that
> information from the decals on the front of the printer. I thought
> the printername needed in the NET command is its virtual name within
> the local network. Or am I making a wrong assumption?
I believe so - just try renaming it. It makes sense for the system to give
the printer a default name which enables you to identify it easily. You can
rename it to something more 'friendly' if you like in the same sort of way
as you can rename a file in Windows Explorer. e.g. click on the name and
overwrite it, select 'Rename' from the context-sensitive menu etc. etc.
HAPPY NEW YEAR TO ALL!
I found the place where you could set the printer name, and figured
out how to make the NET command work. Then I printed a sample file
containing underlines, bold text, superscripts and varied fonts. It
printed! A little faint, but it printed correctly, and all the
features worked. Hooray! I was ready to send you all bottles of
champagne.
Then I tried printing an actual document, and just like that success
turned back to failure. The document printed, but half-sized. The
page image is squeezed into the upper left corner of the sheet of
paper. So I tried various control codes for adjusting the font size:
Esc 2, Esc P, nothing worked. Then I tried setting the font size
using the buttons on the printer, but Windows overrode them. Next I
tried changing the printer settings in Control Panel, but none of them
helped.
How could it work once and then just stop?
Sorry, I may have panicked too soon. I have been experimenting with
the order of the printer control codes and getting better results.
I suspect that Windows is not using the fonts and other capabilities
of my printer. It is laying the page out as a bit image, and then
sending that to the printer, so controls work a little differently
than they used to.
However, this should be something I can figure out myself. Thanks to
everyone for your help.
Note that if you use FPC/win32 you could simply use the printer over the GDI
windows API interface. Specially in Delphi circles there should be examples
for that.
(I'd look at lazarus/win32 printers4lazarus package, synedit among others)
I'm afraid I have no idea what "GDI windows API interface" means. I
did a search of the FPC manuals, and could find no mention of GDI,
except in some imbeddings like LongDiv.
(putting "gdi" in google would have yielded the answer on the first hit btw)
GDI is the part of the win32/64 api that is responsible for painting the
screen, but the printing support is also based on it.
It is mostly done via the calls in the OS specific windows unit, which, like
all OS specific headers, are not documented in FPC, but in the OS vendors
documentation. In this case Microsoft's MSDN.
However it's easier to search for Delphi examples. They are easier adapted
(if needed at all) to FPC.
The GDI you mean comes up seventh in Google, after Gardner Denver Inc,
God-Damned Independent, and various other choices.
GDI seems to be exactly the opposite of what I want. I want an
interface that transmits the sequence of characters and control codes
produced by my program directly to the printer without any
modification whatsoever.
The last thing I want is for the interface to create an image, and
then send that image to the printer. That produces a double
degradation of the print quality.
Using the shared-printer LPT2 interface is doing that double-mapping,
resulting in undersized lumpy text, dashed horizontal lines, wavy
vertical lines, and irregular gaps. My printer is capable of far
better.
Optimally, the program and the printer should be in direct contact, so
I can control the printing as it's happening, instead of going back
and rerunning the whole job if there is a printing problem.
Just to be clear here, I am not complaining because I dislike change,
I am complaining because I can't use the features of my programs that
control the printing. In the old days, if something went wrong during
printing, like a misfeed, I could press a key and backup and restart
the printing from the misprinted item. Now, the printing doesn't
start until my program finishes, and the best I can do after a misfeed
is to reprint the entire job. That wastes forms, ink or toner, and
above all, time.
See if there is a PDF driver available for your printer and use it to allow
your program to print to a PDF file. Then if your printer misfeeds you can
just print the bad page separately using Acrobat Reader. An added bonus of
this technique is that you have a machine-readable copy of your program's
output that you can email to others, archive, reprint later if required etc.
etc.
I found two programs that seem related, WIN2PDF and DESKPDF. Are
these what you mean? They both say that they let you create a PDF
from any Windows application, but it is not clear if it is possible to
use them from an FPC program. Creating a PDF might help with the
print quality, but it complicates the process by making printing a
multistep process. First I run my program, then I use Adobe Reader to
print the output. But the printing is still spooled, so there still
no way to control the printer during the run.
> I found two programs that seem related, WIN2PDF and DESKPDF. Are
> these what you mean? They both say that they let you create a PDF
> from any Windows application, but it is not clear if it is possible to
> use them from an FPC program.
I believe there are a few around but haven't had experience with either of
those. I use the driver that is included with the full version of Adobe
Acrobat.
> But the printing is still spooled, so there still
> no way to control the printer during the run.
That all depends on your printer and its drivers. Check to see what options
you have in Windows Control panel. Both my inkjet and laser printers allows
me to specify 'Print directly to the printer' / 'Spool print documents so
program finishes printing faster'.
If you select 'Spool' you have a couple of additional options: 'Start
printing after last page is spooled' / 'Start printing immediately'.
You might be able to have some sort of control over a slower inkjet printer
but I would not be optimistic about a fast laser printer. They usually have
several pages already stored in their buffers in addition to the one that is
currently printing. I normally have to switch mine off on the rare occasions
when it goes berserk.
Chris
> See if there is a PDF driver available for your printer and use it to
> allow your program to print to a PDF file.
A universal printer driver, that does that, is available free from Adobe.
Once you have installed it, and set its properties to "print to file", you
can choose to print to your printer or to a pdf-file in the print-dialogue
of any windows-application.
It looks like we have come full circle. I had tried pretty much every
possible combination of the settings in Control Panel before I made my
first post on this subject.