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 asposeDocument= new Aspose.Words.Document(stream);
// For Debugging
foreach (DocumentProperty prop in asposeDocument.BuiltInDocumentProperties)
{
_logger.DebugFormat("{0} - {1}", prop.Name, prop.Value);
}
DocSaveOptions _options = new DocSaveOptions();
_options.SaveFormat = SaveFormat.Pdf;
using (Stream outputStream = new MemoryStream())
{
asposeDocument.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 (https://docs.aspose.com/words/net/convert-a-document-to-pdf/), 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?