Created
January 18, 2013 09:40
-
-
Save cairey/4563456 to your computer and use it in GitHub Desktop.
iTextSharp PdfStamper stream to MVC File Result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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