Back to Devexpress

PdfSettingsBuilder.ExportUrl(String) Method

aspnetcore-devexpress-dot-aspnetcore-dot-richedit-dot-pdfsettingsbuilder-dot-exporturl-x28-system-dot-string-x29.md

latest3.7 KB
Original Source

PdfSettingsBuilder.ExportUrl(String) Method

Specifies the path where the exported PDF document is sent for further processing.

Namespace : DevExpress.AspNetCore.RichEdit

Assembly : DevExpress.AspNetCore.RichEdit.v25.2.dll

NuGet Package : DevExpress.AspNetCore.RichEdit

Declaration

csharp
public PdfSettingsBuilder ExportUrl(
    string exportUrl
)

Parameters

NameTypeDescription
exportUrlString

The URL.

|

Returns

TypeDescription
PdfSettingsBuilder

An object that can be used to further configure PDF export settings.

|

Remarks

Set the ExportUrl property to process PDF document export on the server side.

Note

The ExportUrl property is not in effect if the PDF document export is implemented on the client side (the handled property is set to true).

cshtml
@(Html.DevExpress().RichEdit("richEdit")
   .Pdf(p => {
       p.ExportUrl(Url.Action("Export"));
   })
   .Fonts(f =>
   //...
)
csharp
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.

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

For Razor Pages web apps only

To use the ExportUrl method in a Razor Pages web app, it is necessary to add the following adjustments.

Add an anti‑forgery token to internal requests the Rich Text Editor sends to action handlers. This token prevents Cross-Site Request Forgery (CSRF/XSRF) attacks.

razor
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Antiforgery

<script>
    function richEdit_beforeSend(richEdit, e) {
        e.request.setRequestHeader("RequestVerificationToken",
                                "@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken");
    }
</script>

@(Html.DevExpress().RichEdit("richEdit")
    .ExportUrl(Url.Page(pageName: null, pageHandler: "Export"))
    .OnBeforeSend("richEdit_beforeSend")
)

Declare a POST action handler to save a document.

csharp
public void OnPostExport(string base64, string fileName) {
    byte[] fileContents = System.Convert.FromBase64String(base64);
 }

Use this handler in the ExportUrl method as follows.

csharp
.ExportUrl("RichEditPage?handler=export")

See also: Add RichEdit to a .NET Core Application

See Also

Export a Document to PDF

PdfSettingsBuilder Class

PdfSettingsBuilder Members

DevExpress.AspNetCore.RichEdit Namespace