Invalid File Format Requested


#1

We just moved our staging environment from one server to another.

Now we are getting a difficult error to troubleshoot.

The error is … Invalid File Format Requested.

Here is the code, line highlighted in red is thowing the error. Please help.

using System;
using System.IO;
using Aspose.Word;
using System.Xml;
namespace IPT.BusinessObjects.CustomModules
{
///


/// Summary description for AsposeDoc.
/// This class uses third party tool Aspose to convert word document to pdf document,
/// get text content from word document and populate Merge fields.
/// For more information, visit www.aspose.com.
///

public class AsposeDoc
{
private Aspose.Word.Document _doc;
public AsposeDoc(string wordFile)
{
Word word = new Word();
_doc = word.Open(wordFile);
}
public AsposeDoc(System.IO.Stream wordStream)
{
Word word = new Word();
doc = word.Open(wordStream);

}
public string Text()
{
return _doc.Range.Text;
}
public byte[] ToPDF()
{
string ExecutionStep = “”;
try
{
ExecutionStep = “New memorystream”;
MemoryStream xmlPdfStream = new MemoryStream();
ExecutionStep = “Save _doc”;
_doc.Save(xmlPdfStream, SaveFormat.FormatAsposePdf);
ExecutionStep = “Seek Stream”;
xmlPdfStream.Seek(0, SeekOrigin.Begin);
StreamReader pdfReader = new StreamReader(xmlPdfStream);
ExecutionStep = “Read PDF to stream”;
String xml = pdfReader.ReadToEnd();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
// Convert the XML document to pdf by using Aspose.PDF
// Read the document in Aspose.Pdf.Xml format into Aspose.Pdf.
ExecutionStep = " Read the document in Aspose.Pdf.Xml format into Aspose.Pdf." ;
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
ExecutionStep = “BindXml”;
pdf.BindXML(xmlDoc, null);
// Instruct to delete temporary image files.
ExecutionStep = “Instruct to delete temporary image files.” ;
pdf.IsImagesInXmlDeleteNeeded = true;
// Produce the PDF file.
MemoryStream pdfStream = new MemoryStream();
ExecutionStep = “Aspose PDF Save”;
pdf.Save(pdfStream);
pdfStream.Seek(0, SeekOrigin.Begin);
ExecutionStep = “Create and return FileObject”;
byte[] FileObject = new byte[pdfStream.Length];
pdfStream.Read(FileObject, 0, (int) pdfStream.Length);
return FileObject;
}
catch( Exception ex)
{
throw new Exception(ex.Message + ", " + ExecutionStep);
}
}
public void PopulateMergeFields(string[] mergeFields, object[] values )
{
_doc.MailMerge.Execute(mergeFields, values);
}
public void InsertImage(System.Drawing.Image image, string mergeField)
{
DocumentBuilder builder = new DocumentBuilder(_doc);
builder.MoveToMergeField(mergeField);
builder.InsertImage(image);
}

public static void SetWordLlicense( string licenseFile, System.Web.UI.Page page )
{
Word.SetLicense( licenseFile, page );
}
public static void SetPDFLlicense( string licenseFile, System.Web.UI.Page page )
{
Aspose.Pdf.Pdf.SetLicense( licenseFile, page );
}
}
}


#2

Hi, I’v replied to this in Aspose.Pdf forum.