請問有沒有人試過將指定一個檔案送到指定的印表機? |
尚未結案
|
rambo287
一般會員 ![]() ![]() 發表:17 回覆:4 積分:4 註冊:2002-06-07 發送簡訊給我 |
|
dododo
一般會員 ![]() ![]() 發表:16 回覆:23 積分:12 註冊:2004-04-29 發送簡訊給我 |
這是我以前寫的一個範例程式,不知道是不是你要的功能。 取得印表機資訊及列印示範
unit ex13_3; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms , Dialogs, StdCtrls, Printers, ExtCtrls; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; PrintDialog1: TPrintDialog; ComboBox1: TComboBox; Label1: TLabel; Label2: TLabel; procedure FormShow(Sender: TObject); procedure Button1Click(Sender: TObject); procedure ComboBox1Change(Sender: TObject); private procedure PrintInfo; //取得印表機資訊程序 public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.FormShow(Sender: TObject); var i : integer; begin for i := 0 to Printer.Printers.Count -1 do //取得系統已安裝印表機 ComboBox1.Items.Add(Printer.Printers.Strings[i]); ComboBox1.ItemIndex := Printer.PrinterIndex; PrintInfo; //取得印表機資訊 end; procedure TForm1.Button1Click(Sender: TObject); var Bitmap1 : TBitmap; Rect1 : TRect; begin Printer.Copies := 1; //預設列印的份數 if PrintDialog1.Execute then //開啟 PrintDialog begin with Printer do begin Title := 'Printer DEMO'; //列印時的文件名稱 BeginDoc; //開啟一項列印工作 Canvas.Font.Name := 'Times New Roman'; //設定屬性 canvas 中字型 Canvas.Font.Size := 9; Canvas.Font.Style := []; Canvas.TextOut(10, 0, 'Hello World! - Page1'); Canvas.Pen.Width := 10; Canvas.Rectangle(10, 200, 510, 700); //在屬性 canvas 中畫上一個矩形 Bitmap1 := TBitmap.Create; Bitmap1.LoadFromFile('C:\windows\Bubbles.bmp'); Rect1 := Rect(10, 1000, 10 + (Bitmap1.Width * 10) , 1000 + (Bitmap1.Height * 10)); // 將 Bitmap1 中的圖片放大十倍 Canvas.StretchDraw(Rect1, Bitmap1); //將 Bitmap1 中的圖片輸出 NewPage; //產生新的輸出頁 Canvas.TextOut(0,0,'Hello World! - Page2'); EndDoc; //結束列印工作並輸出至印表機 Bitmap1.Free; end; end; end; procedure TForm1.PrintInfo; //取得印表機資訊程序 begin Memo1.Clear; Memo1.Lines.Add('紙張大小 : H = ' + inttostr(GetDeviceCaps(Printer.handle, HORZSIZE)) + ' , V = ' + inttostr(GetDeviceCaps(Printer.handle, VERTSIZE))); Memo1.Lines.Add('印表機解度 : H = ' + inttostr(GetDeviceCaps(Printer.handle, LOGPIXELSX)) + ' , V =' + inttostr(GetDeviceCaps(Printer.handle, LOGPIXELSY))); Memo1.Lines.Add('紙張點數 : H = ' + inttostr(GetDeviceCaps(Printer.handle, HORZRES)) + ' , V = ' + inttostr(GetDeviceCaps(Printer.handle, VERTRES))); Memo1.Lines.Add('列印份數 = ' + inttostr(Printer.Copies)); Memo1.Lines.Add('PrinterIndex =' + inttostr(Printer.PrinterIndex)); end; procedure TForm1.ComboBox1Change(Sender: TObject); begin Printer.PrinterIndex := ComboBox1.ItemIndex; PrintInfo; end; end.範例中採用列印前先顯示 PrintDialog 視窗,不但可省略許多程式的撰寫,還可作為輸出前的一個緩衝。 Rect1 變數先定義圖片要輸出的範圍,將 Bitmap1 的圖片放大十倍,再由 StretchDraw 物件方法,依 Rect1 的範圍繪出 Bitmap1 的圖片,如不是使用 StretchDraw 物件方法繪製,而使用物件方法 Draw 來繪製點陣圖,則無法改變點陣圖中的圖片大小,這種作法就可依所取得印表機的解析度,為輸出的圖做適當大小的調整。 取得印表機資訊的 Win 32 函數 GetDeviceCaps,第一個參數要傳入印表機的 handle,第二個參數是要取回的資訊項目名稱,第二個參數詳細的項目名稱在 Win 32 API 中有詳列。 |
rambo287
一般會員 ![]() ![]() 發表:17 回覆:4 積分:4 註冊:2002-06-07 發送簡訊給我 |
|
dododo
一般會員 ![]() ![]() 發表:16 回覆:23 積分:12 註冊:2004-04-29 發送簡訊給我 |
|
conundrum
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:893 回覆:1272 積分:643 註冊:2004-01-06 發送簡訊給我 |
|
manhan
一般會員 ![]() ![]() 發表:0 回覆:1 積分:0 註冊:2011-03-21 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |