Good, I have several pdf with digital signature and when doing the merge does not keep it, I use the following code, which modification I can make to keep it.
Thank you very much
public static void MergeFiles(string destinationFile, string[] sourceFiles, string[] pageName)
{
try
{
int f = 0;
PdfReader reader = new PdfReader(sourceFiles[f]);
int n = reader.NumberOfPages;
Document document = new Document(reader.GetPageSizeWithRotation(1));
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(destinationFile, FileMode.Create));
document.Open();
PdfContentByte cb = writer.DirectContent;
PdfImportedPage page;
int rotation;
int pdfPageName = 0;
bool pdfNewPageFlag = true;
while (f < sourceFiles.Length)
{
int i = 0;
while (i < n)
{
i++;
document.SetPageSize(reader.GetPageSizeWithRotation(i));
document.NewPage();
if (pdfNewPageFlag == true)
{
Chapter chapter = new Chapter(pageName[pdfPageName], pdfPageName + 1);
document.Add(chapter);
pdfNewPageFlag = false;
pdfPageName++;
}
page = writer.GetImportedPage(reader, i);
rotation = reader.GetPageRotation(i);
if (rotation == 90 || rotation == 270)
{
cb.AddTemplate(page, 0, -1f, 1f, 0, 0, reader.GetPageSizeWithRotation(i).Height);
}
else
{
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
}
Console.WriteLine("Processed page " + i);
}
f++;
if (f < sourceFiles.Length)
{
reader = new PdfReader(sourceFiles[f]);
n = reader.NumberOfPages;
Console.WriteLine("There are " + n + " pages in the original file.");
//
pdfNewPageFlag = true;
}
}
document.Close();
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message);
Console.Error.WriteLine(e.StackTrace);
Console.ReadKey();
}
}