示例#1
0
        /// <summary>
        /// Prints a stream.
        /// </summary>
        /// <param name="PrinterName">Printer name on which should be print.</param>
        /// <param name="DocName">Document title for printer spooler.</param>
        /// <param name="Copies">Count of copies.</param>
        /// <param name="Stream">Stream that will be printed.</param>
        /// <example>This example demonstrates the printing of Stream.
        /// <code>
        /// TextExportPrint.PrintStream("EPSON FX-1000", "My Report", 1, txtStream)</code>
        /// </example>
        public static void PrintStream(string PrinterName, string DocName, int Copies, Stream Stream)
        {
            System.IntPtr lhPrinter = new System.IntPtr();
            DOCINFO       di        = new DOCINFO();
            int           pcWritten = 0;

            di.pDocName  = DocName;
            di.pDataType = "RAW";
            OpenPrinter(PrinterName, ref lhPrinter, 0);
            StartDocPrinter(lhPrinter, 1, ref di);
            StartPagePrinter(lhPrinter);
            try
            {
                int    buffSize = 2048;
                byte[] buff     = new byte[buffSize];
                for (int c = 0; c < Copies; c++)
                {
                    Stream.Position = 0;
                    int i = buffSize;
                    while (i == buffSize)
                    {
                        i = Stream.Read(buff, 0, buffSize);
                        WritePrinter(lhPrinter, buff, i, ref pcWritten);
                    }
                }
            }
            finally
            {
                EndPagePrinter(lhPrinter);
                EndDocPrinter(lhPrinter);
                ClosePrinter(lhPrinter);
            }
        }
示例#2
0
 internal static extern long StartDocPrinter(IntPtr hPrinter, int Level, ref DOCINFO pDocInfo);