We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Data at the root level is invalid. Line 1- position 1. Error following upgrade

When trying to convert Word documents to pdf we are receiving a “Data at the root level is invalid. Line 1, position 1.” error. This started when we upgraded from version 4.1 to version 4.6 of Aspose.Pdf.

We have tried 2 versions of the code with no success:

Version 1:
try
{
// load doc in stream
Aspose.Words.Document doc = new Aspose.Words.Document(content);

Aspose.Words.Saving.PdfSaveOptions saveOptions = new Aspose.Words.Saving.PdfSaveOptions();
saveOptions.SaveFormat = Aspose.Words.SaveFormat.Pdf;
saveOptions.JpegQuality = 100;

MemoryStream stream = new MemoryStream();
doc.Save(stream, saveOptions);

stream.Seek(0, SeekOrigin.Begin);

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.Load(stream);

// open stream to pdf
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();

pdf.BindXML(xmlDoc, null);

//clean images from temp directory
pdf.IsImagesInXmlDeleteNeeded = true;

// save pdf to stream
stream = new MemoryStream();
pdf.Save(stream);

return stream;
}
catch(Exception e)
{
string d = e.Message;
throw;
}

Version 2
try
{
// load doc in stream
Aspose.Words.Document doc = new Aspose.Words.Document(content);

Aspose.Words.Saving.PdfSaveOptions saveOptions = new Aspose.Words.Saving.PdfSaveOptions();
saveOptions.SaveFormat = Aspose.Words.SaveFormat.Pdf;
saveOptions.JpegQuality = 100;

MemoryStream stream = new MemoryStream();
doc.Save(stream, saveOptions);

// open stream to pdf
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();

pdf.BindXML(stream, null);

//clean images from temp directory
pdf.IsImagesInXmlDeleteNeeded = true;

// save pdf to stream
stream = new MemoryStream();
pdf.Save(stream);

return stream;
}
catch(Exception e)
{
string d = e.Message;
throw;
}


This occurs with both large, complex Word documents as well as very small, simple test documents. We have no idea how to correct this problem. Could it be something else like a corrupt license file?

Thanks in advance

Hi

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

Thanks for your inquiry. AsposePdf was an intermediate format using for converting Word documents to PDF using old legacy method. This method required both Aspose.Words and Aspose.Pdf for converting documents to PDF. Currently this old method of PDF conversion is excluded from Aspose.Words. You should use direct-to-PDF method. Please see the following link for more information:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-convert-a-document-to-pdf.html

Best regards,