View the created PDF document
7 Oct 20242 minutes to read
The Syncfusion’s Blazor SfPdfViewer 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.
<SfPdfViewer2 ID="pdfviewer"
@ref="@PdfViewer"
DocumentPath="@documentPath"
Height="100%"
Width="100%">
<PdfViewerEvents Created="created"></PdfViewerEvents>
</SfPdfViewer2>
@code{
public SfPdfViewer2 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);
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);
}
}