Tuesday, April 5, 2016

I have been using iTextSharp to merge multiple PDF files

A few years ago, I was wondering if there was any easy way to merge my PDF files all together into one single file. I knew there were a few commercial products out there, but I wanted something letting me handle the page number freely.

That was the reason why I developed this PDF_MergeFiles using iTextSharp, an opensource .NET library.  I am sure iTextSharp has added many new features since then, but I here post my codes hoping they will be useful to you.

public static void PDF_MergeFiles(string targetFile, string[] sourceFiles,
int pageFrom = 1)

  targetFile = a target file name with a full path  (C:\temp\myFile.pdf)
  sourceFiles = must be provided as an array of string, each file name with a full path
  pageFrom = 1, the target file will have a page number from the first page 


Place two source files in your project to consume these static methods. Also, iTextSharp DLL files must be part of your project too.

All files can be found from here at my git repositories, risknet.
https://github.com/risknet/pdf_service

No comments: