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

时间:2022-05-22 13:50:35

不说了,直接代码

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(); iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(BarCodeHelper.MakeBarcodeImage(barcode, , true), BaseColor.WHITE); image.SetAbsolutePosition(, );
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 = ;
outputStream.Read(data, , 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。