-
Notifications
You must be signed in to change notification settings - Fork 20
MuPDFCore.MuPDFRenderer Avalonia control
Giorgio Bianchini edited this page Jul 26, 2022
·
1 revision
The PDFRenderer
control contained in the MuPDFCore.MuPDFRenderer NuGet package can be used to display a document in a cross-platform Avalonia application.
To use the PDFRenderer
control in an Avalonia application, first of all you need to add it to you Avalonia Window
, e.g. in the XAML:
<Window xmlns="https://github.com/avaloniaui"
...
xmlns:mupdf="clr-namespace:MuPDFCore.MuPDFRenderer;assembly=MuPDFCore.MuPDFRenderer"
Opened="WindowOpened"
... >
<mupdf:PDFRenderer Name="MuPDFRenderer" />
</Window>
You then need to initialise it from the backing code, e.g. in a WindowOpened
event:
private void WindowOpened(object sender, EventArgs e)
{
this.FindControl<PDFRenderer>("MuPDFRenderer").Initialize("path/to/file.pdf");
}
This way, the renderer will start showing the first page of the specified document, using a number of rendering threads that is decided based on the number of processors in the computer. There are many other ways to initialise a PDFRenderer, so make sure to look at the documentation to see the other possibilities!