Delphi Network Printer Access Path - delphi

I have my original question posted here:
Delphi Printer Access
Now we need to handle one more case of network printer with specific IP say xx.xx.x.x .
How Do we access Network printer from Delphi for Rewrite function?
I did sample app with this code and it works for all printers:
AssignPrn(lOutputFile);
Rewrite(lOutputFile);
for liIndex := 0 to lsLines.Count-1 do
Writeln(lOutputFile, lsLines[liIndex]);
CloseFile(lOutputFile);
On click of f7 on CloseFile(lOutputFile); in sample app, control goes nowhere and printing works.
When I integrated my code in the main application
On click of f7 on CloseFile(lOutputFile) it goes got o Devexpress files and its not printing.
kindly suggest.

Windows can access network printers. See the documentation.
Once the printer is installed, your application can access that printer just like any other [local] printer.
Use a fully qualified function name: System.CloseFile(lOutputFile);

Related

How to use a host-based USB printer from WinCE

I'm testing an HP LaserJet printer with WinCE7, it's a host-based (not PCL) printer.
When it's plugged into the USB port of WinCE, the USBPRN.dll is loaded but PCL.dll is not loaded which is as expected.
I included wordpad in WinCE and tried to print from wordpad, but there is a error message box saying no printer babah. Printer setting dialog box is not displayed.
Then I use CreateFile/WriteFile/CloseHandle APIs and try to send some ASCII string to the LPT1 port.
The return handles are valid but nothing happened on the printer. According to the debug log, I see something wrong inside WriteFile although the return value is valid.
Then I'm stuck.
I have several other options to try:
Use OpenPrinter/StartDocPrinter/WritePrinter API set. But I'm not
sure if they are different from CreateFile/WriteFile/CloseHandle.
Check to see if there's any open sourced driver for the printer in
Linux world, then I can see what's the data & format I should send
to the printer. But I don't know Linux at all. I'm not sure what
part is different from Windows to Linux or what part is same to
different OS.
Anyone can point out any information about how to implement a
host-based printer driver? Just introduction about the architecture
is also welcome. For example, is there anything related to the
device context (DC) or bitmap or anything else.
I'd like to see any comment on which direction I should go.
Thanks,
Fei

send command to zebra printer xcode

How would I send a CPCL or ZPL command to a Zebra printer through an app?
These commands would be similar to ones used in ToolBox.
For example how would I send "! U1 getvar "allcv"" to a printer and get the results.
I am using the Link-OS ios SDK and already have no problems connecting to and printing to the printers.
Did you ever figure this out? It's quite simple in the *nix world. If you send commands to the lp port via cat or some such, the printer will simply read them in. Note that this must be done as root if you don't have permissions set up on the device to allow normal users.
$ sudo cat command_file.txt > /dev/usb/lp0
So, I'm not a C or C++ developer, but the idea is the same in any language. Open the file for writing (probably O_RDWR so you can read back in any response from the printer) and then send commands to the fd returned from open().
You didn't specify an OS so I'll just stick with this *nix answer. That said, it wouldn't be different in Windows, I suppose. You just have to be able to find the right device.

Need Help in Building Printer Driver

I need some help in building printer driver. The printer connects to system via serial port. I just need to grab the data that application sends to the printer, compress it (its a custom routine) and send it to printer.
I do not have any experience in developing drivers. I have all the tools, SDK, DDK. If someone could point out some link to a sample driver (that could just write to flat file instead of sending to printer) that would be great.
The driver has to run on windows NT.
So basically i am looking for some sample printer driver, the DDK (with the name of winprint) has one but when i compile and link it, it generates dll file instead of sys.
Please not once again that the WDK wont work as this driver would be running on NT.
You should use the Win NT DDK. It would have sample files. Also in Windows NT, the printer driver files are actually .dll files and not .sys files. Printer drivers are a different category of drivers in Win NT and need to be installed using the Add Printer Wizard and in a package form with an INF file.
If you already have the Win NT DDK, you could use the sample TTY driver that is present. I believe this is available in %DDKROOT%\Src\Print\Mini\Txtonly.
This article talks more about some update to this driver - http://support.microsoft.com/kb/289108
Once you are able to install and run this driver, you should be able to see the main code and add in your own code to get the incoming data and stream it to a file.
Hope this helps. If so, +1 :)
You don't need to modify code to get a driver that can write to a flat file.
A Windows printer driver can be connected to a variety of ports. In particular you can create a Local Port that is actually connected to a file. On the printer's Ports tab, click [Add Port] and then select Local Port and click [New Port]. In the 'Enter port name' edit-text control type the path of the file you want to be filled with PDL data. Then every time you print subsequently, the PDL from the driver will be written to the file associated with the new port, overwriting its previous contents.

QuickReport throws "There Is No Default Printer Currently Selected" Exception

I have created a Delphi Service which prints TQuickReports. Everything works fine if compiled and run as a Windows Application. But when converted to operate as a service trying to create a form containing a TQuickRep component throws the exception.
This service runs fine on many other boxes but not this one in particular. Here are some details:
Using QuickReport version 4.07
Box is a Windows Server 2008 operating system.
Using Delphi 2007
Printer.Printers.Count is returning a positive value. In fact I can list out all of the printers.
I have tried running the service both using Local System Account and Logged on as an Admin.
Is there a default printer set up in session 0? Remember that under Vista / Server 2008 / Windows 7, services run in a separate session. Whether or not the logged-in user has a default printer set is not relevant - it's a per-session setting and doesn't affect session 0.
Can you rewrite the code to gracefully handle that exception and pick a printer to use?
You can solve this problem by creating a new dword UserSelectedDefault with the value: 1 in
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\SessionDefaultDevices\Session_ID
Make sure you have a local printer selected.
You might give the user a way to select the printer for the service. The Windows service probably does not have a default printer set.
Set TQuickRep.PrinterSettings.PrinterIndex to set the printer number. Then, TQuickRep.Print to print the report.
A colleague ended up finding the solution. I should have added these are "network" printers and not Local printers (at the time I didn't think this was related to the problem). So the service needed to be installed with "NetworkService" as the user account under the logon tab. From the Windows Help:
To specify that the service uses the Network Service account, click This account, and
then type NT AUTHORITY\NetworkService
We had a simular problem here. Using TS servers, Citrix and Powerfuse 9.
Powerfuse had all printers capitalized, however they were shared in a mixed case.
This combination caused Delphi/QReport to crash
When all printers are from printserver to powerfuse in the same case (not important upper or lower or even mixed), the problem was gone
Actually it is a Delphi(5) problem. The comparison of the available printers and the default printer is case sensitive (Printers.pas):
if TPrinterDevice(Objects[I]).Device = Device then
begin
with TPrinterDevice(Objects[I]) do
SetPrinter(PChar(Device), PChar(Driver), PChar(Port), 0);
Exit;
end;
Changing the comparison to:
if lowercase(TPrinterDevice(Objects[I]).Device) = lowercase(Device)
solves the problem.
If using terminal services 2008, same user for multiple sessions, you should look into the:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\SessionDefaultDevices\Session_ID
instead of
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\
I solved a similar problem: If a Delphi application (or service) uses QuickReport, it runs before the system loads the default printer (or printers).
When QuickReport executes TQRPrinter.Init, the printer.printers.count is zero,
shortly after the system loads, the printer.printers.count is the number of printers,
but tqrprinter.int has already executed, so TQRPrinter.FPrinterOK is false,
you then see this error when you try open a QuickReport.
The solution for me was wait until the printers were loaded before launching the application (in citrix and terminal server). I solved this in two ways, either by overwriting tqrprinter or delay the dpr.

Delphi Printer.Printers not refreshing

I have created a Delphi service which is responsible for printing QuckReports to specific printers contained within the printer.Printers list. I pass my routine the printer name and it looks up in the printer.printers array to get the proper index. It then does this:
QuickRep1.PrinterSettings.PrinterIndex := iIndex;
In the help files it says this for printer.refresh: "Call Refresh when the installed fonts or printers on the current system may have changed". So I call the refresh before I look up the printer name against the printer.printers array.
At one of my installations this function is not working properly. If printers are added/deleted, or someone with printers under their profiles logs on, the list does not seem to get refreshed until the service is stopped and restarted.
Does this function not work for services?
The installation where this is occurring utilizes "virtual services". Could this have anything to do with it?
Thanks.
My experience and understanding is the printers array is updated only at application start. Anytime a new printer is installed, the application must be restarted to get the correct list.
I'm curious to hear any different experience with this myself.
EDIT: From my comment below; I wrote a small test program that confirms the TPrinters.Refresh() does update the printers list.

Resources