Posts

Showing posts with the label iTextSharp

how to stop pdf editing using itextsharp

Editable pdf file textbox, checkbox, etc. doesn't write after creating pdf file from itextsharp this file should not be editable code below: pdfStamper.FormFlattening =  true ;

Add Image through base64 on PDF in itextsharp

If you have base64 code image or image path, easily can add image in PDF from iTextSharp. Code below: PdfReader pdfReader =  new  PdfReader( "C:\\file.pdf" ); PdfStamper pdfStamper =  new  PdfStamper(pdfReader,  new  FileStream( "target save path" , FileMode.Create)); string  imagepath =  "base64 image code" ; Byte[] bytes = Convert.FromBase64String(Regex.Replace(imagepath, @ "^data:image\/[a-zA-Z]+;base64," ,  string .Empty)); var  pdfContentByte = pdfStamper.GetOverContent(1);  // page number iTextSharp.text.Image image1 = iTextSharp.text.Image.GetInstance(bytes); image1.SetAbsolutePosition(140, 70); image1.ScalePercent(20f); pdfContentByte.AddImage(image1); pdfStamper.Close();