線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:5641
推到 Plurk!
推到 Facebook!

請問有沒有人試過將指定一個檔案送到指定的印表機?

尚未結案
rambo287
一般會員


發表:17
回覆:4
積分:4
註冊:2002-06-07

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-12-10 13:52:04 IP:220.228.xxx.xxx 未訂閱
目前有個問題是要將一個檔案送到不特定的印表機? 也就是有很多台印表機在本機都設定好 , 並且可手動列印 , 程式執行時可任意指定要從那一台印表機印出檔案??? 有誰有試過的 ?? 可否丟一支小程式來Support 我一下? 急..急..急.... 麻煩同好幫忙一下! 謝謝!!!
dododo
一般會員


發表:16
回覆:23
積分:12
註冊:2004-04-29

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-12-11 03:09:32 IP:61.62.xxx.xxx 未訂閱
這是我以前寫的一個範例程式,不知道是不是你要的功能。    取得印表機資訊及列印示範 本範例顯示系統已安裝印表機,按下拉鈕可選看不同的印表機狀態及資訊,按下列印測試可印出文字圖形及圖片。 ‧Printers: 目前系統中已安裝的印表機會記錄在屬性 Printers。 ‧PrinterIndex: 目前印表機的索引值。 ‧Fonts: 目前選用印表機所提供的字形。 另外透過 Win 32 API 函數 GetDeviceCaps 可取得更多的資訊,包括印表機解析度、紙張大小、點數等詳細資訊。
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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-12-11 17:09:25 IP:220.135.xxx.xxx 未訂閱
感謝dododo 提供的程式 另外可否請問這樣的方式 可以指定不同檔案型態的檔案嗎 我是說 .tif 檔 .doc 檔 .xls 檔 .ppt 檔 都可用此方法 列印到指定的印表機嗎
dododo
一般會員


發表:16
回覆:23
積分:12
註冊:2004-04-29

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-12-12 01:27:00 IP:61.62.xxx.xxx 未訂閱
果然我想錯了,抱歉 要列印這些格式應該需要 > 這個範例程式並不是直接開啟一個檔案來列印,只有寫如何取得系統安裝印表機及該印表機 的資訊,列印前可選擇系統中所安裝的印表機,而列印的內容則是示範如何設定列印文字, 以及開啟一個
conundrum
尊榮會員


發表:893
回覆:1272
積分:643
註冊:2004-01-06

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-12-12 12:02:04 IP:218.175.xxx.xxx 未訂閱
http://delphi.ktop.com.tw/topic.php?TOPIC_ID=56848 http://homepage2.nifty.com/Mr_XRAY/ 此為日文 去下載dllee版主的 文字工具修改自己要的模式把 【BCB】【發表】文字轉碼程式 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=57431
manhan
一般會員


發表:0
回覆:1
積分:0
註冊:2011-03-21

發送簡訊給我
#6 引用回覆 回覆 發表時間:2011-03-22 14:19:21 IP:61.219.xxx.xxx 訂閱
大大您好:

請問是否可藉由GetDeviceCaps取得列印的張數呢?
aqph

系統時間:2024-04-25 9:26:37
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!