Step 3 of 4: Saving and Loading the Document

In this step you'll add code to save the document using the Save method and then display the PDF file the C1PdfViewer control.

Add the following code to the MainPage.xaml.cs just below the code added in the previous step:

public void HandleButtonClick(object sender, RoutedEventArgs e)

{

    // create document

    var pdf = new C1PdfDocument(PaperKind.Letter);

    pdf.Clear();

 

    // create document

    CreateDocumentText(pdf);

 

    // save document

    var fileName = "TestFile.pdf";

    var file = IsolatedStorageFile.GetUserStoreForApplication();

    using (var stream = file.CreateFile(fileName))

    {

        pdf.Save(stream);

 

    }

    using (var stream = file.OpenFile(fileName, System.IO.FileMode.Open))

    {

        this.pdfViewer.LoadDocument(stream);

        this.pdfViewer.ViewMode = C1.Phone.PdfViewer.ViewMode.FitWidth;

    }

}

Now when the button is pressed, a PDF file will be created, saved to a stream, and then loaded into the C1PdfViewer control.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.