Conversion from Word Docuiment to PDF using XML Stream - Freezes when saving the PDF

I am using ASPose to convert Word documents into PDF documents. I am running ASPose in trial evaluation mode without a license. I have run a bulk conversion of our CVs, using a memory stream to convert the documents to PDF. The majority of these CVs have converted without any problems.

There are a minority of CVs which appear to be causing the conversion process to hang. I am running my conversion function ConvertWordDoc (please see code below) from within an ASPX web page under .NET Framework version 1.1.

The conversion process is converting the Word document to PDF using a memory stream and is being run with the mode parameter set to ConvertWordDocumentMode.ToPDFStream.

The conversion process is freezing when the statement pdf.Save is executed. I have waited up to 20 minutes for this function to finish but it always remains frozen. On occasions, it is returning an IIS out of memory error message which forces me to reboot the web server.

An empty PDF file of zero size is left after the process is abandoned.

I have attached a sample of one of the documents that is causing the process to freeze. This document will always cause the process to hang.

I would be grateful if you could investigate and try and replicate this problem.

Thanks in Advance,

Chris Hurrell


Public Shared Function ConvertWordDocument(ByVal mode As ConvertWordDocumentMode, ByVal inputfilename As String, ByVal outputfilename As String, ByRef errormessage As String) As String

    ' Transform document using ASPose
    ' ---------------------------------

    Dim s_save As String
    Dim s As String

    Try
        ' Open the DOC file using Aspose.Words.
        Dim doc As Aspose.Words.Document = New Aspose.Words.Document(inputfilename)

        Select Case mode
            Case ConvertWordDocumentMode.ToHTML
                ' Save the document in HTML format into a file
                doc.Save(outputfilename, SaveFormat.Html)
                s_save = outputfilename
            Case ConvertWordDocumentMode.ToHTMLString
                ' Save the document in HTML format into a memory stream and return as string
                Dim stream1 As MemoryStream = New MemoryStream
                doc.Save(stream1, SaveFormat.Html)

                ' Seek to the beginning so it can be read by XmlDocument.
                stream1.Seek(0, SeekOrigin.Begin)

                Dim tr As New System.IO.StreamReader(stream1)
                s_save = tr.ReadToEnd
            Case ConvertWordDocumentMode.ToPDFStream
                ' Save the document in Aspose.Pdf.Xml format into a memory stream.
                ' Was failing when images were present in the Word document.
                ' Changing security permissions on the Windows temporary folder has resolved this.
                ' Images are temporarily saved to the Windows temporary folder.

                Dim stream As MemoryStream = New MemoryStream
                doc.Save(stream, SaveFormat.AsposePdf)

                ' Seek to the beginning so it can be read by XmlDocument.
                stream.Seek(0, SeekOrigin.Begin)

                ' Load the document into an XmlDocument
                Dim xmlDoc As XmlDocument = New XmlDocument
                xmlDoc.Load(stream)

                ' Load the XML document into Aspose.Pdf
                Dim pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf
                pdf.BindXML(xmlDoc, Nothing)

                ' Make sure the images that were saved by Aspose.Words into the Windows temporary
                ' folder are automatically deleted by Aspose.Pdf when they are no longer needed.
                pdf.IsImagesInXmlDeleteNeeded = True

                ' Now produce the PDF file.
                pdf.Save(outputfilename)
                s_save = outputfilename

                stream.Close()
                stream = Nothing
                xmlDoc = Nothing
                pdf = Nothing
            'Case ConvertWordDocumentMode.ToPDFXML
            ' ' Save the document in Aspose.Pdf.Xml by using an intermediate XML file
            ' '----------------------------------------------------------------------
            ' ' This is failing with the error message when saving the .pdf to a mapped network file
            ' ' "Logon failure: unknown username or password"
            ' ' Works ok if saved to a local folder.
            ' ' If we are to use this, we need to save to a local folder on the web server.

            ' Dim s_temporary_xmlfile As String
            ' s_temporary_xmlfile = Left(outputfilename, Len(outputfilename) - 4) & "_Temp.xml"
            ' ' You can merge data/manipulate document content here.
            ' ' Save the document in Aspose.Pdf.Xml format.
            ' doc.Save(s_temporary_xmlfile, SaveFormat.AsposePdf)
            ' ' Read the document in Aspose.Pdf.Xml format into Aspose.Pdf.
            ' Dim pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf
            ' pdf.BindXML(s_temporary_xmlfile, Nothing)
            ' ' Instruct to delete temporary image files.
            ' pdf.IsImagesInXmlDeleteNeeded = True
            ' ' Produce the PDF file.
            ' pdf.Save(outputfilename)
            ' s_save = outputfilename
            ' pdf = Nothing

        End Select

        doc = Nothing
        errormessage = ""
    Catch ex As Exception
        errormessage = ex.Message
    End Try

    Return s_save
End Function

Thank you for considering Aspose.

I have reproduced this error. We will fix it ASAP.

It seems there are some errors in the xml generated by Aspose.Words. We need to contact the Aspose.Words team to fix this problem.

Thanks for your speedy response.

I am glad that you have managed to replicate the problem.

I look forward to a fix for this problem.

Regards

Chris Hurrell

Is there a fix available for this problem yet please?

Hi,

I have tested this document with the latest versions of Aspose.Words and Aspose.Pdf and didn't get the problems you had reported earlier. So the issues have been resolved.

Thanks.