Step 2 of 4: Adding Content to the Page

In this step you'll switch to Code View and add some content to the document using the DrawString method.

1.   Open the MainPage.xaml.cs file in Visual Studio and add the following code at the top of the page with the using statements:

using C1.Phone.Pdf;

using System.IO.IsolatedStorage;

using C1.Phone.PdfViewer;

2.   Then add the following code just after the MainPage constructor:

public static void CreateDocumentText(C1PdfDocument pdf)

{

    // use landscape for more impact

    pdf.Landscape = true;

 

    // measure and show some text

    var text = "Hello World!";

    var font = new Font("Times New Roman", 60, PdfFontStyle.Italic);

 

    // create StringFormat used to set text alignment and line spacing

    var fmt = new StringFormat();

    fmt.LineSpacing = -1.5; // 1.5 char height

    fmt.Alignment = HorizontalAlignment.Center;

 

    // measure it

    var sz = pdf.MeasureString(text, font, 72 * 3, fmt);

    var rc = new Rect(pdf.PageRectangle.Width / 2, 72, sz.Width, sz.Height);

 

 

    // draw the text

    pdf.DrawString(text, font, Colors.Black, rc, fmt);

}

This code creates content that will appear in the PDF file.


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