public static void GeneratePODForm(string templateFormsPath, string podFilePath, string receivedBy, string receivingTime, string signature) { PdfReader reader = new PdfReader(templateFormsPath); //select three pages from the original document reader.SelectPages("1-3"); //create PdfStamper object to write to get the pages from reader PdfStamper stamper = new PdfStamper(reader, new FileStream(podFilePath, FileMode.Create)); Rectangle pagesize = reader.GetPageSize(1); // PdfContentByte from stamper to add content to the pages over the original content PdfContentByte pbover = stamper.GetOverContent(1); PdfContentByte pbunder = stamper.GetUnderContent(1); //add content to the page using ColumnText ColumnText.ShowTextAligned(pbover, Element.ALIGN_LEFT, new Phrase(receivedBy), pagesize.Left + 320, pagesize.Bottom + 90, 0); ColumnText.ShowTextAligned(pbover, Element.ALIGN_LEFT, new Phrase(receivingTime), pagesize.Left + 400, pagesize.Bottom + 60, 0); // PdfContentByte from stamper to add content to the pages under the original content //add image from a file iTextSharp.text.Image img = new Jpeg(imageToByteArray(System.Drawing.Image.FromFile(signature))); //add the image under the original content img.SetAbsolutePosition(pagesize.Left + 380, pagesize.Bottom + 10); pbunder.AddImage(img); //pbunder.AddImage(img, img.Width / 2, 0, 0, img.Height / 2, 0, 0); //close the stamper stamper.Close(); }
private void pdfToolStripMenuItem_Click(object sender, EventArgs e) { try { SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "Bulmaca Pdf Kayıt"; sfd.Filter = "Pdf Dosyası (*.pdf) | *.pdf"; string sfdname = sfd.FileName; if (sfd.ShowDialog() == DialogResult.OK) { kelimeEkleText.Focus(); soldanSagaSorular.BorderStyle = BorderStyle.None; yukaridanAsagiyaSorular.BorderStyle = BorderStyle.None; var doc = new iTextSharp.text.Document(); MemoryStream ms = new MemoryStream(); Bitmap img2 = new Bitmap(A4.Width, A4.Height); A4.DrawToBitmap(img2, new System.Drawing.Rectangle(0, 0, A4.Width, A4.Height)); iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create)); doc.Open(); iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(img2, System.Drawing.Imaging.ImageFormat.Png); var jpeg = new Jpeg(img); jpeg.ScaleToFit(doc.PageSize.Width - (doc.LeftMargin + doc.RightMargin), doc.PageSize.Height - (doc.BottomMargin + doc.TopMargin)); jpeg.SetAbsolutePosition(doc.BottomMargin, doc.TopMargin); doc.Add(jpeg); doc.Close(); soldanSagaSorular.BorderStyle = BorderStyle.FixedSingle; yukaridanAsagiyaSorular.BorderStyle = BorderStyle.FixedSingle; } } catch { } }