next up previous contents index
Next: Example Program in VB.NET Up: cpdflibmanual Previous: Dates   Contents   Index

Example Program in C#

This program loads a file from disk, adds page numbers, and then writes the file encrypted to disk.
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
          //Load the (unencrypted) input file
          Pdf.pdfdoc pdf = Cpdflib.FromFile("C:\\input.pdf");

          //Resolve any rotation of pages
          Cpdflib.Upright(pdf, Cpdflib.All(pdf));

          //Add page numbers
          Cpdflib.AddText
            (pdf,                                 //Document
             Cpdflib.All(pdf),                    //Range
             "Page %Page of %EndPage",            //Text
             Cpdf.position.Top(20.0),             //Position
             1.0,                                 //Line spacing
             0,                                   //Bates number
             Pdftext.standard_font.TimesBold,     //Font
             12.0,                                //Font Size
             Cpdflib.Black,                       //Text Color
             false);                              //If set, stamp on shorter side

          //Write to file, encrypted with AES encryption
          Pdfcrypt.permission[] permissions =
            {Pdfcrypt.permission.NoEdit,
             Pdfcrypt.permission.NoAssemble};
          Cpdflib.ToFileEncrypted
             (pdf,                                          //Document
              Pdfwrite.encryption_method.AES128bit(false),  //Encryption method
              permissions,                                  //Permissions
              "fred",                                       //Owner Password
              "charles",                                    //User Password
              false,                                        //Linearize
              "C:\\output.pdf");                            //Output filename
        }
    }
}


root 2008-12-01