Beispiel #1
0
        public static void Print(IWin32Window owner, string fileName)
        {
            var    vector      = new WIA.VectorClass();
            object objFilename = fileName;

            vector.Add(ref objFilename, 0);

            var dialogClass = new WIA.CommonDialogClass();

            var form = new Form
            {
                ShowInTaskbar   = false,
                FormBorderStyle = FormBorderStyle.None
            };

            form.TransparencyKey = form.BackColor;
            form.Shown          += (sender, args) =>
            {
                object vectorObject = vector;
                dialogClass.ShowPhotoPrintingWizard(ref vectorObject);
                form.Close();
            };

            form.ShowDialog(owner);
            form = null;

            Marshal.ReleaseComObject(dialogClass);
            dialogClass = null;
        }
Beispiel #2
0
        private void BotonCapturarImagen_Click(object sender, EventArgs e)
        {
#if WINDOWS
            try {
                WIA.CommonDialogClass WiaDialog = new WIA.CommonDialogClass();
                WIA.ImageFile         WiaImage  = null;

                WiaImage = WiaDialog.ShowAcquireImage(
                    WIA.WiaDeviceType.UnspecifiedDeviceType,
                    WIA.WiaImageIntent.ColorIntent,
                    WIA.WiaImageBias.MaximizeQuality,
                    System.Drawing.Imaging.ImageFormat.Jpeg.Guid.ToString("B"), true, false, false);

                if (WiaImage != null)
                {
                    WIA.Vector vector = WiaImage.FileData;
                    using (Entrada.AuxForms.ImagenRecorte Recorte = new Entrada.AuxForms.ImagenRecorte()) {
                        Recorte.Imagen = System.Drawing.Image.FromStream(new System.IO.MemoryStream((byte[])vector.get_BinaryData()));
                        if (Recorte.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            EntradaImagen.Image = Recorte.Imagen;
                            this.Changed        = true;
                            this.ActualizarElemento();
                        }
                    }
                }
            } catch (Exception ex) {
                Lui.Forms.MessageBox.Show("No se puede conectar con el dispositivo de captura. " + ex.Message, "Error");
            }
#endif
        }
Beispiel #3
0
        private static void Print(string fileName)
        {
            WIA.VectorClass vector     = new WIA.VectorClass();
            object          tempName_o = (object)fileName;

            vector.Add(ref tempName_o, 0);
            object vector_o = (object)vector;

            WIA.CommonDialogClass cdc = new WIA.CommonDialogClass();
            cdc.ShowPhotoPrintingWizard(ref vector_o);
        }
Beispiel #4
0
 private void btnWia_Click(object sender, EventArgs e)
 {
     try
     {
         var        dialog  = new WIA.CommonDialogClass();
         WIA.Device scanner = dialog.ShowSelectDevice(WIA.WiaDeviceType.ScannerDeviceType, true, false);
         dialog.ShowAcquisitionWizard(scanner);
     }
     catch
     {
         MessageBox.Show("Não foi possível scannear documento");
     }
 }
Beispiel #5
0
        private void _PrintFileCallback(object sender, SaveImageCompletedEventArgs e)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.BeginInvoke((SaveImageAsyncCallback)_PrintFileCallback, new [] { sender, e });
                return;
            }

            if (e.Cancelled || e.Error != null)
            {
                MessageBox.Show("Unable to print the image");
                return;
            }

            object path = e.ImagePath;

            WIA.CommonDialog dialog = new WIA.CommonDialogClass();
            dialog.ShowPhotoPrintingWizard(ref path);
        }
Beispiel #6
0
        // Prints the document file specified
        // by lpFile. If lpFile is not a
        // document file, the function will
        // fail.

        public static void PrintFiles(params string[] files)
        {
            try
            {
                WIA.CommonDialog dialog = new WIA.CommonDialogClass();
                WIA.VectorClass  vector = new WIA.VectorClass();

                for (int i = 0; i < files.Length; i++)
                {
                    object obj = files[i];
                    vector.Add(ref obj, i);
                }
                object vecObj = vector;
                dialog.ShowPhotoPrintingWizard(ref vecObj);
            }
            catch
            {
            }
        }
Beispiel #7
0
        public void Print(Control owner, string fileName)
        {
            Tracing.Enter();

            WIA.VectorClass vector     = new WIA.VectorClass();
            object          tempName_o = (object)fileName;

            vector.Add(ref tempName_o, 0);
            object vector_o = (object)vector;

            WIA.CommonDialogClass cdc = new WIA.CommonDialogClass();

            // Ok, this looks weird, but here's the story.
            // When we show the WIA printing dialog, it is a modal dialog but the way
            // it handles itself is that the main window can still be interacted with.
            // I don't know why, and it doesn't matter to me except that it causes all
            // sorts of other problems (esp. related to the scratch surface.)
            // So we show a modal dialog that is effectively invisible so that the user
            // cannot interact with the main window while the print dialog is still open.

            Form modal = new Form();

            modal.ShowInTaskbar   = false;
            modal.TransparencyKey = modal.BackColor;
            modal.FormBorderStyle = FormBorderStyle.None;

            modal.Shown +=
                delegate(object sender, EventArgs e)
            {
                cdc.ShowPhotoPrintingWizard(ref vector_o);
                modal.Close();
            };

            modal.ShowDialog(owner);
            modal = null;

            Marshal.ReleaseComObject(cdc);
            cdc = null;

            Tracing.Leave();
        }
Beispiel #8
0
        public ScanResult Scan(Control owner, string fileName)
        {
            ScanResult result;

            WIA.CommonDialogClass cdc       = new WIA.CommonDialogClass();
            WIA.ImageFile         imageFile = null;

            try
            {
                imageFile = cdc.ShowAcquireImage(WIA.WiaDeviceType.UnspecifiedDeviceType,
                                                 WIA.WiaImageIntent.UnspecifiedIntent,
                                                 WIA.WiaImageBias.MaximizeQuality,
                                                 "{00000000-0000-0000-0000-000000000000}",
                                                 true,
                                                 true,
                                                 false);

                Marshal.ReleaseComObject(cdc);
                cdc = null;
            }

            catch (System.Runtime.InteropServices.COMException)
            {
                result    = ScanResult.DeviceBusy;
                imageFile = null;
            }

            if (imageFile != null)
            {
                imageFile.SaveFile(fileName);
                result = ScanResult.Success;
            }
            else
            {
                result = ScanResult.UserCancelled;
            }

            return(result);
        }
        public void Print(Control owner, string fileName)
        {
            Tracing.Enter();

            WIA.VectorClass vector = new WIA.VectorClass();
            object tempName_o = (object)fileName;
            vector.Add(ref tempName_o, 0);
            object vector_o = (object)vector;
            WIA.CommonDialogClass cdc = new WIA.CommonDialogClass();

            // Ok, this looks weird, but here's the story.
            // When we show the WIA printing dialog, it is a modal dialog but the way
            // it handles itself is that the main window can still be interacted with.
            // I don't know why, and it doesn't matter to me except that it causes all
            // sorts of other problems (esp. related to the scratch surface.)
            // So we show a modal dialog that is effectively invisible so that the user
            // cannot interact with the main window while the print dialog is still open.

            Form modal = new Form();
            modal.ShowInTaskbar = false;
            modal.TransparencyKey = modal.BackColor;
            modal.FormBorderStyle = FormBorderStyle.None;

            modal.Shown +=
                delegate(object sender, EventArgs e)
                {
                    cdc.ShowPhotoPrintingWizard(ref vector_o);
                    modal.Close();
                };

            modal.ShowDialog(owner);
            modal = null;

            Marshal.ReleaseComObject(cdc);
            cdc = null;

            Tracing.Leave();
        }
Beispiel #10
0
        private static ScanResult Scan(string fileName)
        {
            ScanResult result;

            WIA.CommonDialogClass cdc = new WIA.CommonDialogClass();
            WIA.ImageFile imageFile = null;

            try
            {
                imageFile = cdc.ShowAcquireImage(WIA.WiaDeviceType.UnspecifiedDeviceType,
                                                 WIA.WiaImageIntent.UnspecifiedIntent,
                                                 WIA.WiaImageBias.MaximizeQuality,
                                                 "{00000000-0000-0000-0000-000000000000}",
                                                 true,
                                                 true,
                                                 false);
            }

            catch (System.Runtime.InteropServices.COMException)
            {
                result = ScanResult.DeviceBusy;
                imageFile = null;
            }

            if (imageFile != null)
            {
                imageFile.SaveFile(fileName);
                result = ScanResult.Success;
            }
            else
            {
                result = ScanResult.UserCancelled;
            }

            return result;
        }
Beispiel #11
0
 private static void Print(string fileName)
 {
     WIA.VectorClass vector = new WIA.VectorClass();
     object tempName_o = (object)fileName;
     vector.Add(ref tempName_o, 0);
     object vector_o = (object)vector;
     WIA.CommonDialogClass cdc = new WIA.CommonDialogClass();
     cdc.ShowPhotoPrintingWizard(ref vector_o);
 }
Beispiel #12
0
                private void BotonCapturarImagen_Click(object sender, EventArgs e)
                {
#if WINDOWS
                        try {
                                WIA.CommonDialogClass WiaDialog = new WIA.CommonDialogClass();
                                WIA.ImageFile WiaImage = null;
                                
                                WiaImage = WiaDialog.ShowAcquireImage(
                                        WIA.WiaDeviceType.UnspecifiedDeviceType,
                                        WIA.WiaImageIntent.ColorIntent,
                                        WIA.WiaImageBias.MaximizeQuality,
                                        System.Drawing.Imaging.ImageFormat.Jpeg.Guid.ToString("B"), true, false, false);

                                if (WiaImage != null) {
                                        WIA.Vector vector = WiaImage.FileData;
                                        using (Entrada.AuxForms.ImagenRecorte Recorte = new Entrada.AuxForms.ImagenRecorte()) {
                                                Recorte.Imagen = System.Drawing.Image.FromStream(new System.IO.MemoryStream((byte[])vector.get_BinaryData()));
                                                if (Recorte.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
                                                        EntradaImagen.Image = Recorte.Imagen;
                                                        this.Changed = true;
                                                        this.ActualizarElemento();
                                                }
                                        }
                                }
                        } catch (Exception ex) {
                                Lui.Forms.MessageBox.Show("No se puede conectar con el dispositivo de captura. " + ex.Message, "Error");
                        }
#endif
                }
Beispiel #13
0
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                // parametros de scanner
                int resolucion  = 150;
                int anchoImagen = 1200;
                int altoImagen  = 1500;
                int modoColor   = 1;

                // la mas importante
                bool HayMasPaginas = true; // tiene mas paginas :)

                // ruta principal donde se guardan los archivos
                string rutaBase = string.Format("{0}\\{1}", Application.StartupPath, DateTime.Now.ToString("yyyMMddhhmmss"));

                Directory.CreateDirectory(rutaBase);

                // elegir escanner
                WIA.CommonDialog dialogoSeleccionaEscanner = new WIA.CommonDialog();
                WIA.Device       escaner = dialogoSeleccionaEscanner.ShowSelectDevice(WIA.WiaDeviceType.ScannerDeviceType, true, false);

                if (escaner != null)
                {
                    idEscaner = escaner.DeviceID;
                }
                else
                {
                    MessageBox.Show("No se eligió Escaner");
                    return;
                }

                int x             = 0;
                int numeroPaginas = 0;

                while (HayMasPaginas)
                {
                    // mientras la bandera de mas paginas este activa
                    // conectar escaner
                    // mostrando avance de escaneo
                    WIA.CommonDialog  dialogoEscaneo = new WIA.CommonDialogClass();
                    WIA.DeviceManager manager        = new WIA.DeviceManagerClass();
                    WIA.Device        dispoWIA       = null;

                    // cargando el dispositivo
                    foreach (WIA.DeviceInfo scannerInfo in manager.DeviceInfos)
                    {
                        if (scannerInfo.DeviceID == idEscaner)
                        {
                            WIA.Properties infoprop = null;
                            infoprop = scannerInfo.Properties;

                            dispoWIA = scannerInfo.Connect();

                            break;
                        }
                    }

                    // inicia escaneo
                    WIA.ImageFile imgEscaneo  = null;
                    WIA.Item      escanerItem = dispoWIA.Items[1] as WIA.Item;

                    AdjustScannerSettings(escanerItem, resolucion, 0, 0, anchoImagen, altoImagen, 0, 0, modoColor);

                    // tomando la imagen
                    imgEscaneo = (WIA.ImageFile)dialogoEscaneo.ShowTransfer(escanerItem, WIA.FormatID.wiaFormatPNG, false);

                    string RutaNombreEscaneo = String.Format("{0}\\{1}.png", rutaBase, x.ToString());

                    if (File.Exists(RutaNombreEscaneo))
                    {
                        //file exists, delete it
                        File.Delete(RutaNombreEscaneo);
                    }

                    imgEscaneo.SaveFile(RutaNombreEscaneo);
                    numeroPaginas++;
                    x++;
                    imgEscaneo = null;

                    // preguntar si hay mas documentos pendientes de escaneo
                    if (MessageBox.Show("¿Deseas escanear otro documento?. Antes de seleccionar 'Yes' Por favor introduzca el documento a escanear.", "Escaner", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    {
                        HayMasPaginas = false;
                    }
                }

                // una vez escaneado los dosucmentos, se hace un pdf con ellos para despues hacerlo zip
                // rutaBase es el nombre de la variable de la carpeta
                MessageBox.Show("Escaneo finalizado. Armando archivo pdf");
                string nombreArchivoPdf = string.Format("{0}\\{1}.pdf", rutaBase, DateTime.Now.ToString("yyyMMddhhmmss"));

                Document  pdfDoc = new Document(PageSize.LETTER, 2, 2, 2, 2);
                PdfWriter writer = PdfWriter.GetInstance(pdfDoc, new FileStream(nombreArchivoPdf, FileMode.CreateNew));

                pdfDoc.Open();

                // tomar las imagenes del escaneo
                for (int i = 0; i < x; i++)
                {
                    // tomar la imagen
                    string rutaImagen = String.Format("{0}\\{1}.png", rutaBase, i.ToString());

                    PdfContentByte cb = writer.DirectContent;

                    using (FileStream fsSource = new FileStream(rutaImagen, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        Image img = Image.GetInstance(fsSource);
                        img.ScaleToFit(pdfDoc.PageSize.Width, pdfDoc.PageSize.Height);
                        pdfDoc.Add(img);
                    }
                }

                pdfDoc.Close();

                MessageBox.Show("Archivo pdf generado. Generando archivo zip");

                // comprimir
                FileInfo        pdfFileInfo      = new FileInfo(nombreArchivoPdf);
                string          nombreArchivoZip = string.Format("{0}\\{1}.zip", rutaBase, DateTime.Now.ToString("yyyMMddhhmmss"));
                ZipOutputStream zipStream        = new ZipOutputStream(File.Create(nombreArchivoZip));
                zipStream.SetLevel(6);

                // abrir el archivo para escribirlo
                FileStream pdfFile = File.OpenRead(nombreArchivoPdf);
                byte[]     buffer  = new byte[pdfFile.Length];
                pdfFile.Read(buffer, 0, buffer.Length);

                // agregando el archivo a la carpeta comprimida
                ZipEntry entry = new ZipEntry(Path.GetFileName(nombreArchivoPdf))
                {
                    DateTime = pdfFileInfo.LastWriteTime,
                    Size     = pdfFile.Length
                };

                pdfFile.Close();

                Crc32 objCrc32 = new Crc32();
                objCrc32.Reset();
                objCrc32.Update(buffer);

                entry.Crc = objCrc32.Value;
                zipStream.PutNextEntry(entry);
                zipStream.Write(buffer, 0, buffer.Length);

                zipStream.Finish();
                zipStream.Close();

                MessageBox.Show("Archivo zip generado. Enviando archivo por FTP");

                // enviar el documento en ftp

                MessageBox.Show("proceso completo.");
            }
            catch (Exception ex)
            {
                // cachando errores com
                if (ex is COMException)
                {
                    // Convert the error code to UINT
                    uint errorCode = (uint)((COMException)ex).ErrorCode;

                    // See the error codes
                    if (errorCode == 0x80210006)
                    {
                        MessageBox.Show("The scanner is busy or isn't ready");
                    }
                    else if (errorCode == 0x80210064)
                    {
                        MessageBox.Show("The scanning process has been cancelled.");
                    }
                    else if (errorCode == 0x8021000C)
                    {
                        MessageBox.Show("There is an incorrect setting on the WIA device.");
                    }
                    else if (errorCode == 0x80210005)
                    {
                        MessageBox.Show("The device is offline. Make sure the device is powered on and connected to the PC.");
                    }
                    else if (errorCode == 0x80210001)
                    {
                        MessageBox.Show("An unknown error has occurred with the WIA device.");
                    }
                }
                else
                {
                    MessageBox.Show("Error " + ex.Message);
                }
            }
        }