Free Support Forum - aspose.com

Invalid SaveFormat Error doing basic Doc -> PDF conversion

I’m evaluating Aspos Words to do document conversion from Word to PDF.


My code is very simple, but every document I get an error, System.ArgumentException: An invalid SaveFormat for this options type was chosen.


public virtual byte[] Convert(byte[] document)
{
using (Stream stream = new MemoryStream(document))
{
byte[] pdfDocument;
Aspose.Words.Document aposeDocument = new Aspose.Words.Document(stream);
// For Debugging
foreach (DocumentProperty prop in aposeDocument.BuiltInDocumentProperties)
{
_logger.DebugFormat("{0} - {1}", prop.Name, prop.Value);
}
DocSaveOptions _options = new DocSaveOptions();
_options.SaveFormat = SaveFormat.Pdf;
using (Stream outputStream = new MemoryStream())
{

aposeDocument.Save(outputStream, _options);//SaveFormat.Pdf);
outputStream.Position = 0;
int streamLength = (int) outputStream.Length;
pdfDocument = new byte[streamLength];
int bytesRead = outputStream.Read(pdfDocument, 0, streamLength);
return pdfDocument;
}
}
}

I’ve read the document section (http://www.aspose.com/docs/display/wordsnet/Converting+a+Document#ConvertingaDocument-ConvertMicrosoftWorddocumenttoPDF), but it only covers saving to disk, rather than converting in memory.

The error seems strange - why is the save format invalid? What am I doing wrong?

Hi,


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document
  • Please create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,