I noticed a strange problem, and printed a Postscript file .
So here is my setup:
I have a Windows 8 PC , on this PC there is a C # application "NetworkPrintTest.exe", which when it starts should open a PDF file, create a Postscript file and, ultimately, print it. But that doesnโt mean anything. I am not getting an error, but it will not print. The same program works without errors in Windows 7, and even I can make the printer print a file.
As mentioned above, the .ps file was generated successfully on both operating systems, but printing failed.
Here is my source code that should print the file.
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; }
I used some import dlls
[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);
I found that GDI32.dll is different in version, but I still do not see any problems.
Windows 7 โ 6.1.7601.18275
Windows 8 โ 6.2.9200.16654
My application is written in C # in .Net Framework 2.0