Free Support Forum -

Aspose.Word crashes exe when saving rtf to memory stream works fine

This is my function that converts an RTF document into PDF. The Words.LoadFormat is set to Auto

I am having problems attaching the file, I can email it to you if you tell me at what address. Aspose.Word version works fine.

public static string ConvertToPDF(string fileName, Aspose.Words.LoadFormat fileFormat)

string convertedFile = string.Empty;
// License Aspose
Aspose.Words.License wordLicense = new Aspose.Words.License();

Aspose.Pdf.License pdfLicense = new Aspose.Pdf.License();

// Convert this file into PDF Using Aspose.Word and Aspose.PDF
Aspose.Words.Document wordDoc = new Aspose.Words.Document(fileName, fileFormat, string.Empty);

// If the margins or page size is out of wack, default it
foreach (Aspose.Words.Section currentSection in wordDoc.Sections)
if ((currentSection.PageSetup.TopMargin < 0) ||
(currentSection.PageSetup.BottomMargin < 0) ||
(currentSection.PageSetup.LeftMargin < 0) ||
(currentSection.PageSetup.RightMargin < 0) ||
(currentSection.PageSetup.PageWidth < 0) ||
(currentSection.PageSetup.PageHeight < 0)
// Format as a typical Letter page
currentSection.PageSetup.TopMargin = 18;
currentSection.PageSetup.BottomMargin = 18;
currentSection.PageSetup.LeftMargin = 18;
currentSection.PageSetup.RightMargin = 18;
currentSection.PageSetup.PageHeight = 792;
currentSection.PageSetup.PageWidth = 612;

MemoryStream msWordDoc = new MemoryStream();

// This next line is what crashes the exe
wordDoc.Save(msWordDoc, Aspose.Words.SaveFormat.AsposePdf);

Aspose.Pdf.Pdf pdfDoc = new Aspose.Pdf.Pdf();
pdfDoc.BindXML(msWordDoc, null);
pdfDoc.IsTruetypeFontMapCached = true;
if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "PDFFonts") == false)
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "PDFFonts");
pdfDoc.TruetypeFontMapPath = AppDomain.CurrentDomain.BaseDirectory + "PDFFonts";
convertedFile = fileName.Replace(Path.GetExtension(fileName), ".PDF");
System.IO.FileStream fs = new System.IO.FileStream(convertedFile, System.IO.FileMode.Create);

return convertedFile;



Thanks for your inquiry. Please attach your document. I will try to reproduce this problem and provide you more information.

Best regards.


Thank you for reporting to us. I managed to reproduce the problem. I created an issue # 3994 in our defects database and we will investigate whether and when it can be fixed. Please expect a reply before the next hotfix (within 2-3 weeks).

Best regards.


I have the same problem in trying to save a document by calling:

.Save(sWordDocumentFullName, Aspose.Words.SaveFormat.Doc)

Error Source: Aspose.Words
Error message: Object reference not set to an instance of an object.

at ?.?.?(String ?, BinaryWriter ?, Byte ?) at ?.?.?(BinaryWriter ?) at ?.?.?(BinaryWriter ?) at ?.?.?(? ?, BinaryWriter ?) at ?.?.?() at ?.?.?() at ?.?.?(? ?) at Aspose.Words.Document.Save(String fileName, SaveFormat fileFormat) at NeptuneProcess.Start.ProcessJob(Int64 lJobID)

It works in, and so I have had to roll back...




Thank you for additional information. This will help us to solve this problem.

Best regards.

Fixed, will release soon.

We have released a new version of Aspose.Words that contains a fix for your issue.

The new version of Aspose.Words is available for download from here.

Best regards.