對於給定的打印文檔的PrintSettings
,Duplex
值可能(且可能會)設置爲Duplex.Default
。查找打印機的默認雙面打印選項
我如何知道這是否意味着所選擇的打印機是否會以雙面打印或不打印?
如何查找已安裝打印機支持的行爲的默認值?
對於給定的打印文檔的PrintSettings
,Duplex
值可能(且可能會)設置爲Duplex.Default
。查找打印機的默認雙面打印選項
我如何知道這是否意味着所選擇的打印機是否會以雙面打印或不打印?
如何查找已安裝打印機支持的行爲的默認值?
我不知道你可以獲得在默認對於給定的打印機。如果你有創意,你可以得到實際的當前值。不過,如果你想確保你擁有正確的信息,你將不得不使用DEVMODE結構。這不是一個簡單的操作,需要一些花哨的Win32 fu。這是從幾個來源改編,但在我的(不可否認的參差不齊的)測試工作。
[DllImport("kernel32.dll")]
static extern bool GlobalFree(IntPtr hMem);
[DllImport("kernel32.dll")]
public static extern IntPtr GlobalLock(IntPtr handle);
[DllImport("kernel32.dll")]
public static extern IntPtr GlobalUnlock(IntPtr handle);
private static short IsPrinterDuplex(string PrinterName)
{
IntPtr hDevMode; // handle to the DEVMODE
IntPtr pDevMode; // pointer to the DEVMODE
DEVMODE devMode; // the actual DEVMODE structure
PrintDocument pd = new PrintDocument();
StandardPrintController controller = new StandardPrintController();
pd.PrintController = controller;
pd.PrinterSettings.PrinterName = PrinterName;
// Get a handle to a DEVMODE for the default printer settings
hDevMode = pd.PrinterSettings.GetHdevmode();
// Obtain a lock on the handle and get an actual pointer so Windows won't
// move it around while we're futzing with it
pDevMode = GlobalLock(hDevMode);
// Marshal the memory at that pointer into our P/Invoke version of DEVMODE
devMode = (DEVMODE)Marshal.PtrToStructure(pDevMode, typeof(DEVMODE));
short duplex = devMode.dmDuplex;
// Unlock the handle, we're done futzing around with memory
GlobalUnlock(hDevMode);
// And to boot, we don't need that DEVMODE anymore, either
GlobalFree(hDevMode);
return duplex;
}
我使用了pinvoke.net的DEVMODE structure定義。請注意,在pinvoke.net上定義的字符集可能需要根據B0bi對original link的評論進行調整(即,在DEVMODE的StructLayoutAttriute中設置CharSet = CharSet.Unicode)。你還需要DM enum。並且不要忘記使用System.Runtime.InteropServices添加;
您應該能夠從這裏縮小您在打印機設置中獲得的變化。
簡答題?你沒有。無論各種設置如何,實際打印機可能會設置爲始終雙面打印作業。
我不完全確定你打算如何將文檔合併在一起,但它聽起來像你可能能夠簡單地計數頁面,並且可以在文檔之間插入一個空白頁面以確保每個新文檔在奇數頁面上開始。
這是一個更大的變化,但如果您願意轉移到XPS工作流程,則會有一個名爲PageForceFrontSide的頁面級別的檢票項目,以保證文檔不會錯誤地粘在一起。
我試圖想象爲什麼它會影響和失敗。 – 2012-04-05 12:58:50
@Damien_The_Unbeliever - 我們正在嘗試將一系列文檔合併到一個文檔中,以便在單個打印作業中進行打印。但是,我們需要注意打印作業中將要發生的雙面打印選項,以便能夠適當地分離文檔,以便每個文檔從新頁面開始(而不是在另一個文檔的背面)。 – Reddog 2012-04-05 18:57:35
不能保證每個文件都被2整除嗎?如果奇數頁面添加空白頁面。然後它將永遠不會打印在另一個文檔頁面的背面。 – 2012-04-09 22:07:37