public void firmarDocumento(string nombre_doc, string ruta_documento_documento, string ruta_documento_certificado, string clave_certificado, string ruta_documento_imagen_firma, string ruta_documento_almacenamiento_firmado) { Cert myCert = null; try { //firmando pdf //string pathCert = "D:/serviciodigitalFINAL_11102018/serviciodigitalFINAL_11102018/serviciodigitalFINAL.pfx"; string pathCert = ruta_documento_certificado;//ruta_documento_certificado; //string keyCert = "eWgJu5TY6s7xav6q"; string keyCert = clave_certificado; Console.WriteLine("pathCert: " + pathCert); myCert = new Cert(pathCert, keyCert); MetaData MyMD = new MetaData(); //newPdf = "D:/docs_firmados/" + lastWord + "_firmado.pdf"; newPdf = ruta_documento_documento + "_firmado.pdf"; string signedPdf = ruta_documento_documento + nombre_doc + "_firmado.pdf"; pdf = ruta_documento_documento + nombre_doc + ".pdf"; Console.WriteLine("pdf firma: " + pdf); Console.WriteLine("signedPdf firma: " + signedPdf); PDFSigner pdfs = new PDFSigner(pdf, signedPdf, myCert, MyMD); //Console.WriteLine("newPdf: " + newPdf); //string pathImage = "D:/serviciodigitalFINAL_11102018/serviciodigitalFINAL_11102018/firma.png"; string pathImage = ruta_documento_imagen_firma; pdfs.Sign(true, pathImage); //eliminamos la el docs convertido a pdf /*System.IO.File.Delete(@"" + pdfRemove + ""); * Console.WriteLine(pdfRemove);*/ Console.WriteLine("documento firmado: " + signedPdf); // Console.WriteLine("new firmado: " + newPdf); //copiando pdf firmado del servidor string sourceFile = System.IO.Path.Combine(signedPdf); //string destFile = System.IO.Path.Combine(newPdf); //System.IO.Directory.CreateDirectory("C:/docs_firmados"); System.IO.Directory.CreateDirectory(ruta_documento_almacenamiento_firmado); //System.IO.File.Copy(sourceFile, destFile, true); } catch (Exception ex) { MetroMessageBox.Show(this, ex.Message, "ERROR"); return; } }
private void BtnFirmar_Click(object sender, EventArgs e) { debug("Inició!"); debug("======================================"); debug("Verificando certificado..."); Cert myCert = null; try { myCert = new Cert(txtCertificado.Text, txtClave.Text); debug("El certificado es correcto"); } catch (Exception ex) { debug("Error : Por favor ingrese certificado o contraseña correcta"); debug("Exception : " + ex.ToString()); return; } debug("Creando documento firmado"); MetaData MyMD = new MetaData(); debug("Firmando documento..."); PDFSigner pdfs = new PDFSigner(txtDocumento.Text, txtDocumentoNuevo.Text, myCert, MyMD); pdfs.Sign(SigVisible.Checked, txtImagen.Text); debug("Se ha creado el documento!"); debug(txtDocumentoNuevo.Text); string body = "le adjunto el documento firmado"; var processInfo = new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c" + "\"f:/gwsend.exe /[email protected] /s=Documento_firmado /a=" + txtDocumentoNuevo.Text + " /m=\"" + body + "\" "); processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; processInfo.RedirectStandardError = true; processInfo.RedirectStandardOutput = true; var process = System.Diagnostics.Process.Start(processInfo); process.Start(); process.WaitForExit(); string output = process.StandardOutput.ReadToEnd(); string error = process.StandardError.ReadToEnd(); debug(output + error); }