/// <summary> /// Agregar o inserta un código de barras en el documento especificado. /// La plantilla para generar el documento debe contener un campo que en su nombre contenga la palabra barcode. /// </summary> /// <param name="pathFileTemplate">Indica la ruta completa del documento base o plantilla para insertar el código de barras</param> /// <param name="fileNameOutput">Indica el nombre que se le dara al documento final.</param> /// <param name="pathDirectoryOutput">Indica la ruta del directorio de salida donde se almacena el documento final.</param> /// <param name="pathFileImage">Indica la ruta de ubicación de la imagen.</param> /// <param name="width">Indica el ancho de la imagen.</param> /// <param name="height">Indica el alto de la imagen.</param> /// <param name="formatOutput">Indica el formato de salida del documento final, debe incluirse el punto.</param> /// <returns>Devuelve un entero positivo o negativo que indica si el proceso se completo o no.</returns> public int AddBarCodeInDocument(string pathFileTemplate, string fileNameOutput, string pathDirectoryOutput, string pathFileImage, double width, double height, string formatOutput = ".docx") { int output = 0; try { if (!pathFileTemplate.FileExist()) { output = (int)TypesEvent.FileNotFound; return(output); } Document document = new Document(pathFileTemplate); var fieldBarCode = DocumentProcessor.FindFieldByKeyWord(document, "barcode"); if (fieldBarCode == null) { output = (int)TypesEvent.FieldNotFound; return(output); } string fieldName = DocumentProcessor.GetFieldNameInMergedField(fieldBarCode.DisplayResult); document.InsertImageInDocument(pathFileImage, fieldName, width, height); return(document.SaveDocument(pathDirectoryOutput, fileNameOutput, formatOutput)); } catch (UnsupportedFileFormatException) { output = (int)TypesEvent.UnsupportedFileFormat; } catch (FileCorruptedException) { output = (int)TypesEvent.FileCorrupted; } catch (IOException ioex) { var message = ioex.Message.ToLower(); if (message.Contains("porque está siendo utilizado en otro proceso")) { output = (int)TypesEvent.DocumentInOtherProccess; } else { output = (int)TypesEvent.ErrorGeneric; } } catch (Exception) { output = (int)TypesEvent.ErrorGeneric; } return(output); }
public int AddBarCodeInDocument(DocumentConfig documentConfig, BarCodeConfig barCodeConfig) { int output = 0; try { if (!documentConfig.FullPathTemplate.FileExist()) { output = (int)TypesEvent.FileNotFound; return(output); } Document document = new Document(documentConfig.FullPathTemplate); var fieldBarCode = DocumentProcessor.FindFieldByKeyWord(document, barCodeConfig.FieldBarCodeName); if (fieldBarCode == null) { output = (int)TypesEvent.FieldNotFound; return(output); } string fieldName = DocumentProcessor.GetFieldNameInMergedField(fieldBarCode.DisplayResult); document.InsertImageInDocument(barCodeConfig.FullPathImage, fieldName, barCodeConfig.Width, barCodeConfig.Height); return(document.SaveDocument(documentConfig.FullPathDirectory, documentConfig.FileName, documentConfig.Format)); } catch (UnsupportedFileFormatException) { output = (int)TypesEvent.UnsupportedFileFormat; } catch (FileCorruptedException) { output = (int)TypesEvent.FileCorrupted; } catch (IOException ioex) { var message = ioex.Message.ToLower(); if (message.Contains("porque está siendo utilizado en otro proceso")) { output = (int)TypesEvent.DocumentInOtherProccess; } else { output = (int)TypesEvent.ErrorGeneric; } } catch (Exception) { output = (int)TypesEvent.ErrorGeneric; } return(output); }
/// <summary> /// Agregar o inserta la imagen de la firma en el documento especificado. /// </summary> /// <param name="documentConfig">Es la configuración del documento.</param> /// <param name="signatureConfig">Es la configuración de la firma.</param> /// <returns>Devuelve un entero positivo o negativo que indica si el proceso se completo o no.</returns> public int AddSignatureInDocument(DocumentConfig documentConfig, SignatureConfig signatureConfig) { int output = 0; try { if (!documentConfig.FullPathTemplate.FileExist()) { output = (int)TypesEvent.FileNotFound; return(output); } Document document = new Document(documentConfig.FullPathTemplate); var fieldSignatures = DocumentProcessor.FindFieldByKeyWord(document, signatureConfig.FieldSignatureName); if (fieldSignatures == null) { output = (int)TypesEvent.FieldNotFound; return(output); } string fieldSignature = DocumentProcessor.GetFieldNameInMergedField(fieldSignatures.DisplayResult); document.InsertImageInDocument(signatureConfig.FullPathImage, fieldSignature, signatureConfig.Width, signatureConfig.Height); if (!string.IsNullOrEmpty(signatureConfig.FieldFooterName)) { var footerField = DocumentProcessor.FindFormFieldByKeyWord(document, signatureConfig.FieldFooterName); if (footerField == null) { output = (int)TypesEvent.FieldNotFound; return(output); } footerField.Result = signatureConfig.FieldFooterValue; } return(document.SaveDocument(documentConfig.FullPathDirectory, documentConfig.FileName, ".docx")); } catch (UnsupportedFileFormatException) { output = (int)TypesEvent.UnsupportedFileFormat; } catch (FileCorruptedException) { output = (int)TypesEvent.FileCorrupted; } catch (IOException ioex) { var message = ioex.Message.ToLower(); if (message.Contains("porque está siendo utilizado en otro proceso")) { output = (int)TypesEvent.DocumentInOtherProccess; } else { output = (int)TypesEvent.ErrorGeneric; } } catch (Exception ex) { output = (int)TypesEvent.ErrorGeneric; } return(output); }