OutMemoryException on Document.Save with FormatPDF parameter

Hi,
I have to convert a Word document, that is about 46mb, into PDF one. When I call the Word document Save(…) method with PdfFormat parameter, i get an OutMemoryException.
I tried to use a memory stream and a temp file, but i get the same exception in both cases.
I also tried to force garbage collection just before calling the methode but nothing change.
Another problem is that memory ressources are not released after garbage collections and memory ressources are retained until i recycle IIS process. I haven’t found Dispose methode on Aspose objects.
I use the latest version of Aspose Word and PDF, on a release version of the application with debug option disabled.
Is there a way to solve the problem ?
Regards,
Bertrand

Hi
Thanks for your inquiry. Usually Aspose.Words needs about 10 times more memory for building the model than the source document size. But this is dependent on your document. I think that as a workaround you can split your document and use several smaller documents instead one big document.
Also maybe there is some problem with your document. Could you share your document somewhere that we will be able to download it and do some testing? (You can use rapidshare or try to send your document to my e-mail noskov.aleksey@gmail.com )
Best regards.

Hi Aleksey,
The document have been sent to your mail.

Hi
Thank you for additional information. I tested your document on my side. “OutMemoryException” exception occurs during building PDF using Aspose.Pdf.

Document doc = new Document("200807_PLAT.doc");
doc.Save("out.xml", SaveFormat.AsposePdf);
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.BindXML("out.xml", null); //Error occurs here
pdf.IsImagesInXmlDeleteNeeded = true;
pdf.Save("out.pdf");

I think that you should split your document and use several small documents instead one big document.
Best regards.

Hi, Alexey,
Thank you for your answer.
Actualy, the exception is thrown on the BindXML method.
Is my Word document not well formated ? I can make multiple PDF documents during a step of the process but at the end I have to produce only one PDF in order to send it to the print shop by FTP. After generating the PDF from the Word document, some changes are made specificaly for printing.
I have tried to concat PDF sections of all documents but the same exception occurs.
I there a way to bypass this problem ?
Regards,
Bertrand

Hi
Your document is well formatted but it is very big. So I think that you should split you document. Here is code example how you can do that.

Document doc = new Document(@"Test255\200807_PLAT.doc");
// Calculate count of sub documents
// Sub document will have 100 sections (you can generate the smallest documents)
int iterations = 0;
if (doc.Sections.Count % 100 > 0)
    iterations = (int)(doc.Sections.Count / 100) + 1;
else
    iterations = (int)(doc.Sections.Count / 100);
// Generate sub documents
for (int i = 0; i < iterations; i++)
{
    Document interDoc = new Document();
    interDoc.RemoveAllChildren();
    // import sections into the sub document
    for (int sectIndex = i * 100; sectIndex < (i + 1) * 100; sectIndex++)
    {
        if (sectIndex < doc.Sections.Count)
        {
            Node dstSection = interDoc.ImportNode(doc.Sections[sectIndex], true, ImportFormatMode.KeepSourceFormatting);
            interDoc.AppendChild(dstSection);
        }
        else
        {
            break;
        }
    }
    // Generate PDF
    interDoc.Save(@"Test255\out.xml", SaveFormat.AsposePdf);
    Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
    pdf.BindXML(@"Test255\out.xml", null); //Error occurs here
    pdf.IsImagesInXmlDeleteNeeded = true;
    pdf.Save(@"Test255\out" + i.ToString() + ".pdf");
}

After generating multiple PDF documents you can merge these documents together using Aspose.Pdf.Kit.Here is code example how you can achieve this

string[] pdfNames = Directory.GetFiles(@"Test255", "*.pdf");
Stream[] inStreams = new Stream[pdfNames.Length];
// Create input stream objects holding the PDF files to be concatenated
// Store all input streams in an Array
for (int i = 0; i < inStreams.Length; i++)
{
    inStreams[i] = new FileStream(pdfNames[i], FileMode.Open);
}
// Create output stream object that would contain the final PDF file
FileStream outStream = new FileStream(@"Test255\multiStream.pdf", FileMode.Create);
// Instantiate PdfFileEditor object
Aspose.Pdf.Kit.PdfFileEditor pdfEditor = new Aspose.Pdf.Kit.PdfFileEditor();
// Call Concatenate method of PdfFileEditor object to concatenate all input streams
// into a single output stream
pdfEditor.Concatenate(inStreams, outStream);
// Finally close the output stream
outStream.Close();

Hope this helps.
Best regards.

Hey, Alexey,
I tried your code, with an evaluation copy of Aspose.Pdf.Kit. I still have the same problem :

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at Aspose.Pdf.Kit.PdfFileEditor.Append(Stream inputStream, Stream portStream, Int32 startPage, Int32 endPage, Stream outputStream)

I split source documents into 2 pages that I concatene. But it seems to be the capacity of the output stream that throw the exception.
Regards
Bertrand

Hi
I have no ideas how you can workaround this. Try using exactly the same code I provided. This code works fine on my side.
Best regards.