3
我發現一個奇怪的問題,而打印Postscript文件。Windows 8打印Postscript文件編程
因此,這裏是我的設置:
我有一個的Windows 8 PC,這臺電腦上有一個C#應用程序 「NetworkPrintTest.exe」,在執行時,應該打開一個PDF,產生一個Postscript文件並最終應該打印出來。 但它什麼也沒做。我沒有收到錯誤,但也不會打印。 相同的程序在Windows 7上運行無錯誤,我甚至讓打印機打印文件。
如上所述,在兩個操作系統上成功生成.ps文件,但打印失敗。
這是我的源代碼,它應該打印文件。
public static bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, int dwCount, params string[] docName)
{
int dwWritten = 0;
IntPtr hPrinter = new IntPtr(0);
DOCINFOA di = new DOCINFOA();
bool flag = false;
di.pDocName = "print document";
if (docName.Length > 0)
di.pDocName = docName[0];
di.pDataType = "RAW";
if (OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero))
{
if (StartDocPrinter(hPrinter, 1, di))
{
if (StartPagePrinter(hPrinter))
{
flag = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
EndPagePrinter(hPrinter);
}
EndDocPrinter(hPrinter);
}
ClosePrinter(hPrinter);
}
if (!flag)
{
Marshal.GetLastWin32Error();
}
return flag;
}
[StructLayout(LayoutKind.Sequential)]
public class DOCINFOA
{
[MarshalAs(UnmanagedType.LPStr)]
public string pDocName;
[MarshalAs(UnmanagedType.LPStr)]
public string pOutputFile;
[MarshalAs(UnmanagedType.LPStr)]
public string pDataType;
}
我使用了一些DLL進口
[DllImport("winspool.Drv", CallingConvention = CallingConvention.StdCall, SetLastError = true, ExactSpelling = true)]
public static extern bool EndDocPrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", CallingConvention = CallingConvention.StdCall, SetLastError = true, ExactSpelling = true)]
public static extern bool EndPagePrinter(IntPtr hPrinter);
[DllImport("gdi32.dll")]
private static extern int GetDeviceCaps(IntPtr hdc, int capindex);
[DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out IntPtr hPrinter, IntPtr pd);
我發現GDI32.DLL不同版本,但我看不出有什麼問題爲止。
的Windows 7 - > 6.1.7601.18275
的Windows 8 - > 6.2.9200.16654
我的應用程序是用C#在.Net框架2.0
託尼,你救了我的一天。我正在挖這個問題。當我將「RAW」替換爲「XPS_PASS」時,它按預期工作。 – fkucuk
我在https://www.nuget.org/packages/RawPrint/ –
上爲nuget創建了一個解決方案。對不起,回覆遲了。我會盡快測試,看看它是否奏效。非常感謝+1 – Bongo