Conversion
Show Office files, HTML, e-books and photos in a .NET MAUI PdfView, and export the open document to Word, Excel, PowerPoint and HTML.
License module
Conversion to and from Office, HTML, e-book and data formats needs the conversion module (Startup
tier and above). Images to PDF and Markdown export need no module.
Show other formats
PdfView.LoadAsync opens what NexPdfDocument.OpenBytes opens: PDF, JPEG, PNG and TIFF pictures,
and, converted with the conversion module, Word, Excel and PowerPoint files, EPUB and zipped
FictionBook books, XPS files and CBZ comics (e-books and comics since 1.0.1):
var file = await FilePicker.Default.PickAsync();
if (file is not null)
{
await using var s = await file.OpenReadAsync();
using var ms = new MemoryStream();
await s.CopyToAsync(ms);
await view.LoadAsync(ms.ToArray());
}For HTML, convert first and load the PDF bytes. OpenEbook does the same for e-books explicitly:
using Nexdevit.NexPdf;
using (var pdf = NexPdfDocument.FromHtml("<h1>Invoice 1042</h1><p>Total: 120 EUR</p>"))
await view.LoadAsync(pdf.SaveBytes());
using (var book = NexPdfDocument.OpenEbook(epubBytes)) // EPUB, FictionBook, XPS/OpenXPS, CBZ
await view.LoadAsync(book.SaveBytes());Word and Excel options
NexPdfSdk.OpenDocxWithOptionsJson(data, optionsJson) converts a Word document with
show_comments (comments in balloons in a markup area at the right of each page) and
show_revisions (tracked changes as coloured insertions, struck deletions and change bars instead
of the final document); both default to false. Comments are always exported as PDF text
annotations anchored at the commented text.
var pdf = await Task.Run(() =>
{
using var doc = NexPdfSdk.OpenDocxWithOptionsJson(docxBytes, """{"show_comments":true}""");
return doc.SaveBytes();
});
await view.LoadAsync(pdf);Excel formulas without a cached value are calculated (about 280 functions, dynamic arrays,
LAMBDA, circular references as the workbook's settings say), and
NexPdfSdk.OpenXlsxWithClock(data, clockUnixSeconds) makes NOW() and TODAY() return a fixed
time. Word, Excel, PowerPoint and HTML conversion shapes text with OpenType and orders it with the
full Unicode bidi algorithm, so Arabic, Hebrew and Indic documents convert correctly. Details are
in the .NET conversion guide.
Export the open document
var doc = view.Document!;
var docx = await Task.Run(() => doc.ToDocx());
var path = Path.Combine(FileSystem.CacheDirectory, "document.docx");
await File.WriteAllBytesAsync(path, docx);
await Share.Default.RequestAsync(new ShareFileRequest("Word document", new ShareFile(path)));ToXlsx(), ToPptx(), ToHtml(), ToReflowHtml(options), ToJson(), ToXml(), ToCsv(),
ToRtf() and ToMarkdown() work the same way. ToReflowHtml is handy for a reading mode in a
WebView on small screens. See the .NET conversion guide.