Uploading PDFs

You can enable uploading of PDFs by setting the 'PermitPdfUploads' parameter to 'true' when configuring your PDF viewer. You can also specify the maximum file size as well as a callback containing the uploaded file.

You should consider the potential security implications of allowing users to upload PDF files to your application

Enable PDF Uploads


<PdfViewer PermitPdfUploads="true"/>

Specify Max Upload Size


builder.Services.AddBlazorPdfViewer(config =>
{
    config.MaxPdfFileUploadSize = 15728640; // 15MB
});

Upload Event Callback


<PdfViewer PermitPdfUploads="true" OnFileUploaded=@FileUploaded/>

@code
{
    [Inject] public ISnackbar Snackbar { get; set; }
    
    private void FileUploaded(PdfViewerFileUploaded data)
    { 
        var fileInfo = $"Uploaded {data.FileName} ({data.Size} bytes)";
        Snackbar.Add(new MarkupString(fileInfo));
    }
}

Callback object


public class PdfViewerFileUploaded
{
  public required string FileName { get; set; }

  public required byte[] Contents { get; set; }

  public required long Size { get; set; }
}

Demo

Upload File

Max file size: 10 MB

An unhandled error has occurred. Reload 🗙