Been struggling with this.
I have a physical file (pdf) and a generated one that is generated by iTextSharp (pdf) my goal is to merge both of them and output it to the browser.
By the way, I am using ASP.NET MVC 4
So, in my controller, I have something like this:
public ActionResult Index()
{
MemoryStream memoryStream = new MemoryStream();
var path = Server.MapPath("~/Doc/../myfile.pdf"); // This is my physical file
var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
GenerateFile(); // This is my generated file thru iTextSharp
Response.AddHeader("Content-Disposition", "inline");
memoryStream.Position = 0;
return new FileStreamResult(// Maybe merged file goes here? not sure.
,"application/pdf");
}
private void GenerateFile()
{
MemoryStream stream = new MemoryStream();
var document = new Document(/*some settings here*/);
PdfWriter.GetInstance(document, stream).CloseStream = false;
document.Open();
// generate pdf here
document.Close();
}
And is it possible to set the generated pdf as the first (or how many pages it will generate) page then append the physical file?
Any help would be much appreciated. Thanks