C# PDF Library


In the Visual Studio Marketplace there is a Free .NET PDF Library called Free Spire.PDF for .NET. It enables developers to create, write, edit, convert, print, handle and read PDF files on any .NET applications.

You can create a Windows Form application and manipulate PDF files. You will need to download and install the software to your hard drive. After you create your Windows Forms project in Visual Studio (Windows Desktop > Windows Forms App (.NET Framework) you can begin coding. The software comes with an independent application that gives you example code to practice with.

using System;
using System.Drawing;
using System.Windows.Forms;
using Spire.Pdf;
using Spire.Pdf.Graphics;
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();
            //Create one page
            PdfPageBase page = doc.Pages.Add();
            //Draw the text
            page.Canvas.DrawString("Hello, Dioni!",
                                   new PdfFont(PdfFontFamily.Helvetica, 30f),
                                   new PdfSolidBrush(Color.Black),
                                   10, 10);
            //Save the document
            doc.SaveToFile(@"D:\test\HelloDioni.pdf");
            doc.Close();
            //Launch the Pdf file
            PDFDocumentViewer(@"D:\test\HelloDioni.pdf");
            //Open pdf document
            PdfDocument doc2 = new PdfDocument();
            doc.LoadFromFile(@"D:\test\HelloDioni.pdf");
            // the pdf version
            MessageBox.Show($"File version is: {doc.FileInfo.Version}");
            doc.Close();
        }
        private void PDFDocumentViewer(string fileName)
        {
            try
            {
                System.Diagnostics.Process.Start(fileName);
            }
            catch { }
        }
    }
}