This is a migrated thread and some comments may be shown as answers.

Merge PDF files

3 Answers 498 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kipp
Top achievements
Rank 1
Kipp asked on 11 Feb 2013, 02:27 PM
I need to merge multiple PDF files into one file.  Can the Telerik Winforms PDF API be used to do this?

3 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Todorov
Telerik team
answered on 12 Feb 2013, 10:22 AM
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.
0
Kipp
Top achievements
Rank 1
answered on 12 Feb 2013, 01:37 PM
Thank you.  I found pdfSharp yesterday and have a working solution.  Great stuff!
0
Kipp
Top achievements
Rank 1
answered on 19 Apr 2013, 12:46 PM
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);

}

}

Tags
General Discussions
Asked by
Kipp
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Kipp
Top achievements
Rank 1
Share this question
or