Hello World

This example demonstrates how to write a simple text to a PDF document.

Hello it's me
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
using OfficeComponent.Pdf;
using OfficeComponent.Pdf.Graphics;

namespace OfficeComponent.Samples
{
    class HelloWorldExample : ExampleBase
    {
        public HelloWorldExample(string commonDataPath, string outputDir)
            : base(commonDataPath, outputDir)
        {
        }

        public HelloWorldExample(string commonDataPath, string outputDir, string xmlFile) : base(commonDataPath, outputDir, xmlFile)
        {
        }

        public override string Execute()
        {
            // Create a new instance of PdfDocument class.
            PdfDocument doc = new PdfDocument();

            PdfPage page = doc.Pages.Add();

            // Create a solid brush
            PdfBrush brush = new PdfSolidBrush(Color.Black);

            const float fontSize = 24.0f;

            // Set the font
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, fontSize);

            // Draw the text
            page.Graphics.DrawString("Hello World!", font, brush, new PointF(30, 30));



            // Save and close the document.
            var outputPath = Path.Combine(OutputDir, this.GetType().Name + "_" + Guid.NewGuid().ToString() + ".pdf");
            doc.Save(outputPath);
            doc.Close(true);

            return outputPath;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
using OfficeComponent.Pdf;
using OfficeComponent.Pdf.Graphics;

namespace OfficeComponent.Samples
{
    class HelloWorldExample : ExampleBase
    {
        public HelloWorldExample(string commonDataPath, string outputDir)
            : base(commonDataPath, outputDir)
        {
        }

        public HelloWorldExample(string commonDataPath, string outputDir, string xmlFile) : base(commonDataPath, outputDir, xmlFile)
        {
        }

        public override string Execute()
        {
            // Create a new instance of PdfDocument class.
            PdfDocument doc = new PdfDocument();

            PdfPage page = doc.Pages.Add();

            // Create a solid brush
            PdfBrush brush = new PdfSolidBrush(Color.Black);

            const float fontSize = 24.0f;

            // Set the font
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, fontSize);

            // Draw the text
            page.Graphics.DrawString("Hello World!", font, brush, new PointF(30, 30));



            // Save and close the document.
            var outputPath = Path.Combine(OutputDir, this.GetType().Name + "_" + Guid.NewGuid().ToString() + ".pdf");
            doc.Save(outputPath);
            doc.Close(true);

            return outputPath;
        }
    }
}