static void manipulatePdf(string src, string dest, string imageFile) { PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileStream(dest, FileMode.Create, FileAccess.Write)); //GetInstance(System.Drawing.Image image, BaseColor color, bool forceBW) { System.Drawing.Image img = System.Drawing.Image.FromFile(imageFile); iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(img, iTextSharp.text.BaseColor.WHITE, false); PdfImage stream = new PdfImage(image, "", null); stream.Put(new PdfName("ITXT_SpecialId"), new PdfName("123456789")); PdfIndirectObject reference = stamper.Writer.AddToBody(stream); image.DirectReference = reference.IndirectReference; image.ScaleAbsolute(133, 100); iTextSharp.text.Rectangle pagesize = reader.GetPageSizeWithRotation(1); image.SetAbsolutePosition(0, pagesize.Height - 100); //image.ScaleAbsolute(new iTextSharp.text.Rectangle( PdfContentByte over = stamper.GetOverContent(1); over.AddImage(image); stamper.Close(); reader.Close(); }
private void UpdateImageStream(PRStream imageStream, byte[] newData) { PdfImage image = new PdfImage(Image.GetInstance(newData), "", null); if (imageStream.Contains(PdfName.SMASK)) { image.Put(PdfName.SMASK, imageStream.Get(PdfName.SMASK)); } if (imageStream.Contains(PdfName.MASK)) { image.Put(PdfName.MASK, imageStream.Get(PdfName.MASK)); } if (imageStream.Contains(PdfName.SMASKINDATA)) { image.Put(PdfName.SMASKINDATA, imageStream.Get(PdfName.SMASKINDATA)); } imageStream.Clear(); imageStream.PutAll(image); imageStream.SetDataRaw(image.GetBytes()); }
// --------------------------------------------------------------------------- /** * Creates a PDF document. */ public byte[] CreatePdf() { using (MemoryStream ms = new MemoryStream()) { using (Document document = new Document(new Rectangle(400, 300))) { PdfWriter writer = PdfWriter.GetInstance(document, ms); document.Open(); Image img = Image.GetInstance( Path.Combine(Utility.ResourceImage, "bruno.jpg" )); img.ScaleAbsolute(400, 300); img.SetAbsolutePosition(0, 0); PdfImage pi = new PdfImage(img, "", null); pi.Put(new PdfName("ITXT_SpecialId"), new PdfName("123456789")); PdfIndirectObject pio = writer.AddToBody(pi); img.DirectReference = pio.IndirectReference; document.Add(img); } return(ms.ToArray()); } }