CA.Blazor.Pdf 1.1.0

dotnet add package CA.Blazor.Pdf --version 1.1.0
NuGet\Install-Package CA.Blazor.Pdf -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CA.Blazor.Pdf" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CA.Blazor.Pdf --version 1.1.0
#r "nuget: CA.Blazor.Pdf, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CA.Blazor.Pdf as a Cake Addin
#addin nuget:?package=CA.Blazor.Pdf&version=1.1.0

// Install CA.Blazor.Pdf as a Cake Tool
#tool nuget:?package=CA.Blazor.Pdf&version=1.1.0

Blazor PDFViewer

CA.Blazor.Pdf is a library that allows to show pdf in your blazor website

This examples uses 1.1.0 or higher version of this library

For previous versions examples check this readme

New Updates

Recently I published a new version of this library, now it allows to pick larger files, and a sort of pagination is present.

The PdfViewer has not more Height property, because the base structure of component has changed

Usage

In your Program.cs you have to import the extension class, and add CA.Blazor services:

using CA.Blazor.Pdf.Extensions; // add this line
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddCaBlazorPdf(); // add this line

await builder.Build().RunAsync();

Now you can use CA.Blazor.PdfViewer in your project

First of all you have to insert library using:

@using CA.Blazor.Pdf
@using CA.Blazor.Pdf.Extensions

The second using is for a extensions class that allows the client to use methods like: ToMemoryStreamAsync() and ToBase64String().

<InputFile OnChange="OnInputFileChange" />

<PdfViewer Base64Data="@Base64" Width="50%"/>

@code {
    public string Base64 { get; set; }
    IBrowserFile selectedFiles;

    private async void OnInputFileChange(InputFileChangeEventArgs e)
    {
        selectedFiles = e.File;
        using var memory = await selectedFiles.OpenReadStream(2000000000).ToMemoryStreamAsync();
        Base64 = memory.ToBase64String();
        this.StateHasChanged();
    }


}

To get base64 encoded string you have to use a MemoryStream and use the extension method ToBase64String().

You have to pass a buffer size to OpenReadStream(), which default use 512 KB, otherwise you'll be not allowed to pick larger files.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 470 3/18/2023
1.0.3 244 3/10/2023
1.0.2 234 3/9/2023
1.0.1 221 3/8/2023
1.0.0 218 3/8/2023

Added pagination to pdf, can also handle larger file.