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();

Comments

  1. Use this diet hack to drop 2 lb of fat in just 8 hours

    Over 160 thousand men and women are trying a simple and SECRET "water hack" to lose 1-2lbs every night while they sleep.

    It's very simple and works every time.

    You can do it yourself by following these easy steps:

    1) Go grab a drinking glass and fill it half glass

    2) Proceed to follow this awesome hack

    so you'll be 1-2lbs thinner when you wake up!

    ReplyDelete

Post a Comment

Popular posts from this blog

how to insert text and tags at the cursor CKEDITOR