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 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?

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,