System.OutOfMemoryException: Save *.docx as *.pdf (*.docx is 15.833KB)33kb/263134

I have a Problem with Save *.docx as *.pdf, *docx is 15833KB lage.

@VladimirR Could you please attach your problematic document here for testing? We will check the issue and provide you more information.

Hi Alexey,

thank you for your quick response.

V.

tmpA791.docx (15.5 MB)

@VladimirR I am afraid your document is simply to large. Even MS Word on my side hangs for few minutes and then crashes while converting your document to PDF. If unzip your DOCX document, only document.xml size is abnormally big - 750+MB.
For reducing memory usage upon processing extremally large documents, you can try using LoadOptions.TempFolder, SaveOptions.TempFolder and SaveOptions.MemoryOptimization properties.
Using the following code I managed to convert your document to PDF:

LoadOptions opt = new LoadOptions();
opt.TempFolder = @"C:\Temp\tmp\";
Document doc = new Document(@"C:\Temp\in.docx", opt);

PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.TempFolder = opt.TempFolder;
pdfSaveOptions.MemoryOptimization = true;
doc.Save(@"C:\Temp\out.pdf", pdfSaveOptions);

The conversion took about 662 seconds. The output PDF size is 12MB and it has 4032 pages.

Hi Alexey,

thank you for your fast response!

Sadly, still it doesn’t work.

I used your solution in the following code for the NUnit-test:

[Test]
public void DocxToPdf()
{
    Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
    //Load the encrypted license and decrypt it using the key.
    byte[] decryptedLicense;
    decryptedLicense = EncryptDecryptLicense(File.ReadAllBytes(@"asposewordslic.enc"), keywords);
    var temppath = System.IO.Path.GetTempPath();
    // Load the decrypted license into a stream and set the license.
    MemoryStream licenseStream = new MemoryStream(decryptedLicense);
    Aspose.Words.License license = new Aspose.Words.License();
    license.SetLicense(licenseStream);
    Aspose.Words.Loading.LoadOptions opt = new Aspose.Words.Loading.LoadOptions();
    opt.TempFolder = @"C:\Temp\tmp\";
    Aspose.Words.Document doc = new Aspose.Words.Document(@"C:\Temp\in.docx", opt);
    Aspose.Words.Saving.PdfSaveOptions pdfSaveOptions = new Aspose.Words.Saving.PdfSaveOptions();
    pdfSaveOptions.TempFolder = opt.TempFolder;
    pdfSaveOptions.MemoryOptimization = true;
    doc.Save(@"C:\Temp\out.pdf", pdfSaveOptions);
}

@VladimirR As I mentioned, your document is simply to large. It is not recommended to use such abnormally huge documents, because even MS Word cannot handle them normally.
Unfortunately, except the recommended options there are no other ways to reduce memory consumption upon processing documents.