Editing pages and documents
Rotate, delete, reorder, merge and change pages of the document shown in a .NET MAUI PdfView, then reload and save it.
License module
Page and content editing needs the editor module (Startup tier and above). Inserting pictures as
pages needs no module.
Edit through view.Document, then call ReloadAsync(): it re-reads the page count and sizes and
re-renders.
var doc = view.Document!;
var page = view.CurrentPage;
doc.RotatePage(page, 90);
await view.ReloadAsync();
doc.DeletePage(page);
await view.ReloadAsync();PdfView renders on a background thread and does not lock Document. For a series of edits, use
your own document and load the result:
using Nexdevit.NexPdf;
using var doc = NexPdfDocument.OpenBytes(pdfBytes);
doc.MovePage(3, 0);
doc.DuplicatePage(0);
using (var appendix = NexPdfDocument.OpenBytes(appendixBytes))
doc.AppendDocument(appendix);
await view.LoadAsync(doc.SaveBytes());Add photos as pages
var photo = await MediaPicker.Default.CapturePhotoAsync();
if (photo is not null)
{
await using var s = await photo.OpenReadAsync();
using var ms = new MemoryStream();
await s.CopyToAsync(ms);
view.Document!.InsertImagePages(view.PageCount, ms.ToArray());
await view.ReloadAsync();
}Save and share
var path = Path.Combine(FileSystem.CacheDirectory, "edited.pdf");
view.Document!.Save(path);
await Share.Default.RequestAsync(new ShareFileRequest("Edited PDF", new ShareFile(path)));Page text and image editing and page backgrounds work as in the
.NET editing guide, through view.Document.
Related
- Document structure: metadata, bookmarks, page labels and attachments
- Compare and optimise: compare versions and make files smaller