首页 > 其他 > 详细

打开现有的pdf,并插入一个图片

时间:2015-02-26 16:17:22      阅读:325      评论:0      收藏:0      [点我收藏+]

不说了,直接代码

T_ScanUploadData file = _IScanUploadDataAccessService.GetScanUploadData(id);
            byte[] filedata = FineUploaderUtil.DownloadData(file.SignDocPath);
            
            string filename = Server.MapPath("//pictemp/") + "downSignDoc.pdf";
            //using (Stream inputPdfStream = new FileStream(@"d:\Users\Administrator\Desktop\xml\111.pdf", FileMode.Open, FileAccess.Read, FileShare.Read))
            //using (Stream inputImageStream = new FileStream(@"d:\Users\Administrator\Desktop\xml\myimage.jpg", FileMode.Open, FileAccess.Read, FileShare.Read))
            using (Stream outputPdfStream = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) {
                var reader = new PdfReader(filedata);
                var stamper = new PdfStamper(reader, outputPdfStream);
                var pdfContentByte = stamper.GetOverContent(1);

                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(BarCodeHelper.MakeBarcodeImage(barcode, 1, true), BaseColor.WHITE);

                image.SetAbsolutePosition(430, 730);
                pdfContentByte.AddImage(image);
                stamper.Close();

                Stream outputStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None);
                int length = (int)outputStream.Length;
                byte[] data = new byte[length];
                outputStream.Position = 0;
                outputStream.Read(data, 0, length);
                MemoryStream ms = new MemoryStream(data);

                Response.AppendHeader("Content-Disposition", "attachment;filename=" + "" + file.OrderNo + "." + System.IO.Path.GetExtension(file.SignDocPath));
                Response.BinaryWrite(ms.ToArray());
                Response.End();
                ms.Close();
                ms = null;

            }

用的iTextSharp。

打开现有的pdf,并插入一个图片

原文:http://www.cnblogs.com/brantshi/p/4301245.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!