Pages

Wednesday, July 6, 2011

sharepoint 2010 Javascript Function to acess the Control

Here is a Javascript Function to acess the Control.
tagName – The name of the tag rendered in the form’s HTML
identifier – The string associated with the SharePoint type of the relevant ield
title – The value of the relevant HTML tag’s “title” attribute, which also matches the field’s display name

ref from:http://blogs.msdn.com/b/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx

function getTagFromIdentifierAndTitle(tagName, identifier, title) { 
     var len = identifier.length; 
     var tags = document.getElementsByTagName(tagName); 
     for (var i=0; i < tags.length; i++) { 
          var tempString = tags[i].id; 
          //if you are not sure what the actual title of your field is, uncomment this alert 
          //alert(tags[i].title); 
          if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) { 
               return tags[i]; 
          } 
      } 
      return null; 
}
for eg: if you control rendered as(Use FireBug or Devlopers Tool)
"input type="text" autopostback="0" class="ms-input" title="Calendar2" id="ctl00_m_g_267b3037_41f7_4630_8946_1f2378ebeda2_ctl00
_ctl05_ctl03_ctl00_ctl00_ctl04_ctl00_ctl00_DateTimeField_
DateTimeFieldDate" 
maxlength="45" name="ctl00$m$g_267b3037_41f7_4630
_8946_1f2378ebeda2$ctl00$ctl05$ctl03$ctl00$ctl00$ctl04$ctl00$ctl00
$DateTimeField$DateTimeFieldDate"
Here
Tag Name: is input
Title: is Calendar2
Identifier: is DateTimeFieldDate

Friday, February 25, 2011

Watermark on a Exisiting PDF using iTextsharp Library

iText Download
Creating a Template For Text Watermark
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using System.Drawing;
namespace ConsoleApplication1
{
    public static class GenrateStampingTemplate
    {

        public static void createTemplate(string StampSignautre, string stampFilename)
        {
            Document document = new Document();
            PdfWriter writer = PdfWriter.GetInstance(document, 
                new FileStream(stampFilename, FileMode.Create));
            document.Open();
            iTextSharp.text.Font font =
                new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.COURIER, 22, 
                    iTextSharp.text.Font.NORMAL,
                    new BaseColor(System.Drawing.Color.Blue));
            ColumnText.ShowTextAligned(writer.DirectContent, Element.ALIGN_CENTER, 
                new Phrase(StampSignautre, font), 297.5f, 421, 45);
            document.Close();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using System.IO;
using iTextSharp.text;

namespace ConsoleApplication1
{
    /// 
    /// This class is used to Put Watermark Text and Image on PDF Document
    /// 
   public static class StampDocument
   {
       
      public static void PutTextWateMark(string path,string waterMarkTemplate)
      {
            byte[] _byte = File.ReadAllBytes(path);
            byte[] _templateBye = File.ReadAllBytes(waterMarkTemplate);
            PdfReader reader = new PdfReader(_byte);
            PdfStamper pdfStamper = new PdfStamper(reader, 
                new FileStream(path, FileMode.Create));
            PdfContentByte content;
            PdfReader templateReader = new PdfReader(_templateBye);
            PdfImportedPage page = pdfStamper.GetImportedPage(templateReader, 1);
            for (int i = 0; i < reader.NumberOfPages; i++)
            {
                content = pdfStamper.GetUnderContent(i+1);
                content.AddTemplate(page, 0, 0);
            }
            pdfStamper.Close();
            templateReader.Close();
            
     }
     public static void PutImageWaterMark(string path, string imagePath)
     {
            byte[] _byte = File.ReadAllBytes(path);
            
            PdfReader reader = new PdfReader(_byte);
            PdfStamper pdfStamper = new PdfStamper(reader,
                new FileStream(path, FileMode.Create));
            Image img = Image.GetInstance(imagePath);
            PdfContentByte content;
            
            img.SetAbsolutePosition(200, 400);
            
            for (int i = 0; i < reader.NumberOfPages; i++)
            {
                content = pdfStamper.GetUnderContent(i+1);
                content.AddImage(img);
            }
            pdfStamper.Close();
            

     }
  }
}
//using custom Text
GenrateStampingTemplate.createTemplate("Watermark", "d:\\CompanyStamp.pdf");
StampDocument.PutTextWateMark("d:\\test.pdf", "d:\\CompanyStamp.pdf");
//using image
StampDocument.PutImageWaterMark("d:\\test.pdf", "d:\\test.img");