Skip to content

Instantly share code, notes, and snippets.

@cairey
Created January 18, 2013 09:40
Show Gist options
  • Save cairey/4563456 to your computer and use it in GitHub Desktop.
Save cairey/4563456 to your computer and use it in GitHub Desktop.
iTextSharp PdfStamper stream to MVC File Result
public virtual ActionResult PdfDownloadTravel()
{
var reader = new PdfReader(Server.MapPath("~/pdf/travel_insurance_card.pdf"));
var outputPdfStream = new MemoryStream();
var stamper = new PdfStamper(reader, outputPdfStream) { FormFlattening = true, FreeTextFlattening=true };
var form = stamper.AcroFields;
form.SetField("Name", "");
form.SetField("number", "500-0000324");
stamper.SetFullCompression();
stamper.Close();
var file = outputPdfStream.ToArray();
var output = new MemoryStream();
output.Write(file, 0, file.Length);
output.Position = 0;
var cd = new System.Net.Mime.ContentDisposition
{
FileName = "Reiseforsikringskort.pdf",
Inline = false,
Size = file.Length,
CreationDate = DateTime.Now
};
Response.AppendHeader("Content-Disposition", cd.ToString());
return File(output, System.Net.Mime.MediaTypeNames.Application.Pdf);
}
@Niladri24dutta
Copy link

Hi .. can you please share the sample pdf template travel_insurance_card.pdf for this ?? I need to fill up a pdf template with placeholders using itextsharp but i am not able to find or create any sample pdf template for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment