Having 2 different pdf in stream , and want to merge selected pages

Posted by: somya.5 on 29 May 2023, 5:33 am EST

  • Posted 29 May 2023, 5:33 am EST

    Hello, i have to two or more pdf i want to merge selected pages. how i can open file from stream in gc , like we earlier using pdfsharp they have this code to open already selected pdf

    var openPdfDocument = PdfReader.Open(stream, PdfDocumentOpenMode.Import);

    what will equivalent code to open stream in grapecity ?

  • Posted 29 May 2023, 2:31 pm EST

    Hello Somya,

    To open the pdf via stream, you can use the following overload of the Load method:

    Load(Stream) Method

    https://www.grapecity.com/documents-api-pdf/docs/online/GrapeCity.Documents.Pdf~GrapeCity.Documents.Pdf.GcPdfDocument~Load(Stream,String).html

    https://www.grapecity.com/documents-api-pdf/docs/online/quickstart.html#load

    You can also check out our Demo sample for evaluating the Documents for Pdf API.

    If you need any help on this, please feel free to ask.

    Regards,

    Prabhat Sharma.

  • Posted 12 June 2023, 12:16 am EST - Updated 12 June 2023, 5:58 pm EST

    I have two streams and want to merge selected page like page 2 from stream 1 and page 4 and 6 from stream 2. How i can do this using GC PDF ? i used PageCollection pageCollection = doc.Pages; but i am not able to merge the selected pages.

    var pdfDocument = new GcPdfDocument();

    GcPdfDocument doc = new GcPdfDocument();

    GcPdfDocument doc2 = new GcPdfDocument();

    doc.Load(stream1);

    doc2.Load(stream2);

    PageCollection pageCollection = doc.Pages; //6

    PageCollection pageCollection2 = doc2.Pages; //5

    GcPdfDocument selectedPage1 = new GcPdfDocument();

    GcPdfDocument selectedPage2 = new GcPdfDocument();

    var ms= pageCollection[4].GetStream();

    selectedPage.Load(ms);

    var ms2= pageCollection2[3].GetStream();

    pdfDocument.MergeWithDocument(selectedPage);

    selectedPage2 .Load(ms2);

    pdfDocument.MergeWithDocument(selectedPage2 );

    tthis gives me error '%%eof marker is not found when we load stream on selectedpage.

                                            }
    

    This code giving me error '%%eof marker is not found .

  • Posted 12 June 2023, 7:21 pm EST

    Hello Somya,

    There is no direct way to load the pages from the pdf to the GcPdf API so you can create a new GcPdf object and merge the respected pages from your pdfs one by one.

    Please find the attached sample implementing the same and let us know if it helps.

    In case you still face any issues then please let us know and modify the attached sample accordingly.

    Regards,

    Prabhat Sharma.

    MergePdfDemo.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels