Posts

Showing posts from January 17, 2014

Create an Excel file using Excel libraray

 private void button9_Click(object sender, EventArgs e)         {             string file = "E:\\" + "newdoc" + DateTime.Now.Millisecond + ".xls";             Workbook workbook = new Workbook();             Worksheet worksheet = new Worksheet("First Sheet");             worksheet.Cells[0, 1] = new Cell((short)1);             worksheet.Cells[2, 0] = new Cell(2.8);             worksheet.Cells[3, 3] = new Cell((decimal)3.45);             worksheet.Cells[2, 2] = new Cell("Text sduplicated across each Web server in the farm.");             worksheet.Cells[2, 4] = new Cell("Second string");             worksheet.Cells[4, 0] = new Cell(32764.5, "#,##0.00");             worksheet.Cells[5, 1] = new Cell(DateTime.Now, @"YYYY\-MM\-DD");             worksheet.Cells[1, 1] = new Cell("http://www.gooogle.com");             worksheet.Cells.ColumnWidth[0, 1] = 3000;             //Picture pic = new P

inset a text into an existing pdf

private void button4_Click(object sender, EventArgs e)         {             String sourceFileName = "D:\\reader2.pdf";             String newFileName = "E:\\" + DateTime.Now.Millisecond + ".pdf";             InsertTextToPdf(sourceFileName, newFileName);         }  private static void InsertTextToPdf(string sourceFileName, string newFileName)         {             using (Stream pdfStream = new FileStream(sourceFileName, FileMode.Open))             using (Stream newpdfStream = new FileStream(newFileName, FileMode.Create, FileAccess.ReadWrite))             {                 PdfReader pdfReader = new PdfReader(pdfStream);                 PdfStamper pdfStamper = new PdfStamper(pdfReader, newpdfStream);                 PdfContentByte pdfContentByte = pdfStamper.GetOverContent(1);                 BaseFont baseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);                 pdfContentByte.SetColorFill(BaseC

insert a image into pdf document

private void button2_Click(object sender, EventArgs e)         {             String sourceFileName = "D:\\reader2.pdf";             String imageFileName = "D:\\AxaltaByAnil.jpg";             String newFileName = "E:\\" + DateTime.Now.Millisecond + ".pdf";             OpenFileDialog dlg = new OpenFileDialog();             ////string filepath;             dlg.Filter = "PDF Files(*.PDF)|*.PDF|All Files (*.*)|*.*";             if (dlg.ShowDialog() == DialogResult.OK)             {                 sourceFileName = dlg.FileName.ToString();                 InsertImageToPdf(sourceFileName, imageFileName, newFileName);             }             ////InsertTextToPdf("asd", "jahlks");         } private static void InsertImageToPdf(string sourceFileName, string imageFileName, string newFileName)         {             using (Stream pdfStream = new FileStream(sourceFileName, FileMode.Open, FileAccess.Read, FileSha

Read the pdf file and convert it into a .doc file

private void button3_Click(object sender, EventArgs e)         {             //path you want to store PDF             string pdfPath = string.Format(@"E:\{0}.pdf", DateTime.Now.ToString("yyyy-MM-dd hhmmss"));             using (FileStream msReport = new FileStream(pdfPath, FileMode.Create))             {                 //step 1                 using (Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 140f, 30f))                 {                     // step 2                     PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, msReport);                     //open the stream                     pdfDoc.Open();                     iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance("ANIL SCAN.jpg");                     jpg.Alignment = iTextSharp.text.Image.ALIGN_LEFT;                     jpg.Border = iTextSharp.text.Rectangle.NO_BORDER;                     jpg.BorderColor = iTextSharp.text.BaseColor.WHITE;