im still struggling to print an invoice that i have made in pascal to a usb port printer. any help please. i have tried using various inbuilt function but have had no luck probably because im coding it wrong. thanks in advance

Dani AI

Generated

mpx10’s problem is a common one: Turbo Pascal for DOS has no USB stack or Windows printer‑spooler integration, so a DOS program that writes to LPT/PRN can’t talk to a USB printer directly. ’s Win32/Delphi suggestion is correct for native Windows printing, but for a DOS TP binary there are a few practical workarounds.

Try these approaches (ordered from easiest to most robust):

  1. Redirect an LPT port to the Windows‑installed USB printer (lets a DOS program print to LPT1 and have Windows spool it). Share the USB printer in Windows, open an elevated Command Prompt and run:

    net use LPT1 \\<ComputerName>\<PrinterShareName> /persistent:yes

    When finished remove the mapping:

    net use LPT1 /delete

    Use the actual machine name (or \127.0.0.1\ShareName) if \localhost fails. The Windows Print Spooler must be running and the command must be run with sufficient privileges.

  2. Run the TP program inside DOSBox and use DOSBox’s printer bridge (no kernel hacking required). In dosbox.conf set:

    [printer]
    output=winprn
    printername=<YourWindowsPrinterName>

    DOSBox will forward LPT output to the Windows printer.

  3. If the program runs on a real DOS machine, USB printing is generally impractical without special drivers or a hardware-parallel printer. A true parallel (LPT) or serial printer, or a networked printer the DOS machine can reach, is the reliable solution.

Troubleshooting notes: confirm the TP program writes to PRN/LPT (or change it to write to a file and spool that file from Windows), check the printer share name and permissions, try mapping LPT2 if LPT1 is in use, and test with a simple text print to verify the redirection before sending formatted invoices. If migrating is an option, compiling with a Win32 Pascal (Free Pascal/Lazarus or Delphi) lets the program use Windows printing APIs directly.

im still struggling to print an invoice that i have made in pascal to a usb port printer. any help please. i have tried using various inbuilt function but have had no luck probably because im coding it wrong. thanks in advance

This works in Delphi 7 / WinXP:

program ptest;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Printers;

begin
  Printer.BeginDoc;
  Printer.Canvas.TextOut(200,200,'Hello, world!');
  printer.EndDoc;
end.

I don't have/use Turbo Pascal so can't say if it works there as well...

tried it in turbo pascal but it doesnt work its says cannot find file 'sysutils.tpu' thanks for your help though!! any other ideas please.

About the only thing I could suggest would be to write the information to a file the use the Exec function (in DOS unit -- at least it is in Free Pascal) to launch NotePad or WordPad and print from there.

If you're running Windows, you could also move up to Delphi. I've also had pretty good luck with Lazarus (although I haven't used it much). It's an open source IDE for Free Pascal similar to Delphi.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.