static void Main(string[] args) { var t = new ExportadorDocumentosLaserfiche <Something>(); t.ExportarAsync(new List <DocumentoRepositorio>(), "", true).ConfigureAwait(false); SqlConnection con = new SqlConnection(); Trace.Listeners.Add(new ConsoleTraceListener()); //Conectamos a Laserfiche LFConnection conexionLF = new LFConnection(); conexionLF.UserName = "******"; conexionLF.Password = "******"; LFApplication aplicacionLF = new LFApplication(); LFServer servidorLF = aplicacionLF.GetServerByName("ServerWA"); LFDatabase baseDeDatosLF = servidorLF.GetDatabaseByName("DA-HINOJOSA"); //Se obtienen las referencias que se encuentran en try { Trace.WriteLine("Conectando a laserfiche"); conexionLF.Create(baseDeDatosLF); //conexionLF.Connect(baseDeDatosLF); Trace.WriteLine("Conectado"); //LFSearch busquedaLF = baseDeDatosLF.CreateSearch(); //busquedaLF.Command = "{LF:LOOKIN=\"DA-HINOJOSA\\MANZANILLO\\2018\\GALVAPRIME, S.A. DE C.V. ID2281\\IMPO\\Z1801770-0A\", Subfolders=0} & {LF:Name=\"PEDIMENTO FORMATO ANTERIOR\", TYPE=\"D\"}"; Trace.WriteLine("Inicia búsqueda"); //busquedaLF.BeginSearch(true); Trace.WriteLine("Busqueda finalizada"); //ILFCollection coleccionLF = busquedaLF.GetSearchHits(); //14694366 //var doc2 = baseDeDatosLF.GetEntryByID(14658218); var doc2 = baseDeDatosLF.GetEntryByID(14694366); LFDocument doc = doc2 as LFDocument; ILFEntry entry = doc2 as ILFEntry; var pe = new PdfExporter.PdfExporter(); //doc.ElectFile.WriteStream. //long size = doc.ElectFileSize; //byte[] buffer = new byte[size]; //doc.ElectFile.ReadStream.Open(); //doc.ElectFile.ReadStream.ReadToBuffer(buffer); //doc.ElectFile.ReadStream.Close(); //using (FileStream st = File.Create("something")) //{ // st.Write(buffer, 0, Convert.ToInt32(size)); // st.Flush(); //} //doc.ElectFile.WriteStream. var exportador = new DocumentExporter(); exportador.SourceDocument = entry; //exportador.SourceDocument = doc.; // exportador. //exportador. if (doc.ElectFile.MimeType == "application/pdf") { try { doc.ElectFile.ReadStream.Open(); doc.ElectFile.ReadStream.Export(@"c:\users\analista.programador\downloads\lf\" + doc.Name + ".pdf"); }catch (Exception ex) { throw ex; } finally { doc.ElectFile.ReadStream.Close(); } var doc3 = (doc.ElectFile.Document as ILFDocument); pe.ExportPagesToFile(doc3, @"c:\users\analista.programador\downloads\lf\" + doc.Name + ".pdf"); } else { //exportador.Format = Document_Format.DOCUMENT_FORMAT_EMBED_FAVOR_PDFA; //exportador.ExportToFile(@"c:\users\analista.programador\downloads\lf\" + doc.Name + ".pdf"); exportador.Format = Document_Format.DOCUMENT_FORMAT_TIFF; exportador.ExportToFile(@"c:\users\analista.programador\downloads\lf\" + doc.Name + "2"); } //foreach (LFSearchHit laserficheHit in coleccionLF) //{ // LFDocument entradaLF = laserficheHit.Entry as LFDocument; // //LFElectFile entradaLF2 = laserficheHit.Entry as LFElectFile; // Console.WriteLine(entradaLF.ElectFile.Extension); // //entradaLF. // var exportador = new DocumentExporter(); // exportador.SourceDocument = entradaLF; // Trace.WriteLine("Iniciando descarga de " + entradaLF.Name); // exportador.Format = Document_Format.DOCUMENT_FORMAT_EMBED_FAVOR_PDFA; // exportador.ExportToFile(@"c:\users\analista.programador\downloads\lf\" + entradaLF.Name + ".pdf" ); // exportador.Format = Document_Format.DOCUMENT_FORMAT_TIFF; // exportador.ExportToFile(@"c:\users\analista.programador\downloads\lf\" + entradaLF.Name + "2"); // exportador.Format = Document_Format.DOCUMENT_FORMAT_ELECTRONICFILE; // exportador.ExportToFile(@"c:\users\analista.programador\downloads\lf\" + entradaLF.Name + "3"); //} //using(FileStream file = File.Create("")) //{ // StreamWriter sw = new StreamWriter(file); // sw.WriteLine(""); // sw.Flush(); //} } catch (Exception exc) { Trace.TraceError(exc.Message); } finally { if (!conexionLF.IsTerminated) { conexionLF.Terminate(); Trace.WriteLine("Desconectado"); } } Console.ReadKey(); }
public void Exportar(IEnumerable <DocumentoRepositorio> documentos, string ruta, bool zip, Func <DocumentoRepositorio, string> rutaInterna) { foreach (DocumentoRepositorio documento in documentos) { DocumentInfo informacionDocumento = documento.DocumentoAsociado as DocumentInfo; string directorioInterno = rutaInterna.Invoke(documento); //Crear los directorios internos string[] subdirectorios = directorioInterno.Split('\\'); string rutaActual = ruta; rutaActual += !rutaActual.EndsWith("\\") ? "\\" : ""; for (int i = 0; i < subdirectorios.Length; i++) { rutaActual += subdirectorios[i]; DirectoryInfo directorio = new DirectoryInfo(rutaActual); if (!directorio.Exists) { directorio.Create(); } rutaActual += "\\"; } rutaActual += !rutaActual.EndsWith("\\") ? "\\" : ""; var exportadorDocumentos = new DocumentExporter(); if (informacionDocumento.IsElectronicDocument) { if (!File.Exists(rutaActual + documento.Nombre + "." + informacionDocumento.Extension)) { documento.Nombre = documento.Nombre.Replace("/", "_").Replace("*", "_").Replace("\\", "_").Replace(":", "_").Replace("\"", "_").Replace('<', '_').Replace('>', '_').Replace('|', '_'); exportadorDocumentos.ExportElecDoc(informacionDocumento, rutaActual + documento.Nombre + "." + informacionDocumento.Extension); } } else { //En ocasiones hay documentos TIFF (escaneados) que no tienen páginas, en este caso bypasear if (informacionDocumento.PageCount <= 0) { continue; } var rangoPaginas = new PageRange(1, informacionDocumento.PageCount); var configuracionPaginas = new PageSet(rangoPaginas); string nombre = informacionDocumento.Name; if (nombre.Contains("*") && string.IsNullOrEmpty(informacionDocumento.TemplateName)) { nombre = informacionDocumento.TemplateName; } nombre = nombre.Replace("/", "_").Replace("*", "_").Replace("\\", "_").Replace(":", "_").Replace("\"", "_").Replace('<', '_').Replace('>', '_').Replace('|', '_'); if (!File.Exists(rutaActual + nombre + ".pdf")) { exportadorDocumentos.ExportPdf(informacionDocumento, configuracionPaginas, PdfExportOptions.None, rutaActual + nombre + ".pdf"); } } } if (zip) { Zippear(ruta); } }