How to abort a print job and print to a file instead (Views: 32)
Problem/Question/Abstract: How to abort a print job and print to a file instead Answer: Print to file: uses printers; {$R *.DFM} procedure StartPrintToFile(filename: string); var CTitle: array[0..31] of Char; DocInfo: TDocInfo; begin with Printer do begin BeginDoc; { Abort job just started on API level. } EndPage(Canvas.handle); Windows.AbortDoc(Canvas.handle); { Restart it with a print file as destination. } StrPLCopy(CTitle, Title, SizeOf(CTitle) - 1); FillChar(DocInfo, SizeOf(DocInfo), 0); with DocInfo do begin cbSize := SizeOf(DocInfo); lpszDocName := CTitle; lpszOutput := PChar(filename); end; StartDoc(Canvas.handle, DocInfo); StartPage(Canvas.handle); end; end; procedure TForm1.Button1Click(Sender: TObject); begin StartPrintToFile('C:\temp\temp.prn'); try Printer.Canvas.TextOut(100, 100, 'Hello World.'); finally Printer.endDoc; end; end; |