Merge PDF files

4 posts, 1 answers
  1. Kipp
    Kipp avatar
    23 posts
    Member since:
    Sep 2012

    Posted 11 Feb 2013 Link to this post

    I need to merge multiple PDF files into one file.  Can the Telerik Winforms PDF API be used to do this?
  2. Answer
    Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 12 Feb 2013 Link to this post

    Hi Kipp,

    Thank you for contacting us.

    No, the current WinForms PDF API is only used to export grid data to PDF files. With the upcoming Q1 2013 we are going to release a new RadPdfViewer control for WinForms, which however will only be able to display PDF files.

    To merge PDF files, you need a library that can edit PDFs. Such library is the open source PdfSharp project. Here is a sample that demonstrates how you can merge two PDF files using this library: http://www.pdfsharp.com/PDFsharp/index.php?option=com_content&task=view&id=34&Itemid=45.

    I hope you find it useful. Do not hesitate to ask if you have any additional questions.

    All the best,
    Ivan Todorov
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Kipp
    Kipp avatar
    23 posts
    Member since:
    Sep 2012

    Posted 12 Feb 2013 Link to this post

    Thank you.  I found pdfSharp yesterday and have a working solution.  Great stuff!
  5. Kipp
    Kipp avatar
    23 posts
    Member since:
    Sep 2012

    Posted 19 Apr 2013 Link to this post

    Here's the static class I created to handle PDF merges in my solution:

    public static class PDF_Utilities

    {

    /// <SUMMARY>

    /// Imports all pages from a list of documents.

    /// </SUMMARY>

    public static void MergeFiles(List<string> filepaths, string outputFilePath, bool viewNow)

    {

    // Open the output document

    PdfDocument pdfDocument = new PdfDocument();

    // Iterate files

    foreach (string filepath in filepaths)

    {

    // Open the document to import pages from it.

    PdfDocument inputDocument = PdfReader.Open(filepath, PdfDocumentOpenMode.Import);

    // Iterate pages

    int pageCount = inputDocument.PageCount;

    for (int index = 0; index < pageCount; index++)

    {

    // Get the page from the external document...

    PdfPage page = inputDocument.Pages[index];

    // ...and add it to the output document.

    pdfDocument.AddPage(page);

    }

    }

    // Save the document...

    pdfDocument.Save(outputFilePath);

    // ...and start a viewer.

    if (viewNow)

    Process.Start(outputFilePath);

    }

    }

Back to Top