Imports System.Data.OleDb
Imports MySql.Data.MySqlClient
Imports DevExpress.Office.Services
'Imports DevExpress.Web
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.Native
Imports DevExpress.XtraRichEdit.Model
Imports DevExpress.XtraReports.UI
Imports System.Data

Namespace Utilidades
    Public Class odt




        Public Shared Sub ExportarApdf(FicheroOrigen As String, FicheroDestino As String)
            Try
                Dim docServer As New RichEditDocumentServer
                docServer.LoadDocument(FicheroOrigen, DevExpress.XtraRichEdit.DocumentFormat.OpenDocument)
                docServer.Options.Export.Html.EmbedImages = True

                Dim fs As New IO.FileStream(FicheroDestino, IO.FileMode.Create, IO.FileAccess.Write)
                docServer.ExportToPdf(fs)
                fs.Close()
                docServer.Dispose()
                GC.Collect()
                GC.WaitForPendingFinalizers()
            Catch ex As Exception
                Throw New Exception(ex.Message, ex)
            End Try
        End Sub
        Public Shared Function ExportarApdf(FicheroOrigen As String) As Byte()
            Try
                Dim docServer As New RichEditDocumentServer
                docServer.LoadDocument(FicheroOrigen, DevExpress.XtraRichEdit.DocumentFormat.OpenDocument)
                docServer.Options.Export.Html.EmbedImages = True

                Dim po As New PdfExportOptions
                po.Compressed = True
                Dim ms As New IO.MemoryStream
                docServer.ExportToPdf(ms, po)
                If ms.CanSeek Then ms.Seek(0, 0)
                Dim b = ms.ToArray
                docServer.Dispose()
                GC.Collect()
                GC.WaitForPendingFinalizers()
                Return b
            Catch ex As Exception
                Throw New Exception(ex.Message, ex)
            End Try
        End Function
        Public Shared Sub ExportarApdf(Documento As IO.Stream, Destino As IO.Stream)
            Try
                Dim docServer As New RichEditDocumentServer
                docServer.LoadDocument(Documento, DevExpress.XtraRichEdit.DocumentFormat.OpenDocument)
                docServer.Options.Export.Html.EmbedImages = True

                Dim po As New PdfExportOptions
                po.Compressed = True
                'po.PageRange = "1-10"

                docServer.ExportToPdf(Destino, po)
                docServer.Dispose()
                GC.Collect()
                GC.WaitForPendingFinalizers()
            Catch ex As Exception
                Throw New Exception(ex.Message, ex)
            End Try
        End Sub
        Public Shared Function ExportarApdf(Documento As IO.Stream) As Byte()
            Try
                Dim docServer As New RichEditDocumentServer
                docServer.LoadDocument(Documento, DevExpress.XtraRichEdit.DocumentFormat.OpenDocument)
                docServer.Options.Export.Html.EmbedImages = True

                Dim po As New PdfExportOptions
                po.Compressed = True
                'po.PageRange = "1-10"

                Dim ms As New IO.MemoryStream
                docServer.ExportToPdf(ms, po)
                docServer.Dispose()
                GC.Collect()
                GC.WaitForPendingFinalizers()
                Return ms.ToArray
            Catch ex As Exception
                Throw New Exception(ex.Message, ex)
            End Try
        End Function

    End Class
End Namespace