Serverside PDF

MDriven reports are created with open document text (odt) or open document spreadsheet formats (ods).

If you need to convert the odt to PDF, there are online services available. If you would rather do this yourself, buy a third-party library that has this ability - for example, Aspose.Words as used in this example.

Please note that this solution works well inside IIS, but it's not free. If you can access Word locally, like the WPF client, you can use Word instead of paying for a .net component. You can find an example of how to use Word with automation here.

Yet another new approach is to use LibreOffice - read more here


This example uses a transient class PDF converter to make PDF conversion easy to access from anywhere in the model.

PDF converter class.png

This is the C# code for the two functions:

public void ConvertToPDF()
      Aspose.Words.License license = new Aspose.Words.License();
      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();

CheckCodeDressingActive is a way of ensuring that the PDF component has been properly loaded - in this case, with CodeDress.

public bool CheckCodeDressingActive()
  return true;

Note: Include the Aspose license file as an Embedded resource in the VS project to avoid the error message "the invoked member is not supported in a dynamic assembly."

This page was edited 5 days ago on 06/17/2024. What links here