In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Delphi how to call driver printing, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Introduction to the TPrinter class
The interface of the Windows printer is encapsulated in the TPrinter class.
Class relation TObject
Use the TPrinter object to perform any print operation in your application. You can get a TPrinter object in the Printers unit by calling the Printer function. To determine how to display the printed image of the form, you can use the PrintScale property of the Tform component.
You can print after a text variable or a printer canvas is ready. Printing continues until the EndDoe procedure is called. The topics displayed on the PrintManager (or web front page) are determined by the Title property. If you want to start printing, you can call the BeginDoc method. To finish a successful print, you need to call the EndDoc procedure. If there is a problem and you need to interrupt printing, you can call the Abort method.
Attribute list
Aborted interrupt printing
Indicates whether the user currently interrupts printing, thus calling the method
_ _ property bool Aborted = {read = FAborted,nodefalt}
If the property Aborted is true, the printing work has been interrupted. If it is false, it means that the user has not interrupted the printing process.
The surface of the currently printed page of Canvas
Represents the surface of the currently printed page.
_ _ property Graphics:: TCanvas * Canvas = {read = GetCanvas}
The property Canvas represents the printed surface of a page. Use the Brush,Font and Pen properties of the Canvas object to determine how the page is drawn and displayed. Some printers do not support images, so calling the Draw,StretchDraw or CopyRect method on these printers will fail.
Capabilities indicates the current settings of a print device driver
Indicates the current settings for a print device driver.
_ _ property TPrinterCajpabilities Caoabukutues = {read = FCapabities, nodefault}
The property Capabilities contains printer compatibility, which specifies the direction of printing, the number of pages, and whether to proofread.
Copies specifies the number of copies to print
Specifies the number of copies to print.
_ _ property int Copies = {read = GetNumCopies, write = SetNumCopies, nodefault}
The number of copies printed is specified in the property Copies.
Fonts lists the fonts supported by the current printer
Lists the fonts supported by the current printer.
_ _ property Classes;; TStrings * Fonts = {read = GetFonts}
Use the Fonts property to get a list of fonts supported by the current printer. TrueType fonts are always included in the list, even if they are not included in the printer, because Windows Graphies Device Interface (GDI) can accurately draw the font when used by the printer.
Handle provides the ability to access printer object handles
Provides the ability to access printer object handles.
_ _ property HdC Handle = {read = GetHandle, node fault}
Use the Handle property to get access to the printer object handle.
Orientation determines the direction in which the print works on the page
Determine the direction in which the print works on the page, vertical or horizontal.
_ _ property TpinterOrientation Orientation = {read = GetPrientatiion, write = SetOrienatiion, nodefault}
Use the Orientation property to determine the direction in which the printer prints. The Onienation property value can only be of type TPrinterOrientation. The possible values of the property are listed in the following table:
TPrinter::PageHeight
Indicates the pixel height of the currently printed page.
_ _ property int PageHeight = {read = GetPageHeight, nodefault}
The pixel height of the current printed page can be found in the property PageHeight.
PageHeight indicates the pixel height of the currently printed page
Indicates the pixel height of the currently printed page.
PateNurnber indicates the current printed page
Indicates the currently printed page.
_ _ property int PageNumber = {read = FPageNumber, nodefault}
You can get the currently printed page number in the property PageNumber. The property PageNumber is incremented by 1 after the NewPage method is called. When you enter a carriage return at the end of the page and write a text variable, the property PageNumber is also incremented by 1.
PageWidth indicates the pixel width of the current printed page
Indicates the pixel width of the currently printed page.
_ _ property int PageWidth = {read = GetPageWidth, modefault}; the pixel width of the current printed page can be found in the property PsheWifyh.
Printerlndex lists the current printer in the Printers property
Specifies that the printer listed in the Printers property is the current printer.
_ _ property int Printerlndex = {read = GetPrinterlndex, write = SetPrinterlndex, nodefault}
The property Printerlndex specifies the current printer. If you change the value of this property, the EndDoc method will be called automatically. If you want to choose the default printer, you can set the property Printerlndex to-1. The installed printers are listed in the Printers property. The list of fonts currently supported by the printer is in the Fonts property.
Printers lists all printers installed in Windows
List all printers installed in Windows.
_ _ property Classes:: TStrings * Printers = {read = GePrinters}; all printers installed in Windows are listed in the Printers property. The property Printerlndex specifies the currently selected printer. The list of fonts currently supported by the printer is in the Fonts property.
Printing indicates that printing is in progress
Indicates that printing is in progress.
_ _ property bool Printing = {read = FPrinting, nodefault}
Use the Printing property to determine whether a print job is in progress. If the BeginDoc method is called in the application and the Printing property is set to true before calling the EndDoc method (or the Abort method).
The text displayed by Title on the front page of the main network in Ptint Manager
Determines the text to be displayed in Print Manager and in the web front page.
_ _ property Systen:: AndiString Title = {read = FTitle, wrete = FTitle}
The property Title is used by Windows in Print Manager and also serves as the front page of the network.
Method list
~ TPrinter deletes a printer instance
_ _ fastcall virtual ~ TPrinter (void)
Generally, the ~ TPrinter method is not called directly. Printer objects are automatically created and deleted. When the ~ TPrinter method is called, it checks to see if the printing work is finished. If it's over, release the resources. Such as handles, fonts, canvases, etc., and finally turn off the printer and call the inherited destructor.
Abort interrupt printing
Void _ fastcall Abort (void)
Interrupt printing and discard unprinted data.
Use the Abort method to interrupt printing before the printing job is complete, otherwise the EndDoc method will be used. After calling the Abort method, the device is set to the next print job.
BeginDoc sends a print job to the printer
_ void _ _ fastcall BeginDoc (void)
Send a print job to the printer.
Call BeginDoc to initialize a print job. If the printing work is successfully fed, the application will call the EndDoc method to end the printing. Printing actually starts only after the EndDoc method is called.
EndDoc ends the current printing job and closes the text file variable
Void _ fastcall EndDoc (void)
Ends the current printing job and closes the file variable.
Calling the EndDoc method ends printing (and closes the currently open style). Printing starts after the end of the EndDoc method call. After calling the EndDoc method in the application, the printer starts printing. The EndDoc method is called after a print job is successfully sent to the printer. If the printing job is not successful, the Abort method is called.
GrtPrinter retrieves the current printer
Void _ fastcall GetPrinter (char* ADevice,char* ADriver,char* APort,int& ADeviceMode)
Retrieve the current printer.
You do not need to call the GetPrinter method directly. This can be obtained by accessing the printer in the Printers properties array. For more information, see the CreateDC function in Win32Developer's Reference (WIN32::HLP).
NewPage starts a new page
Void _ fastcall NewPage (void)
Start a new page and add 1 to the value of the PageNumber property.
Using the NewPage method forces printing to continue on the new page of the printer.
The NewPage method adds 1 to the value of the PageNumber property. At the same time, the Pen property of the Canvas object will be set to (0mem0).
SetPrinter specifies a printer as the current printer
Void _ fastcall SetPrinter (char* ADevice,char* ADriver,char* APort,int ADeviceMode)
Specify a printer as the current printer.
The SetPrinter method is not called directly. You can set this by accessing the printer in the Printers properties array. For more information, see the CreateDC function in Win32Developer's Reference (WIN32.HLP).
TPrinter creates a printer
_ _ fastcall TPrinter (void)
Create a printer.
The TPrinter method cannot be called directly. The TPrinter method will be called automatically by the Printer function. Method allocates memory for the printer and calls the inherited constructor. Then set the correct drive, device, and port.
TPrinter:
Code demonstration
/ / you must first get the actual size of the printer:
Var
Pointx,pointy:integer
Pointx:=getdevicecaps (printer.handle,logpixelsx)
Pointy:=getdevicecaps (printer.handle,logpixelsy)
Printer.canvas.TextOut (X-ray pointx.Y-point point text)
/ / Note that Printer needs to add a Printers reference.
If printdialog1.Execute then
Begin
Printer.BeginDoc
Printer.Title: = 'memo content'
Printer.Canvas.TextOut (100pi 100pi 'print content')
Printer.EndDoc
End
/ / print string function
Procedure PosPrintStr (SizeType,ColorType:integer; str:string)
Var ls:TStrings
Begin
/ / print test parameter ticket output to file XSysPrint.Log
If PosCfg.blPrnText then
Begin
WritePrintTxt (str)
{ls: = TStringList.Create
Ls.Clear
Try
Ls.Add (str)
TEXT_PrintString (PosCfg.sPrinterPort,0,0,ls)
Finally
Ls.Free
End
DelayMSec (PosCfg.nPrnDelay);}
Exit
End
If PosCfg.sPrinterType='TM300K' then
Begin
TM300K_PrintStr (sPrinterPortID,SizeType,ColorType,str)
DelayMSec (PosCfg.nPrnDelay); / / print delay
End
Else if PosCfg.sPrinterType='TM200D' then
Begin
TM200D_PrintStr (sPrinterPortID,SizeType,ColorType,str)
DelayMSec (PosCfg.nPrnDelay); / / print delay
End
Else if PosCfg.sPrinterType='TEC200D' then
Begin
LPTDOT_PrintStr (sPrinterPortID,1,str); / / parallel port printing
DelayMSec (PosCfg.nPrnDelay); / / print delay
End
Else if PosCfg.sPrinterType='TM210D' then
Begin
TM210D_PrintString (sPrinterPortID,SizeType,ColorType,str); / / Universal parallel port printing
DelayMSec (PosCfg.nPrnDelay); / / print delay
End
Else if PosCfg.sPrinterType='TEXTFILE' then / / Universal text printing
Begin
TEXT_PrintString (PosCfg.sPrinterPort,SizeType,ColorType,str)
DelayMSec (PosCfg.nPrnDelay); / / print delay
End
Else if PosCfg.sPrinterType='OTHER' then
Begin
Other_PrintString (sPrinterPortID,SizeType,ColorType,str)
DelayMSec (PosCfg.nPrnDelay); / / print delay
End
Else begin
TM200D_PrintStr (sPrinterPortID,SizeType,ColorType,str)
DelayMSec (PosCfg.nPrnDelay); / / print delay
End
End
/ / simulate printing test text
Procedure WritePrintTxt (sMessage: String)
Const PRINT_FILE='XSysPrint.Log'
Var
Fname, fname0: String
Fp: TextFile
Begin
/ / create a log file
Fname:=DirConcat (UGetAppPath,PRINT_FILE)
If not FileExists (fname) then
Begin
AssignFile (fp,fname)
Rewrite (fp)
Writeln (fp,' Analog print')
Flush (fp)
CloseFile (fp)
End
/ / record log information
AssignFile (fp,fname)
Try
Append (fp)
Writeln (fp,sMessage)
Flush (fp)
Finally
CloseFile (fp)
End
End
After reading the above, have you mastered how to call the driver printing method in Delphi? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.