You can convert an MDriven report document from ODT to PDF on the server by calling a .NET PDF library from a transient converter class; this page is for developers deploying conversion in IIS, Turnkey, or MDrivenServer.
Choose a server-side conversion approach
MDriven reports are created as OpenDocument Text (ODT) or OpenDocument Spreadsheet (ODS) documents. Server-side conversion is needed when the generated document must become a PDF without relying on software installed on a user's workstation.
| Approach | Use it when | Important limitation |
|---|---|---|
| Third-party .NET library, such as Aspose.Words | You need conversion to run in IIS, Turnkey, or MDrivenServer and can deploy the library and its license. | The library is a third-party, licensed component. |
| LibreOffice | LibreOffice is installed on the server and you want to use the SysDocBatch conversion workflow. | LibreOffice is a separate product and must be installed and configured on the server. |
| Microsoft Word automation | Conversion runs in a client that has local access to Word, for example a WPF client. | Do not use this approach for IIS server-side conversion; Word components do not work well when called from IIS. |
For the general PDF-conversion options and a Word automation example, see Documentation:PDF. For ODT/ODS conversion through LibreOffice, use Documentation:SysDocBatch and Use LibreOffice for PDF Conversion.
Implement conversion with a .NET component
The example below uses Aspose.Words in a transient class named PDF converter. A transient class is suitable here because the converter holds document bytes while it performs an operation; it can be called from elsewhere in the model without making the converter itself persistent.
The converter needs two binary attributes:
| Attribute | Purpose |
|---|---|
Document
|
Source ODT document as a byte array. |
PDF
|
Generated PDF as a byte array. |
Prepare the deployment
- Add the third-party .NET component used by the code to the Visual Studio project that is deployed with your application.
- Make the component available to the server application, including IIS, Turnkey, or MDrivenServer as applicable.
- Obtain and deploy the component license according to the supplier's licensing requirements.
- Add the C# methods through CodeDress so that the model can call them.
The example sets an Aspose license named Aspose.Words.lic. Include that license file as an embedded resource in the Visual Studio project. This avoids the error: the invoked member is not supported in a dynamic assembly.
Add the conversion method
Set Document to the bytes of the ODT report before calling ConvertToPDF. The method loads those bytes, saves the document to a memory stream as PDF/A-1b, and assigns the resulting bytes to PDF.
public void ConvertToPDF()
{
Aspose.Words.License license = new Aspose.Words.License();
license.SetLicense("Aspose.Words.lic");
MemoryStream srcStream = new MemoryStream(this.Document);
Document srcDoc = new Document(srcStream);
MemoryStream dstStream = new MemoryStream();
Aspose.Words.Saving.PdfSaveOptions options =
new Aspose.Words.Saving.PdfSaveOptions();
options.Compliance = Aspose.Words.Saving.PdfCompliance.PdfA1b;
options.MemoryOptimization = true;
options.OptimizeOutput = true;
srcDoc.Save(dstStream, options);
this.PDF = dstStream.ToArray();
}
Example flow:
- Generate an ODT report and assign its byte content to
PDF converter.Document. - Call
PDF converter.ConvertToPDF(). - Read
PDF converter.PDFand use those bytes where the calling ViewModel or server-side process needs the PDF, such as an attachment or download.
The code keeps both the source and result in memory. Ensure that the documents handled by the process fit the memory available to the server.
Verify that CodeDress is active
Add the following method to verify that the PDF component's CodeDress code has loaded:
public bool CheckCodeDressingActive()
{
return true;
}
Call CheckCodeDressingActive as a deployment check. A successful true result confirms that this CodeDress method is available; it does not itself convert a document or validate the third-party license.
Run conversion from server-side work
If conversion must run without a logged-in client, invoke the converter from a server-side ViewModel or job. Server-side actions delegate work to MDrivenServer, while server-side jobs can execute actions periodically or in response to work such as a SysAsync Ticket.
When access groups restrict the ViewModel that performs conversion, make sure the server-side execution is allowed to access it. Server-side ViewModels execute without a logged-in user; see the access-group guidance in Documentation:Serverside actions.
For a separate PDF-conversion service that reports completion back to another MDrivenServer, see Documentation:Communication between MDrivenServers.
