Free Support Forum - aspose.com

PDF conversion fails OutOfMemoryException

OutOfMemoryException Converting to PDF<?xml:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /><o:p></o:p>

Why?

Manuel Fernandez

Public Function Convertir(ByVal FicheroOriginal As String, ByRef FicheroConvertido As String) As Boolean Implements IConversor.Convertir

Dim FicheroTemporalXML As String = String.Empty

Try

' Licenciamos los componentes

Dim LicenciaWORD As New Aspose.Words.License() : LicenciaWORD.SetLicense("Aspose.Total.lic")

Dim LicenciaPDF As New Aspose.Pdf.License() : LicenciaPDF.SetLicense("Aspose.Total.lic")

' Cargamos el documento a memoria y lo guardamos en formato intermedio (XML) en un fichero temporal

FicheroTemporalXML = System.IO.Path.GetTempFileName()

Dim DocumentoWORD As Aspose.Words.Document = New Aspose.Words.Document(FicheroOriginal)

DocumentoWORD.Save(FicheroTemporalXML, Aspose.Words.SaveFormat.AsposePdf)

' Cargamos el fichero intermemedio en Aspose.Pdf.

Dim DocumentoPDF As Aspose.Pdf.Pdf = Nothing

DocumentoPDF = New Aspose.Pdf.Pdf()

DocumentoPDF.BindXML(FicheroTemporalXML, Nothing)

' Le indicamos que deseamos que se borren los ficheros temporales para imagenes

DocumentoPDF.IsImagesInXmlDeleteNeeded = True

' Modificamos las propiedades del documento

DocumentoPDF.Author = DocumentoWORD.BuiltInDocumentProperties.Author

DocumentoPDF.Creator = "ServEx - Servidor de Expedientes"

DocumentoPDF.Subject = DocumentoWORD.BuiltInDocumentProperties.Subject

DocumentoPDF.Title = DocumentoWORD.BuiltInDocumentProperties.Title

DocumentoPDF.Producer = "ServEx - Servidor de Expedientes"

DocumentoPDF.Keywords = DocumentoWORD.BuiltInDocumentProperties.Keywords

' Opciones sobre el formato del archivo

DocumentoPDF.OpenType = Aspose.Pdf.OpenType.Auto

DocumentoPDF.DestinationType = Aspose.Pdf.DestinationType.FitWidth

DocumentoPDF.CompressionLevel = 9

' Produce the PDF file.

DocumentoPDF.Save(System.IO.Path.ChangeExtension(FicheroOriginal, ".PDF"))

FicheroConvertido = System.IO.Path.ChangeExtension(FicheroOriginal, ".PDF")

Convertir = True

Catch ex As Exception

Dim mensaje As String = String.Format("No se ha podido convertir el fichero {0} a PDF.", FicheroOriginal)

TrazaError(mensaje, ex)

Throw New ApplicationException(mensaje, ex)

Finally

' Intentamos borrar el fichero temporal

Try : System.IO.File.Delete(FicheroTemporalXML) : Catch nada As Exception : End Try

End Try

Hi Manuel.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

The issue is common for several documents and I’ve answered in the following thread:

http://www.aspose.com/Community/Forums/thread/105869.aspx

Regards,