Skip to main content
A newer version of this page is available. .

Export to PDF

  • 2 minutes to read

The exportToPdf method exports the current document to the portable document format (PDF) and invokes the PdfExporting event for further processing on the client side. 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.

Important

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

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