Forums

Overview » C# » How to Set PDF Properties with C#
Reply

How to Set PDF Properties with C#

Lemon Brown
Member



Since: 15 Sep 2011
Posts: 89
Posted 06 Mar 2012 02:18:31

PDF properties can show a brief information of one document, including document name, size and generated date. Besides, in Description, we can get document title, author and key words in document. Now, I want to introduce a method about how to set PDF properties by using C# via Spire.PDF.

using System;
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Graphics;

namespace PDFProperties
{
    class property
    {
        static void Main(string[] args)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            // Create one page
            PdfPageBase page = doc.Pages.Add();

            //Draw Page
            DrawPage(page);

            //Document Info
            doc.DocumentInformation.Author = "E-ICEBLUE";
            doc.DocumentInformation.Creator = "E-ICEBLUE";
            doc.DocumentInformation.Keywords = "Employee Information";
            doc.DocumentInformation.Producer = "Spire.Pdf";
            doc.DocumentInformation.Subject = "Data about employees personal information.";
            doc.DocumentInformation.Title = "EmployeeInfo";

            //File Info
            doc.FileInfo.CrossReferenceType = PdfCrossReferenceType.CrossReferenceStream;
            doc.FileInfo.IncrementalUpdate = false;
            doc.FileInfo.Version = PdfVersion.Version1_5;

            //Save
            doc.SaveToFile("Properties.pdf");
            doc.Close();

            //Launch
            System.Diagnostics.Process.Start("Properties.pdf");
        }
        private static void DrawPage(PdfPageBase page)
        {
            //Draw Image
            PdfImage image = PdfImage.FromFile(@"D:\work\My Documents\ei.png");
            float width = image.Width * 0.65f;
            float height = image.Height * 0.65f;
            float x = (page.Canvas.ClientSize.Width - width) / 2;

            page.Canvas.DrawImage(image, x, 40, width, height);
        }
    }
}

PDF properties can show a brief information of one document, including document name, size and generated date. Besides, in Description, we can get document title, author and key words in document. Now, I want to introduce a method about how to set PDF properties by using C# via Spire.PDF.

using System;
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Graphics;

namespace PDFProperties
{
    class property
    {
        static void Main(string[] args)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            // Create one page
            PdfPageBase page = doc.Pages.Add();

            //Draw Page
            DrawPage(page);

            //Document Info
            doc.DocumentInformation.Author = "E-ICEBLUE";
            doc.DocumentInformation.Creator = "E-ICEBLUE";
            doc.DocumentInformation.Keywords = "Employee Information";
            doc.DocumentInformation.Producer = "Spire.Pdf";
            doc.DocumentInformation.Subject = "Data about employees personal information.";
            doc.DocumentInformation.Title = "EmployeeInfo";

            //File Info
            doc.FileInfo.CrossReferenceType = PdfCrossReferenceType.CrossReferenceStream;
            doc.FileInfo.IncrementalUpdate = false;
            doc.FileInfo.Version = PdfVersion.Version1_5;

            //Save
            doc.SaveToFile("Properties.pdf");
            doc.Close();

            //Launch
            System.Diagnostics.Process.Start("Properties.pdf");
        }
        private static void DrawPage(PdfPageBase page)
        {
            //Draw Image
            PdfImage image = PdfImage.FromFile(@"D:\work\My Documents\ei.png");
            float width = image.Width * 0.65f;
            float height = image.Height * 0.65f;
            float x = (page.Canvas.ClientSize.Width - width) / 2;

            page.Canvas.DrawImage(image, x, 40, width, height);
        }
    }
}

Reply to this topic

Message
Reply
Follow us on twitter Subscribe to our RSS feed
Activate your free membership today | Login | Currency