I am using itextsharp c# that creates PDF files, it also has user signatures, i need to combine those PDFs so that user can generate single PDF file, the files are combining perfectly but that works if there is no signature, the solution is to create PDF portfolio I found many examples that create portfolio but that all generating PDF fields and document on fly, in my case I have already PDF generated but I need to create portfolio with existing files.
Here is current code to merge pdf files:
using (System.IO.MemoryStream msOutput = new System.IO.MemoryStream())
{
using (iTextSharp.text.Document doc = new iTextSharp.text.Document())
{
using (iTextSharp.text.pdf.PdfSmartCopy pCopy = new iTextSharp.text.pdf.PdfSmartCopy(doc, msOutput) { PdfVersion = iTextSharp.text.pdf.PdfWriter.VERSION_1_7 })
{
doc.Open();
foreach (byte[] oFile in files)
{
using (iTextSharp.text.pdf.PdfReader pdfFile = new iTextSharp.text.pdf.PdfReader(oFile))
{
for (int i = 1; i <= pdfFile.NumberOfPages; i++)
{
pCopy.AddPage(pCopy.GetImportedPage(pdfFile, i));
}
}
}
}
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "Output_Filename.pdf"));
// Response.AddHeader("Content-Length", msOutput.Length.ToString());
Response.BinaryWrite(msOutput.ToArray());
Response.End();