Created
July 13, 2017 20:18
-
-
Save pedroinfo/2f44f1b4f08f8f3d8dac22de1235650f to your computer and use it in GitHub Desktop.
Merge image files with itextsharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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