using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ExpertXPS;

namespace DemoXPS
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void BtnCreate_Click(object sender, EventArgs e)
        {
            // instantiate the main object of the library
            XPSDocument doc = new XPSDocument();

            // create a section - you can only add content to the document using sections
            XPSSection section1 = doc.AddSection();

            // set some styles
            section1.PageMargins.All = 50;
            section1.PageNumbering.Format = "Page <%#CurrentPage%> of <%#TotalCount%>";
            section1.PageNumbering.ShowNumberOnFirstPage = true;
            section1.PageNumbering.Alignment = XPSPageNumberAlignment.RightBottom;
            section1.PageOrientation = XPSPageOrientation.Portrait;
            section1.PageSize = XPSPageSize.A4;

            // add a paragraph to the document (to the first section of the document)
            XPSParagraph paragraph01 = section1.AddParagraph();

            // set the font of the text in the paragraph
            paragraph01.Font = new Font("Verdana", 12, FontStyle.Bold);

            // set the color of the text in the paragraph
            paragraph01.Color = Color.Blue;

            paragraph01.AddText("This is some text in the main section. This is some text in the main section. This is some text in the main section. This is some text in the main section. ");

            // you can set a different font / color for some of the texts in the paragraph
            paragraph01.AddText("This is another text in the same paragraph with a smaller red font. ", 
                new Font("Verdana", 10, FontStyle.Italic | FontStyle.Bold), 
                Color.Red);
            paragraph01.AddText("This is some other text in the main section.");
            paragraph01.AddNewLine();
            paragraph01.AddNewLine();
            paragraph01.AddText("This is some other text after a new line. This is some other text after a new line. This is some other text after a new line. ");

            // jump to a new page
            section1.AddPageBreak();

            // add a new paragraph
            XPSParagraph paragraph02 = section1.AddParagraph();
            paragraph02.Font = new Font("Arial", 14, FontStyle.Italic);
            paragraph02.Color = Color.Black;
            paragraph02.AddText("This is some text on a new page in the first section. This is some text on a new page in the first section. This is some text on a new page in the first section. This is some text on a new page in the first section. ");
            paragraph02.AddNewLine();
            paragraph02.AddNewLine();
            paragraph02.AddNewLine();
            paragraph02.AddText("Below is the same image as in the header with a smaller size:");
            paragraph02.AddNewLine();
            paragraph02.AddNewLine();

            // add an image
            XPSImage img1 = section1.AddImage(System.Drawing.Image.FromFile(Application.StartupPath + "/oss.jpg"));
            img1.Width = 300;


            XPSParagraph paragraph03 = section1.AddParagraph();

            paragraph03.AddNewLine();
            paragraph03.AddNewLine();
            paragraph03.AddNewLine();
            paragraph03.AddNewLine();
            paragraph03.AddNewLine();
            paragraph03.AddNewLine();
            paragraph03.AddNewLine();
            paragraph03.AddNewLine();
            paragraph03.AddNewLine();
            paragraph03.AddNewLine();
            paragraph03.AddText("Below is some text added from an HTML string:");
            paragraph03.AddNewLine();
            paragraph03.AddNewLine();

            string html = @"
<b>This is a bold text</b>
<br>
<br>
<i>This is some italic text</i>
<br>
<a href='http://www.html-to-pdf.net/xps-library'>This is a link to ExpertXPS Website</a>
<br>
<font color='red'>Red text. Red text. Red text. Red text. Red text. </font>
";
            paragraph03.AddHTML(html);


            
            // HEADER

            // set the header of the document section
            XPSSectionHeader header1 = section1.AddHeader();
            header1.Height = 150;

            // add an image to the header of the section
            XPSImage img2 = header1.AddImage(System.Drawing.Image.FromFile(Application.StartupPath + "/oss.jpg"), 0, 0);
            img2.Width = 500;


            // FOOTER

            // set the footer of the document section
            XPSSectionFooter footer1 = section1.AddFooter();
            footer1.Height = 20;

            XPSParagraph paragraph2 = footer1.AddParagraph(0, 0);
            paragraph2.Color = Color.Blue;
            paragraph2.Font = new Font("Verdana", 12, FontStyle.Bold);
            paragraph2.AddText("This is some text in the footer of the document.");

            
            // SAVE ON DISK
            
            // save the XPS file on the disk
            string FileName = Application.StartupPath + "/document.xps";
            doc.Save(FileName);

            // open the XPS file in the local viewer
            System.Diagnostics.Process.Start(FileName);
        }
    }
}