Free Support Forum - aspose.com

Error: There is no current object

I get this error when I try to convert the attached document to pdf. I use Aspose.Words 9.4.1.0


Code:

Public Shared Function ConvertWordToPDF(ByVal inputFilename As String) As MemoryStream
Using inputstream As FileStream = File.Open(inputFilename, FileMode.Open)
Return ConvertWordToPDF(inputstream)
End Using
End Function

Public Shared Function ConvertWordToPDF(ByRef inputStream As Stream) As MemoryStream
Dim info As FileFormatInfo = FileFormatUtil.DetectFileFormat(inputStream)
Dim stream As New MemoryStream()
Dim doc As New Document(inputStream)
Dim shapes As NodeCollection = doc.GetChildNodes(NodeType.Shape, True)

’ Loop through all shapes.
For Each shape As Shape In shapes
’ If shape contains a vector image, convert it to raster image.
If shape.HasImage AndAlso (shape.ImageData.ImageType = ImageType.Wmf OrElse shape.ImageData.ImageType = ImageType.Emf) Then
Using vectorImageStream As New MemoryStream(shape.ImageData.ImageBytes)
Using image As System.Drawing.Image = System.Drawing.Image.FromStream(vectorImageStream)
Using resterImageStream As New MemoryStream()
image.Save(resterImageStream, ImageFormat.Png)
shape.ImageData.SetImage(resterImageStream)
End Using
End Using
End Using
End If
Next
Try
doc.Save(stream, SaveFormat.Pdf)
Catch ex As Exception
doc.Save(stream, SaveFormat.Pdf)
End Try
Return stream
End Function

Hi

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

Thank you for reporting this problem to us. I managed to reproduce it on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

Best regards,

The issues you have found earlier (filed as 20475) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Here is the code I am using where I am running into this same error ("There is no current object")....

public static byte[] ConvertDocumentToPdfBytes(Document doc)

{

byte[] pdfBytes = null;

using (var pdfStream = new MemoryStream())

{

doc.Save(pdfStream, SaveFormat.Pdf);

pdfBytes = pdfStream.ToArray();

}

return pdfBytes;

}

Question: Is there another work around so I will not get this error?

Question: What causes this error to begin with? Does it have to do with how the Word document got created or something in the document? I am just wondering why some docs convert fine and others don't.

We have several word documents that get coverted to pdf using this same code but a few are breaking on the "doc.Save(pdfStream, SaveFormat.Pdf);" line.

I am planning on getting the new version/upgrade that came out recently, I just want to know how I could get around this in the time being.

Thanks,

Hello

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

Thank you for additional information. Could you please attach the documents you are getting problem with? I will check them on my side and provide you more information.

Best regards,

Hi

Thanks for your request. I checked the issue one more time on my side and all works fine. I use the latest version of Aspose.Words for testing. Please make sure that you are using the latest version in your application. You can download it from here:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/category1188.aspx

The issue was closed with “Cannot Reproduce” resolution. This means that some other changes fixed the problem. So unfortunately, I cannot tell you what the root cause of the problem was.

Best regards,

Of course, thank you for the quick response :)

I have attached the file.

Hello,

Thank you for additional information. I managed to reproduce your problem on my side. I created the appropriate issue in our defect database. Once the problem is resolved you will immediately receive a notification.

That's great news! Thank you!

Adding this email string to keep track of the follow up for this post....

Sent From: charlene
Subject: Your Reply to: 289230
__________________________________

Hello Viktor,

Thank you for taking the time to reproduce our issue with the doc.save() method when coverting a word document to a pdf file. We would like to tell our customers what they should avoid doing to prevent this issue. Can you tell me more about the root cause and how to change our letter to avoid this error.

Thank you, Charlene Wahl

Sent From: Viktor Kazmiruk
Subject: RE: Your Reply to: 289230
__________________________________

Hello,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for your request.

Unfortunately at the moment I can't tell you the cause of the problem. Once developers will analyze the issue, we will notify you immediately. Would also like to ask you, please ask questions at the forum, it is very important to us.

**Aspose - No response needed

A fix for the issue(s) you've reported (filed as 25000) will be released in the next release at the end of this month. You will be notified.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as WORDSNET-4489) have been fixed in this .NET update and in this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.