@AsposeCreatio
Issue Summary
You are receiving a System.OutOfMemoryException
when calling
Aspose.Words.Cloud.Sdk.WordsApi.ConvertDocument(ConvertDocumentRequest request)
during a PDF conversion (printable quotes).
The exception is thrown on the client side, which means the SDK tried to load the entire converted document into memory before returning it to your application.
Quick Fixes
# |
Action |
Why it helps |
1 |
Upgrade to the latest Aspose.Words Cloud SDK |
Memory‑handling improvements and bug fixes are included in every release. |
2 |
Use the “out‑path” (cloud storage) overload |
The API writes the converted file directly to Aspose Cloud Storage, so the SDK never holds the whole PDF in memory. |
3 |
Stream the result instead of loading it |
If you must receive the file in memory, use the GetDocumentWithFormat method with Stream (or async) to process the data chunk‑by‑chunk. |
4 |
Reduce the document size before conversion (e.g., remove unused images, large embedded objects, or split the source file into smaller parts). |
|
5 |
Set PDF save options for size optimization (e.g., disable high‑quality rendering, compress images). |
|
6 |
Increase the available memory for your process (run the app on a machine/instance with more RAM) if streaming cannot be used. |
|
Recommended Implementation
Below is a sample workflow that avoids the out‑of‑memory condition by writing the PDF directly to Aspose Cloud Storage and then downloading it (or providing a public link) as needed.
Prepare the request with an OutPath
using Aspose.Words.Cloud.Sdk.Api;
using Aspose.Words.Cloud.Sdk.Model.Requests;
// Initialise the API (replace with your credentials)
var config = new Configuration
{
ClientId = "YOUR_CLIENT_ID",
ClientSecret = "YOUR_CLIENT_SECRET"
};
var wordsApi = new WordsApi(config);
// Input document (can be in local storage or already uploaded to cloud)
string sourceFileName = "Quote.docx";
string storageFolder = "input";
string outFolder = "output";
string outFileName = "Quote.pdf";
// Build the convert request
var convertRequest = new ConvertDocumentRequest
{
Name = sourceFileName,
Format = "pdf",
Folder = storageFolder, // folder where the source lives
OutPath = $"{outFolder}/{outFileName}", // **important** – write result to cloud storage
// Optional: PDF save options for reduced memory usage
SaveOptionsData = new PdfSaveOptions
{
CompressImages = true,
ImageCompression = PdfImageCompression.Jpeg,
JpegQuality = 70,
OptimizeForSize = true,
// Disable high‑quality rendering if not needed
UseHighQualityRendering = false
}
};
// Perform conversion – the SDK only receives a small JSON response
var convertResult = wordsApi.ConvertDocument(convertRequest);
(Optional) Download the generated PDF when needed
var downloadRequest = new DownloadFileRequest
{
Path = $"{outFolder}/{outFileName}",
Storage = null // default storage
};
using (var pdfStream = wordsApi.DownloadFile(downloadRequest))
using (var file = File.Create(@"C:\Temp\Quote.pdf"))
{
pdfStream.CopyTo(file);
}
Result:
- The heavy PDF generation happens entirely on the Aspose Cloud server.
- The SDK only receives a lightweight JSON response, eliminating the
OutOfMemoryException
.
Useful Documentation Links
Next Steps / Follow‑up Questions
To fine‑tune the solution, could you please share:
- Which SDK language are you using (C#, Java, Python, Node.js, etc.)?
- Approximate size of the source
.docx
and the generated PDF.
- Whether the source document is already uploaded to Aspose Cloud Storage or you are sending it as a byte array/stream.
- Any specific PDF rendering requirements (e.g., need for exact visual fidelity, high‑resolution images).
With that information we can suggest more precise settings (e.g., page range conversion, image down‑sampling) if you still prefer to receive the PDF as a stream.
Feel free to try the “out‑path” approach and let us know the outcome. We’ll be happy to help you further!
Best regards,
Aspose Support Team