Free Support Forum -

Error when using sample code for Aspose.Word

When i try to generate a pdf file using the aspose.word demo code i get an object reference error. I have downloaded and installed the pdf dll and set a reference to them in my project. What am i doing wrong. The creation ms word docs works great, but any other format fails.

I intend on licensing both the word and pdf modules as soon as i get this worked out.



Thank you for considering Aspose.

Please post the code you are using and attach your document template.

Below is the code that i am using, it is what comes with the msi package for Aspose.Word. I have left the commented lines in place in an effort to demonstrate what i have done to try and resolve this on my own. Attached is the large document template i am using to create the mailmerge. The MS Word Doc creation work great but when i try to create pdf files i get the previously attached error. If i set doc = to a new document the creation is successful, but the document is blank.

Private Sub SendToBrowserAsPdf(ByVal doc As Aspose.Word.Document)

'Save the document in Aspose.Pdf.Xml format into a memory stream.
Dim stream As MemoryStream = New MemoryStream
'Dim doc1 As Document = New Document
'doc1 = doc
'doc.Save(stream, Aspose.Word.SaveFormat.FormatAsposePdf)
'Seek to the beginning so it can be read by XmlDocument.
stream.Seek(0, SeekOrigin.Begin)

doc.Save(stream, Aspose.Word.SaveFormat.FormatAsposePdf)

'Load the document into an XmlDocument
Dim xmlDoc As XmlDocument = New XmlDocument

'Load the XML document into Aspose.Pdf
Dim pdf As Aspose.Pdf.Pdf = New Aspose.Pdf.Pdf
'Make sure the images that were saved by Aspose.Word into Windows temporary
'folder are automatically deleted by Aspose.Pdf when they are no longer needed.
pdf.IsImagesInXmlDeleteNeeded = True
pdf.BindXML(xmlDoc, Nothing)
'pdf.Save(“Aspose.Word.Demo.pdf”, Aspose.Pdf.SaveType.OpenInAcrobat, Me.Response)
'Now produce the PDF file.
pdf.Save(“Aspose.Word.Demos.pdf”, Aspose.Pdf.SaveType.OpenInBrowser, Me.Response)
End Sub

The code is ok, the problem is in your template. There is a colored table on page 2 that contains a bulleted list in each cell of the second column. The lists seemed formatted incorrectly so I’ve made nothing but reformatted them a bit. I’ve attached the working document.

Thanks for the help the issue is resolved now. I look forward to using the licensed version. You have provided a level of customer support that i was not expecting. Thank again.

Since you found the formating problem in the first document so readily. i thought that i would see if you can do the same with the attached. While converting to PDF i get an error stating that linked textboxes are not supported. However, i can not find any textbox references in the document.


Thank you for the positive report, we are happy to help you.

Unfortunately, this document needs much more investigation than the previous one. I’ve made some insignificant changes to avoid throwing exceptions (made the logo a solid image and corrected layout of the Contact Information table, see attachment) but the resulting PDF still has many issues in layout and formatting, so we will continue to look into these problems and let you know about the results.

Thanks again for the assistance, i have been given approval to purchase the components. We will work out the formating issues with our internal word processing department. Do you offer an image control ? The previously attached document will need to have some graphics thrown at them. If you do not offer an image control can you give some insight as to how you would substitute images in a mailmerge document.

Can you point me to a document that outlines specific formating items that are not supported.

thanks again


Sure, there are several ways to insert images into a document. First, you can use DocumentBuilder.InsertImage. Second, you can implement MergeImageFieldEventHandler and populate the document with images by executing mail merge. There are also no obstacles to use these approaches together and put DocumentBuilder into the event handler to implement custom image inserting logic. Please see the demo projects to obtain the code samples.

We have a spreadsheet that documents details of various conversions limitations, please refer here to obtain it: