We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.Word 4.4.1.0 crashes exe when saving rtf to memory stream 4.4.0.0 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 4.4.0.0 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();
    wordLicense.SetLicense("Aspose.Custom.lic");
    Aspose.Pdf.License pdfLicense = new Aspose.Pdf.License();
    pdfLicense.SetLicense("Aspose.Custom.lic");
    // 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);
    pdfDoc.Save(fs);
    fs.Close();
    fs.Dispose();
    msWordDoc.Close();
    msWordDoc.Dispose();
    return convertedFile;
}

Hi

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

Best regards.

Hi,
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.

Hi,
I have the same problem in 4.4.1.0 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.

Details:

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 4.4.0.0, and so I have had to roll back…
Cheers,
Steve

Hi
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.