Skip to main content

Export to PDF

  • 2 minutes to read

Rich Text Editor allows you to export a document as a PDF file on the client and server sides.

Client Export

Important

When you export to PDF on the client, you should upload a list of available fonts and their sources to the client and register the pdfkit library on your page.

The exportToPdf method exports the current document as a PDF file and invokes the PdfExporting event for further processing on the client. Use the base64, blob, or blobStream event parameter to access the processed PDF document. You can set the handled property to true to prevent further processing on the server.

@(Html.DevExpress().RichEdit("richEdit")
  .OnPdfExporting(
    @"function(s, e) {
    e.handled = true;
    console.log(e.base64);
    }")

If the handled property is set to false or undefined, specify the ExportUrl(String) property to process the document on the server.

@(Html.DevExpress().RichEdit("richEdit")
  .Pdf(p => {
      p.ExportUrl(Url.Action("Export"));
  })
  .Fonts(f =>
  //...
)
public IActionResult Export(string base64, string fileName) {
    byte[] fileContents = System.Convert.FromBase64String(base64);
    return Ok();
}

Note

If you apply the [ApiController] attribute to your controller, you should add the [FromForm] attribute to parameters in the Export action.

public IActionResult Export([FromForm]string base64, [FromForm]string fileName) {
  byte[] fileContents = System.Convert.FromBase64String(base64);
  return Ok();
}

If document processing is implemented on the server, you can write the PdfExported event handler to perform custom actions after a server sends a response to a request for document processing.

Learn how to use the ExportUrl method in a Razor Pages web app in the following topic: ExportUrl.

Tip

Use the downloadPdf(fileName) method to download the current document as a PDF file.

Server Export

Rich Text Editor allows you implement export to PDF on the server. For this purpose, export the current document in RTF or DOCX format to the server and use the DevExpress Word Processing Document API to export the resulting file content to PDF format.