mercredi 12 août 2015

Save image in Existing PDF using iTextSharp. Not Working

I am using the below mentioned code. Due to some reasons I am not able to save the image in output PDF. is there anything I am missing ?

string imageFileName = Path.Combine(Application.StartupPath, "a.jpg");
var inputpdf = Path.Combine(Application.StartupPath, "b.pdf");
var outputpdf = Path.Combine(Application.StartupPath, "output.pdf");

using (Stream inputPdfStream = new FileStream(inputpdf, FileMode.Open, FileAccess.Read, FileShare.Read))
{
    using (Stream inputImageStream = new FileStream(imageFileName, FileMode.Open, FileAccess.Read, FileShare.Read))
    {

        var reader = new PdfReader(inputPdfStream);
        var stamper = new PdfStamper(reader, new FileStream(outputpdf, FileMode.Create), '\0', true);
        var pdfContentByte = stamper.GetOverContent(1);

        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
        image.SetAbsolutePosition(10, 10);
        pdfContentByte.AddImage(image);
        stamper.Close();

    }
}

Aucun commentaire:

Enregistrer un commentaire