Private Function PDFConverion(ByRef WordPath As String, ByRef PDFPath As String, ByRef waitTime As Short) As Boolean
Dim result As Boolean = False
Dim ConversionComplete As Boolean = False
Dim WordsLicense As New Aspose.Words.License
WordsLicense.SetLicense("Aspose.Total.lic")
Dim PdfLicense As New Aspose.Pdf.License
PdfLicense.SetLicense("Aspose.Total.lic")
Try
Dim doc As Aspose.Words.Document = New Aspose.Words.Document(WordPath)
Dim xmlFileName As String = Mid(WordPath, 1, InStr(WordPath, ".") - 1) & ".xml"
'Save the document in Aspose.Pdf.Xml format
doc.Save(xmlFileName, Aspose.Words.SaveFormat.AsposePdf)
'Read the document in Aspose.Pdf.Xml format into Aspose.Pdf
Dim pdf As New Aspose.Pdf.Pdf
pdf.BindXML(xmlFileName, Nothing)
'delete temporary image file
pdf.IsImagesInXmlDeleteNeeded = True
'code to speed up conversion
pdf.IsTruetypeFontMapCached = True
pdf.TruetypeFontMapPath = System.IO.Path.GetTempPath()
Dim objRandomGenerator As New Random
PDFPath = _TempFolder & objRandomGenerator.Next(System.Int32.MaxValue) & ".PDF"
'produce the pdf file
pdf.Save(PDFPath)
'check the pagecount property - greater than zero means the conversion is complete.
Do While Not ConversionComplete
If pdf.PageCount > 0 Then
ConversionComplete = True
End If
Loop
result = True
Catch ex As Exception
Throw ex
result = False
End Try
Return result
End Function
I am getting a timeout error when this code is run on our production server. It runs fine on our test server. Originally I had use the Thread.Sleep function to wait 45 seconds to make sure the conversion is complete but I modified the code to try and speed the conversion up. Any ideas?