locked
Creating and merging pdf files in C# + asp.net RRS feed

  • Question

  • User-1480307045 posted


    Hi,

    I have a scenario where i have a pdf and i need to add few pages to this pdf which contain some data and table of contents and render the same in asp.net webpage.

    What could be the best approach for this.

    i could think of following:

    1. Creating rdlc for the pages to be appended and merging two pdf's on the fly.

    2. Create and add pages programmatically using itextsharp to the existing pdf file and then streaming same to asp.net webpage.

    Please let me know your comments or any other approach which could suit my case.

    Thanks,

    Friday, October 19, 2012 3:18 PM

Answers

  • User-952121411 posted

    I have a scenario where i have a pdf and i need to add few pages to this pdf which contain some data and table of contents and render the same in asp.net webpage.

    Another sound 3rd party option that I have used personally is DynamicPDF Merge. Check out their online documentation and the section entitled "Adding New Pages to An Existing PDF Document". Expand: DynamicPDF Merger for .NET -> Programming with Merger for .NET -> Adding New Content. Essentially the code is as simple as below:

    MergeDocument document = new MergeDocument();
    Page page = new Page( PageSize.Letter, PageOrientation.Portrait );
    page.Elements.Add( new Label( "Cover Page", 0, 0, 512, 12 ) );
    document.Pages.Add( page );
    document.Append( @"C:\DocumentA.pdf");
    document.Draw( @"C:\MyDocument.pdf" );

    You can look at the tool using the following link:

    DynamicPDF Merger for .NET:
    http://www.dynamicpdf.com/Merge-PDF-.NET.aspx



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 22, 2012 9:00 AM

All replies

  • User1786833724 posted

    iTextsharp or LeadTools can help you. Both are 3rd party tools. We are using both. the former is free and the later need to be purchased from the LeadTools Tech (it's worth in my opnion).

    If you are using report files than it may be available to 'add to' if you are using some reporting tool like the GarpeCity have.

    Friday, October 19, 2012 4:20 PM
  • User-1480307045 posted

    See i have the requirement where in i have one pdf and i need to add some pages like front page, table of content and some other text pages in the start and show the same in browser. what could be the best possible solution for this,

    I can think of

    1. Creating a separate pdf and merging both of them on the fly.

    2 adding pages directly to the available pdf.

    What do you suggest?

    Sunday, October 21, 2012 3:36 PM
  • User1786833724 posted

    Well, in this case I would use LeadTools.

    Sunday, October 21, 2012 5:57 PM
  • User-952121411 posted

    I have a scenario where i have a pdf and i need to add few pages to this pdf which contain some data and table of contents and render the same in asp.net webpage.

    Another sound 3rd party option that I have used personally is DynamicPDF Merge. Check out their online documentation and the section entitled "Adding New Pages to An Existing PDF Document". Expand: DynamicPDF Merger for .NET -> Programming with Merger for .NET -> Adding New Content. Essentially the code is as simple as below:

    MergeDocument document = new MergeDocument();
    Page page = new Page( PageSize.Letter, PageOrientation.Portrait );
    page.Elements.Add( new Label( "Cover Page", 0, 0, 512, 12 ) );
    document.Pages.Add( page );
    document.Append( @"C:\DocumentA.pdf");
    document.Draw( @"C:\MyDocument.pdf" );

    You can look at the tool using the following link:

    DynamicPDF Merger for .NET:
    http://www.dynamicpdf.com/Merge-PDF-.NET.aspx



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 22, 2012 9:00 AM
  • User1786833724 posted

    Was just curious to know if how DynamicPDF is superior to LeadTools ?

    Monday, October 29, 2012 12:13 PM
  • User-1376047094 posted

    It can be done with ComponentPro Ultimate PDF. Developer can merge documents with the Merge method and then modify the merged document before saving:

    using System.IO;
    using ComponentPro.Pdf;
    namespace CSharp.Modify
    {
       class Merge
       {
           static void Main()
           {
               // Source files.
               string[] sourceFiles = new string[] {"file1.pdf", "file2.pdf"};
               // Merge documents.
               PdfDocument newDoc = PdfDocumentBase.Merge(sourceFiles);
               newDoc.Save("mypdf.pdf");
               newDoc.Close();
    
               // Create a new PDF document.
               PdfDocument newDoc2 = new PdfDocument();
               // Do something
               // ...
               // Merge documents.
               PdfDocumentBase.Merge(newDoc2, sourceFiles);
               newDoc2.Save("mypdf2.pdf");
               newDoc2.Close();
    
               // Read files to streams.
               Stream stream1 = new FileStream("file1.pdf", FileMode.Open);
               Stream stream2 = new FileStream("file2.pdf", FileMode.Open);
               PdfDocument newDoc3 = new PdfDocument();
               // Merge documents from streams.
               PdfDocumentBase.Merge(newDoc3, stream1, stream2);
               newDoc3.Save("mypdf3.pdf");
               newDoc3.Close();
    
               PdfDocument newDoc4 = new PdfDocument();
               // Merge documents from streams.
               PdfDocumentBase.Merge(newDoc4, stream1, stream2, "file4.pdf");
               newDoc4.Save("mypdf4.pdf");
               newDoc4.Close();
               stream1.Close();
               stream2.Close();
           }
       }
    }



    Tuesday, June 18, 2013 6:52 AM