I’ve created a document using Document Builder and converted it into pdf format.
When i try to open this pdf file in browser, I get the error “An exception of type ‘System.Xml.XmlException’ occurred in System.Xml.dll but was not handled in user code Additional information: Data at the root level is invalid. Line 1, position 1.”
Here is the code:
MemoryStream stream=new MemoryStream(); Word.Saving.PdfSaveOptions options=new Word.Saving.PdfSaveOptions(); options.OutlineOptions.HeadingsOutlineLevels=2; doc.Save(stream,options); //stream.Seek(0, SeekOrigin.Begin); //Load the document into an XmlDocument XmlDocument xmlDoc=new XmlDocument(); xmlDoc.Load(stream); //--- The error rises here --- //Load the XML document into Aspose.Pdf Aspose.Pdf.Generator.Pdf pdf=new Aspose.Pdf.Generator.Pdf(); pdf.IsBookmarked=true; //Make sure the images that were saved by Aspose.Words into Windows temporary folder are automatically deleted by Aspose.Pdf when they are no longer needed. pdf.IsImagesInXmlDeleteNeeded=true; pdf.BindXML(xmlDoc,null); //Aspose.Pdf font cache, see comments below. pdf.IsTruetypeFontMapCached = false; HttpResponse Response=null; pdf.Save("Report.pdf",Aspose.Pdf.Generator.SaveType.OpenInAcrobat,Response);