PDF for WinRT > Getting Started with WinRT Edition > PDF for WinRT Quick Start > Step 3 of 4: Adding a Code File |
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.
Note: In a UniversalApp application, you'll need to select either the Windows 8.1 or Windows Phone app to add the code file. The code file option is not available to add to the entire application.
C# Copy Code using C1.Xaml.Pdf; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Windows.Foundation; using Windows.Storage; using Windows.Storage.Pickers; using Windows.UI; using Windows.UI.Popups; using Windows.UI.Xaml; namespace PDFNewQSTest { /// <summary> /// Utility class on top of C1.Xaml.Pdf. /// </summary> 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.