View the created PDF document

2 Nov 20212 minutes to read

The Syncfusion’s Blazor PDF Viewer component allows you to view the created PDF document using the Created event.

The following code example shows how to view the created PDF document.

<SfPdfViewerServer ID="pdfviewer" @ref="@PdfViewer" DocumentPath="@documentPath">
    <PdfViewerEvents Created="created"></PdfViewerEvents>
</SfPdfViewerServer>

@code{

    public SfPdfViewerServer PdfViewer { get; set; }
    public string documentPath { get; set; }
    private void created()
    {
        var document = new PdfDocument();
        byte[] bytes;
        //Add a new page to the PDF document.
        PdfPage page = document.Pages.Add();
        //Create a textbox field and add the properties.
        PdfTextBoxField textBoxField = new PdfTextBoxField(page, "FirstName");
        textBoxField.Bounds = new RectangleF(0, 0, 100, 20);
        textBoxField.ToolTip = "First Name";
        //Add the form field to the document.
        document.Form.Fields.Add(textBoxField);
        //stream.Position = 0;

        var stream = new MemoryStream();

        //Save the document.
        document.Save(stream);
        bytes = stream.ToArray();
        string base64string = Convert.ToBase64String(bytes);
        documentPath = "data:application/pdf;base64," + base64string;
        //close the document
        document.Close(true);
    }
}

Find the sample How to view the created PDF document