2013-08-19 187 views
1

將自定義表單大小添加到本地打印服務器我需要通過代碼將自定義表單大小添加到本地打印服務器。我想在bat文件或C#中執行此操作,或者在運行InstallShield安裝程序時運行其他操作。我需要通過代碼

爲了更好地解釋,要手動執行此操作,請打開設備和打印機,然後單擊打印機。然後點擊打印服務器屬性。下面的表格將打開,您可以查看/添加/刪除表單。我想通過代碼在這裏添加一個新的(然後最終在打印機高級選項中選擇這個新的紙張大小)。

enter image description here

+1

[添加自定義紙張尺寸到名爲打印機](http://www.codeproject.com/Articles/12229/Adding-custom-paper-sizes-to - 命名打印機) –

+0

@RobertHarvey您的鏈接完美工作。你想把它作爲答案發布,我會接受嗎? – gwin003

回答

1

This code project article解釋如何做到這一點,想必有一定的輔助類和方法。一些示例代碼低於:

var formInfo = new FormInfo1(); 
formInfo.Flags = 0; 
formInfo.pName = paperName; 
// all sizes in 1000ths of millimeters 
formInfo.Size.width = (int)(widthMm * 1000.0); 
formInfo.Size.height = (int)(heightMm * 1000.0); 
formInfo.ImageableArea.left = 0; 
formInfo.ImageableArea.right = formInfo.Size.width; 
formInfo.ImageableArea.top = 0; 
formInfo.ImageableArea.bottom = formInfo.Size.height; 

// Add the paper size to the printer's list of available paper sizes: 
bool bFormAdded = AddForm(hPrinter, 1, ref formInfo); 

http://www.codeproject.com/Articles/12229/Adding-custom-paper-sizes-to-named-printers