Skip to content

Instantly share code, notes, and snippets.

@pedroinfo
Created July 13, 2017 20:18
Show Gist options
  • Save pedroinfo/2f44f1b4f08f8f3d8dac22de1235650f to your computer and use it in GitHub Desktop.
Save pedroinfo/2f44f1b4f08f8f3d8dac22de1235650f to your computer and use it in GitHub Desktop.
Merge image files with itextsharp
public static void MergeFilesPdf(string destinationFile, List<string> fileNames)
{
Document document = new Document();
using (var stream = new FileStream(destinationFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
PdfWriter.GetInstance(document, stream);
document.Open();
foreach (string strFileName in fileNames)
{
using (var imageStream = new FileStream(strFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
var image = iTextSharp.text.Image.GetInstance(imageStream);
image.Alignment = Element.ALIGN_CENTER;
image.SetAbsolutePosition(0, 0);
image.ScaleToFit(document.PageSize.Width, document.PageSize.Height);
document.Add(image);
document.NewPage();
}
}
document.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment