예제 #1
0
        ////public PagePreview.RenderEvent RenderEvent
        ////{
        ////    get { return this.renderEvent; }
        ////    set
        ////    {
        ////        this.pagePreview.SetRenderEvent(value);
        ////        this.renderEvent = value;
        ////    }
        ////}
        ////PagePreview.RenderEvent renderEvent;

        ///// <summary>
        ///// Prints the document to the default printer.
        ///// See MSDN documentation for information about printer selection and printer settings.
        ///// </summary>
        //public void Print()
        //{
        //    PrintDocument pd = new PrintDocument();
        //    pd.PrintPage += new PrintPageEventHandler(PrintPage);
        //    pd.Print();
        //}

        ///// <summary>
        ///// Draws the page on the printer.
        ///// </summary>
        //private void PrintPage(object sender, PrintPageEventArgs ev)
        //{
        //    Graphics graphics = ev.Graphics;
        //    graphics.PageUnit = GraphicsUnit.Point;
        //    gfx = XGraphics.FromGraphics(graphics, PageSizeConverter.ToSize(PageSize.A4));

        //    //if (this.renderEvent != null)
        //    //    this.renderEvent(gfx);

        //    ev.HasMorePages = false;
        //}

        public void Print()
        {
            string file = Metodos_Globales.crearCarpetaAppdata("\\SoftNet G-Clinic\\TempFiles") + "\\TempFile_Prescription.pdf";

            if (File.Exists(file))
            {
                PdfFilePrinter.AdobeReaderPath = txtAdobeExePath.Text.Trim();
                // Set the file to print and the Windows name of the printer.
                PdfFilePrinter printer = new PdfFilePrinter(file, comboBox1.Text.Trim());
                //&nbsp;
                try
                {
                    printer.Print();
                }
                catch
                {}
            }
        }
예제 #2
0
        public override bool Run()
        {
            var adobe = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("App Paths").OpenSubKey("AcroRd32.exe");
            var path  = (string)adobe.GetValue("");

            // remove parameters and quotes:
            //      "C:\Program Files (x86)\Adobe\Acrobat 10.0\Acrobat\Acrobat.exe" /u "%1"
            // see:
            //      http://stackoverflow.com/questions/10891939/how-to-get-adobe-reader-full-pathincluding-executable-file-name
            var adobeOtherWay          = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Classes").OpenSubKey("acrobat").OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command");
            var quotedRegValueOtherWay = (string)adobeOtherWay.GetValue("");
            var quotedPathOtherWay     = quotedRegValueOtherWay.Substring(0, quotedRegValueOtherWay.Length - " /u \"%1\"".Length);
            var pathOtherWay           = quotedPathOtherWay.Remove(0, 1);

            pathOtherWay = pathOtherWay.Remove(pathOtherWay.Length - 1, 1);

            if (File.Exists(path))
            {
                PdfFilePrinter.AdobeReaderPath = path;
            }
            else if (File.Exists(pathOtherWay))
            {
                PdfFilePrinter.AdobeReaderPath = pathOtherWay;
            }
            else
            {
                mCallback.Log(LogLevel.Critical, "Adobe Acrobat Reader not found");

                return(false);
            }

            var printer = new PdfFilePrinter(mControl.SourceFilePathResolvedValue, mControl.Printers.Text);

            try
            {
                printer.Print();
            }
            catch (Exception ex)
            {
                mCallback.Log(LogLevel.Critical, ex.Message);
            }

            return(true);
        }
예제 #3
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            PdfFilePrinter.AdobeReaderPath = Textbox1.Text;


            string toch = new OpenExcelFile().Filenamereturn();

            if (toch == "can not open file")
            {
                return;
            }
            object[][] tochki = getarray(toch, new int[] { 1 });

            string wpath = DirSelect();

            string[] files = Directory.GetFiles(wpath);
            int      ad    = 0;

            foreach (object t in tochki[0])
            {
                foreach (string file in files)
                {
                    if (file.Contains(t.ToString()))
                    {
                        try
                        {
                            PdfFilePrinter printer = new PdfFilePrinter(file, "HP LaserJet Professional P1606dn");
                            printer.Print();
                        }
                        catch (Exception ex)
                        {
                            win.MessageBox.Show("Error: " + ex.Message, "HP LaserJet Professional P1606dn");
                        }
                        ad++;
                        break;
                        // Process.Start(@"winword.exe", string.Format(@"{0} /mFilePrintDefault /mFileExit", wpath));
                    }
                }
                //if (ad > 3)
                //    break;
            }

            win.MessageBox.Show("Конец  " + ad.ToString());
        }
예제 #4
0
        static void Main()
        {
            // Set Acrobat Reader EXE, e.g.:
            //PdfPrinter.AdobeReaderPath = @"C:\Program Files\Adobe\Adobe Acrobat 7.0\Acrobat\Acrobat.exe";
            // -or-
            //PdfPrinter.AdobeReaderPath = @"C:\Program Files\Adobe\[...]\AcroRd32.exe";

            // On my computer (running Windows Vista 64) it is here:
            PdfFilePrinter.AdobeReaderPath = @"C:\Program Files (x86)\Adobe\Acrobat 8.0\Acrobat\Acrobat.exe";

            // Set the file to print and the Windows name of the printer.
            // At my home office I have an old Laserjet 6L under my desk.
            PdfFilePrinter printer = new PdfFilePrinter(@"..\..\..\..\..\PDFS\HelloWorld.pdf", "HP LaserJet 6L");

            try
            {
                printer.Print();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
예제 #5
0
        public static void Main(string[] args)
        {
            Console.WriteLine("** START PRINT");

            /**************
            * 範例 1 MSDN RawPrinterHelper  (EASY WAY IF WORK)
            **************/
            foreach (var printername in PrinterSettings.InstalledPrinters)
            {
                Console.WriteLine(printername); // 列出所有的印表機
            }

            /* Options
             * // 讓使用者挑機器(要用這個需要用 System.Form)
             * PrintDialog pd = new PrintDialog();
             * pd.Document = new PrintDocument ();
             * pd.PrinterSettings = new PrinterSettings ();
             * pd.UseEXDialog = true;
             * if (DialogResult.OK == pd.ShowDialog (this)) {
             *  // 傳送文字到印表機
             *  RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, s);
             * }
             */

            /* 範例 1 重點使用 RawPrinterHelper 發送檔案 */
            // RawPrinterHelper.SendFileToPrinter(new PrinterSettings().PrinterName, "adobe.pdf");


            /**************
            * 範例 2 使用 Adobe Reader (Failure)
            * 需要安裝 Acrobat Reader
            **************/
            /*
             * ProcessStartInfo info = new ProcessStartInfo();
             * info.Verb = "print";
             * info.FileName = @"c:\adobe.pdf";
             * info.CreateNoWindow = true;
             * info.WindowStyle = ProcessWindowStyle.Hidden;
             *
             * Process process = new Process();
             * process.StartInfo = info;
             * process.Start();
             *
             * process.WaitForInputIdle();
             * System.Threading.Thread.Sleep(3000);
             * if (false == process.CloseMainWindow())
             *  process.Kill();
             */

            /**************
            * 範例 3 使用 Ghostscript (Failure)
            * 需安裝 Ghostscript http://www.ghostscript.com/doc/9.16/Readme.htm
            **************/
            /*
             * ProcessStartInfo psInfo = new ProcessStartInfo();
             * psInfo.Arguments = String.Format(" -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=1 -sDEVICE=ljet4 -sOutputFile=\"\\\\spool\\{0}\" \"{1}\"", "EPSON M200 Series", "adobe.pdf");
             * psInfo.FileName = @"C:\Program Files (x86)\gs\gs9.16\bin\gswin32c.exe";
             * psInfo.UseShellExecute = false;
             * Process process = Process.Start(psInfo);
             */

            /* Using helper */

            /*
             * var gh = new GhostHelper();
             * gh.PrintPDF(@"C:\Program Files\gs\gs9.16\bin\gswin64c.exe", 1, "EPSON M200 Series", "adobe.pdf");
             */

            /**************
            * 範例 4 使用 PrintDocument
            * https://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument%28v=vs.100%29.aspx
            **************/
            /*
             * PrintDocument document = new PrintDocument();
             * document.PrintPage += document_PrintPage;
             * // Configuration by Dialog
             * // PrintPreviewDialog ppd = new PrintPreviewDialog();
             * // ppd.Document = document;
             * // ppd.ShowDialog();
             *
             * // Configuration automatic
             * document.DocumentName = "test";
             * document.PrinterSettings.PrinterName = "EPSON M200 Series";
             * document.PrinterSettings.PrintFileName = "adobe.pdf";
             * document.PrintController = new StandardPrintController();
             * document.OriginAtMargins = false;
             *
             * document.Print();
             */

            /**************
            * 範例 5 使用 PDFSharp (EASY WAY)
            **************/

            PdfFilePrinter.AdobeReaderPath = @"C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe";
            PdfFilePrinter printer = new PdfFilePrinter("adobe.pdf", "EPSON M200 Series");

            printer.Print(5000); // After milliseconds close.



            Console.WriteLine("** DONE PRINT");
            Console.ReadKey();

            /**************
            * 其他
            **************/
            // Working with USB Device http://www.developerfusion.com/article/84338/making-usb-c-friendly/
        }
예제 #6
0
        public static void PrintPDF(string filePath, string Printer = null)
        {
#if ( Print_Using_Adobe_Reader )
            // Define or otherwise determine the path of the Adobe reader
            PdfFilePrinter.AdobeReaderPath = @Properties.Settings.Default.AdobeReader;

            if (string.IsNullOrWhiteSpace(printerName))
            {
                // Present a Printer settings dialogue to the user so that they may select the printer
                // to use.
                PrinterSettings settings = new PrinterSettings();
                settings.Collate = false;

                PrintDialog printerDialog = new PrintDialog();
                printerDialog.AllowSomePages              = false;
                printerDialog.ShowHelp                    = false;
                printerDialog.PrinterSettings             = settings;
                printerDialog.AllowPrintToFile            = true;
                printerDialog.PrinterSettings.PrintToFile = true;

                DialogResult result = printerDialog.ShowDialog();

                if (result == DialogResult.OK)
                {
                    printerName = settings.PrinterName;
                }
                else
                {
                    return;
                }
            }

            // Print the document on the selected printer (We are ignoring all other print
            // options here

            PdfFilePrinter printer = new PdfFilePrinter(filePath, printerName);

            try
            {
                printer.Print();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
#else
            if (!File.Exists(filePath))
            {
                return;
            }
            // This is a massive bodge!
            ((App)App.Current).EventPage.Dispatcher.Invoke(delegate()
            {
                PdfDocumentView pdfViewer1 = new PdfDocumentView();


                pdfViewer1.Load(filePath);

                //if ( !string.IsNullOrWhiteSpace ( Printer ) )
                //    pdfViewer1.Print ( Printer );
                //else
                //    pdfViewer1.Print ( );

                PrintDialog print = new PrintDialog();

                if (!string.IsNullOrWhiteSpace(Printer))
                {
                    PrintQueue t = print.PrintQueue;
                    try
                    {
                        PrintServer server = new PrintServer();
                        print.PrintQueue   = server.GetPrintQueue(Printer);
                    }
                    catch (Exception)
                    {
                        System.Diagnostics.Debug.WriteLine("Failed to find printer");
                        print.PrintQueue = t;
                    }
                }

                //BitmapSource img = pdfViewer1.ExportAsImage ( 1 );


                print.PrintDocument(pdfViewer1.PrintDocument.DocumentPaginator, "Championship Solutions");
            });
#endif
        }