1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | procedure TForm1.Button1Click(Sender: TObject); var I : Integer; DPSDK : Variant; RVal : Integer; OldIndex : Integer; printerIndex : Integer; begin DPSDK:=CreateOleObject('docuPrinter.SDK'); OldIndex:=Printer.PrinterIndex; printerIndex:=-1; Printer.Refresh; for I:=0 to Printer.Printers.Count-1 do begin if CompareText(Printer.Printers.Strings[i],'docuPrinter')=0 then begin printerIndex:=I; Printer.PrinterIndex:=printerIndex; break; end; end; If printerIndex=-1 Then begin ShowMessage('Printer not found!!!'); Exit; end else Printer.PrinterIndex:=printerIndex; DPSDK.DocumentOutputFormat:= 'PDF'; DPSDK.DocumentOutputName:= 'demoDelphi'; DPSDK.DocumentOutputFolder:= 'c:\users\public\'; DPSDK.HideSaveAsWindow:= true; DPSDK.DefaultAction:=1; DPSDK.ApplySettings; Printer.Title:='Hello !'; Printer.BeginDoc; Printer.Canvas.Font.Name:= 'Times New Roman'; Printer.Canvas.Font.Size:= 48; Printer.Canvas.TextOut(0,0,'Hello from Borland Delphi!!!'); Printer.EndDoc; RVal:= DPSDK.Create; // Create output document If (RVal <> 0) Then ShowMessage('Error while creating document!!!') else ShowMessage('Done !!!'); Printer.PrinterIndex:=OldIndex; DPSDK:= Unassigned; end; |