You are viewing limited content. For full access, please sign in.

Question

Question

Exporting document as file Stream or memory stream instead of saving it to disk ?

asked on September 26, 2022

I am facing a performance and security issue while working with documents on Laserfiche

so each time I have to export document from Laserfiche to save it on the disk and work it.

Is there any way to export document a FileStream or Memeoy Streams instead of saving the document?

Current code for exporting document:

RepositoryRegistration repository = new RepositoryRegistration(serverName, repositoryName);
                using (Session session = new Session())
                {
                    session.LogIn(userName, password, repository);
                
                     docInfo = Document.GetDocumentInfo(lfDocId, session);
                   
                    docExt = docInfo.Extension;
                    var documentName = docInfo.Name;
                    documentName = docInfo.Name;
                    saveFilepath = $"{saveImportedPath}{documentName}.{docExt}";
          
                    DocumentExporter exporter = new DocumentExporter();
                    exporter.ExportElecDoc(docInfo, saveFilepath);                  
                    // log out of the repository
                    session.LogOut();
                }

Thanks

0 0

Replies

replied on September 27, 2022

It's actually pretty easy. Here's a VB version.

 

This exports pdf files, 

  'Make sure we have something to export
            If LF_PageSet.GetTotalPageCount > 0 Then

                'Set the Exporter Properties
                With LF_DocExporter
                    .IncludeAnnotations = False
                    .BlackoutRedactions = False

                    'Tiff format:
                    .PageFormat = DocumentPageFormat.Tiff

                    'Export the Document
                    .ExportPdf(LF_DocInfo, LF_PageSet, PdfExportOptions.None, msMemoryStream)
                    ExportedByte = msMemoryStream.ToArray
                    ExportImageAsPDFToByteStream = ExportedByte
                End With

            Else
                sMessage = ("Document # " & nDocID & " has no pages and cannot be exported.")
                WriteLogErrors.WriteMessage(Now & " " & sMessage)
            End If

And this exports tif files:

                'Set the Exporter Properties
                With LF_DocExporter
                    .IncludeAnnotations = False
                    .BlackoutRedactions = False

                    'Tiff format:
                    .PageFormat = DocumentPageFormat.Tiff

                    'Export the Document
                    .ExportPages(LF_DocInfo, LF_PageSet, msMemoryStream)
                    ExportedByte = msMemoryStream.ToArray
                    ExportImageAsTIFFToByteStream = ExportedByte

                End With

            Else
                sMessage = ("Document # " & nDocID & " has no pages and cannot be exported.")
                WriteLogErrors.WriteMessage(Now & " " & sMessage)
            End If

 

0 0
replied on September 27, 2022

There's an overload of ExportElecDoc that accepts a Stream parameter.

0 0
replied on September 27, 2022

Hola Issac,

We apply this method to export electronic files

-------------------------------------------

Imports DocumentProcessor83
Imports LFSO83Lib
Imports Microsoft.VisualBasic

Namespace WorkflowActivity.Scripting.ExportaContenidoContigenciaDirectorio
    Public Class ImportarArchivo
        Inherits SDKScriptClass83
        Protected Overrides Sub Execute()

           Dim StrOrigen              as String            = TokenReplace("%(ID Documento)")
           Dim StrDestino             as String            = TokenReplace("%(Destino)")
           Dim LgcError                as Boolean        = False
           Dim StrError                  as String           = "NO"
           Dim LgcConexion         as Boolean        = False
           Dim objContenido        as LFDocument = Database.GetEntryById(StrOrigen)
           Dim StrNmbContenido as String            = objContenido.Name.ToUpper
           Dim StrComillas            as String             = """"
           If StrNmbContenido.IndexOf(".PDF") <= 0 Then StrNmbContenido = StrNmbContenido & ".PDF"
          '-------------- Inicia Exporta el contenido al disco local --------------
           ' Instancia el nuevo documento
           Dim DocEx As New DocumentExporter
           ' Configura propiedades del contenido origen
           DocEx.SourceDocument = Database.GetEntryById(StrOrigen)
           ' COnfigura el formato del contenido destino
           DocEx.Format = Document_Format.DOCUMENT_FORMAT_ELECTRONICFILE
           ' Exporta el contenido
           StrDestino = StrDestino & StrNmbContenido
           DocEx.ExportToFile(StrDestino)
           Try
            DocEx.ExportToFile(StrDestino)
            Catch ex As System.Runtime.InteropServices.COMException
            LgcError = True
           End Try
           If LgcError = True
            StrError = "Error --> Comando DOS " & StrError
           End If
           SetToken("%Error", StrError)
        End Sub
    End Class
End Namespace

------------------------------

Luck

 

0 0
replied on September 27, 2022

LFSO83 is over 10 years old. Please use a newer version of RepositoryAccess instead.

0 0
replied on September 27, 2022

An example using Laserfiche.RepositoryAccess

Export_FS.txt (1.97 KB)
0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.