In this step you'll add a code file that will contain the Save method, as well as code that defines both the Offset and the Inflate methods referenced in creating the PDF document's text.
C# Copy Code using C1.Xaml.Pdf; using System; using System.Collections.Generic; using Windows.Storage; using Windows.Storage.Pickers; using Windows.UI.Popups; using System.IO; using Windows.Foundation; namespace Pdf_UWP_QS { public static class PdfUtils { public static async void Save(this C1PdfDocument pdf) { FileSavePicker picker = new FileSavePicker(); picker.FileTypeChoices.Add("PDF", new List<string>() { ".pdf" }); picker.DefaultFileExtension = ".pdf"; picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; StorageFile file = await picker.PickSaveFileAsync(); if (file != null) { await pdf.SaveAsync(file); MessageDialog dlg = new MessageDialog("Pdf Document saved to " + file.Path, "PdfSamples"); await dlg.ShowAsync(); } } public static MemoryStream SaveToStream(this C1PdfDocument pdf) { MemoryStream ms = new MemoryStream(); pdf.Save(ms); ms.Seek(0, SeekOrigin.Begin); return ms; } // *********************************************************************** // Extension methods for Rect // *********************************************************************** public static Rect Inflate(this Rect rc, double dx, double dy) { rc.X -= dx; rc.Y -= dy; rc.Width += 2 * dx; rc.Height += 2 * dy; return rc; } public static Rect Offset(this Rect rc, double dx, double dy) { rc.X += dx; rc.Y += dy; return rc; } } }
In this step, you added a code file and the code for the extension methods. In the next step, you'll run your application.