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
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,
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,
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: https://releases.aspose.com/words/net
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,
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.
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,
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