I’m getting an error when converting some docs with field codes to PDF. It isn’t all field codes, because the TOC works fine. I am attaching a document that just contains one of the field codes causing problems. If there is any possible workaround, short of having users delete their field codes, I’d be interested in hearing it. The full stack trace and some example code is below.
ERROR MESSAGE: Unable to cast object of type ‘Aspose.Words.Fields.FieldSeparator’ to type ‘Aspose.Words.Run’.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Unable to cast object of type ‘Aspose.Words.Fields.FieldSeparator’ to type ‘Aspose.Words.Run’.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
CODE SAMPLE (where FileToConvert is from an upload control):
Dim uploadedDocument As New Document(Me.FileToConvert.FileContent)
uploadedDocument.SaveOptions.PdfExportImagesFolder = System.IO.Path.GetTempPath()
Using intermediateDocument As New System.IO.MemoryStream
uploadedDocument.Save(intermediateDocument, SaveFormat.AsposePdf)
Dim pdfDocument As New Aspose.Pdf.Pdf
pdfDocument.BindXML(intermediateDocument, Nothing)
Using resultBuffer As New System.IO.MemoryStream
pdfDocument.Save(resultBuffer)
DeliverBytes(resultBuffer.ToArray(), newName)
End Using
End Using
Thanks for your request. I managed to reproduce the problem on my side. You will be notified as soon as it is resolved.
Also, note, currently, Aspose.Words supports two ways of PDF conversion: direct conversion (without using Aspose.Pdf) and legacy conversion (Aspose.Words+Aspose.Pdf). See the following link for more information: https://docs.aspose.com/words/net/convert-a-document-to-pdf/
So, you can try using new method to convert your document to PDF. Here is the code:
Document doc = new Document("in.doc");
doc.SaveToPdf("out.pdf");
In this case exception does not occur.
Best regards.
Thanks for your response.
Do you have an example of SaveToPDF saving to a stream? I see a few parameters that I’m unsure of their purpose.
Also, is SaveToPDF “mature”? Or are there issues with it that don’t exist in the older method?
Hello!
Thank you for your patience.
I have addressed the issue with the exception. That’s not a problem to fix it but field code is still output incorrectly. We plan to fix this later and will notify you when we succeed.
I’ll explain technical reason of the problems with this document. MACROBUTTON field contains a nested field that is not processed properly. First of all you can remove it or suggest anything else regarding it. Next, enclose [Carpet Quality] into quotation marks. This will make Aspose.Words read display text properly and you will get exactly the same result as in Microsoft Word.
Regards,
The SaveToPDF solution you suggested appears to have an issue converting Word docs that have images in them. This seems to work fine in a development environment, but doesn’t seem to be working for others outside of development.
Any ideas why?
Does SaveToPDF require any special folder permissions on the server?
I’m using code identical to what you suggested, except in VB.Net.
Thanks for your inquiry. The SaveToPdf method does not require any special folder permissions. Could you please attach your document here for testing? I will check the problem on my side and provide you more information.
Best regards,
The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.