示例#1
0
        public void GeretatePDF(AuxFile auxFile, List <KeyWordFile> listKeyWord)
        {
            string res = string.Empty;

            try
            {
                //Validacion del Directorio
                ValidateDirectory(ConfigurationManager.AppSettings["DirectoryTempFile"]);
                auxFile.FullTempPath = ConfigurationManager.AppSettings["DirectoryTempFile"] + auxFile.Name + DateTime.Now.ToString("yyyyMMddhhmmss") + "." + auxFile.Extention;
                //Creacion del Archivo Temporal
                if (GenerateTempFile(auxFile))
                {
                    //Se Procesa el archivo Temporal
                    if (ProcessFile(auxFile.FullTempPath, listKeyWord))
                    {
                        //Se Genera el archivo PDF
                        ValidateDirectory(ConfigurationManager.AppSettings["DirectoryPDFFile"]);
                        //Generacion Archivo PDF
                        Microsoft.Office.Interop.Word.Document    wordDocument;
                        Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
                        wordDocument = appWord.Documents.Open(auxFile.FullTempPath);
                        var auxRes = ConfigurationManager.AppSettings["DirectoryPDFFile"] + auxFile + DateTime.Now.ToString("yyyyMMddhhmmss") + ".pdf";
                        wordDocument.ExportAsFixedFormat(auxRes, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF);
                        //appWord.Documents.Close();
                        wordDocument.Close();
                        res = auxRes;
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#2
0
        private bool GenerateTempFile(AuxFile auxFile)
        {
            bool res = false;

            try
            {
                Byte[] bytes = Convert.FromBase64String(auxFile.Base64);
                File.WriteAllBytes(auxFile.FullTempPath, bytes);
                res = true;
            }
            catch (Exception ex)
            {
                throw;
            }
            return(res);
        }
示例#3
0
 public void GeretatePDFTest()
 {
     try
     {
         byte[]  bytes   = File.ReadAllBytes("C:/Users/lsamaniego/Documents/EjemploPlantilla.docx");
         string  file64  = Convert.ToBase64String(bytes);
         AuxFile auxFile = new AuxFile()
         {
             Base64       = file64,
             Extention    = "docx",
             FullTempPath = "",
             Name         = "EjemploPlantilla"
         };
         var listKeyWord = new List <KeyWordFile>()
         {
             new KeyWordFile()
             {
                 Code  = "«afDia»",
                 Value = "01"
             }, new KeyWordFile()
             {
                 Code  = "«afMes»",
                 Value = "Octubre"
             }, new KeyWordFile()
             {
                 Code  = "«afAnio»",
                 Value = "17"
             }
         };
         formularyService.GeretatePDF(auxFile, listKeyWord);
         Assert.IsTrue(true);
     }
     catch (Exception ex)
     {
         Assert.Fail();
     }
 }