0

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();
afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
  • 1
    *"here is current code to merge pdf files"* - in your question you yourself have mentioned that that code breaks signatures and you want to create portfolios instead. Thus, you surely have tried to implement a routine for creating a portfolio und are stuck at some problem with that. So, why don't you simply post *that* code to allow us showing you where to improve it? – mkl Mar 23 '17 at 16:12
  • What do you mean by "has user signatures". Are you using some application to digitally sign PDFs? – afuzzyllama Mar 23 '17 at 16:12
  • Same code is breaking if pdf has signature fields following line throws error: using (iTextSharp.text.pdf.PdfReader pdfFile = new iTextSharp.text.pdf.PdfReader(oFile)) { for (int i = 1; i <= pdfFile.NumberOfPages; i++) PDF header signature not found. – Integrated guy Mar 23 '17 at 18:59
  • @afuzzyllama Yes it require internet explorer for the user to sign it and PDF has submit button that submit the whole PDF. – Integrated guy Mar 23 '17 at 19:02
  • *"PDF header signature not found"* is not due to the presence or absence of signature fields, you have a different issue. – mkl Mar 23 '17 at 20:44
  • Look at this question... http://stackoverflow.com/questions/9833572/how-to-merge-pdfs-into-a-pdf-portfolio – joelgeraci Mar 23 '17 at 21:04
  • @mkl You are right I found the solution here http://stackoverflow.com/questions/15521972/pdf-merging-by-itextsharp – Integrated guy Mar 23 '17 at 21:30
  • Thank you all the issue has been resolved. – Integrated guy Mar 23 '17 at 21:32

0 Answers0