使用iTextSharp将图像保存在现有PDF中。不工作

时间:2015-08-12 21:30:59

标签: c# asp.net asp.net-mvc-3 asp.net-mvc-4 c#-4.0

我正在使用下面提到的代码。由于某些原因,我无法将图像保存在输出PDF中。有什么我想念的吗?

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

    }
}

0 个答案:

没有答案