Hi all,
I am using a method:
Code:
private void MergeMultiplePDFIntoSinglePDF(string outputFilePath, StudentsFile[] pdfFiles)
{
var outputPdfDocument = new PdfDocument();
var format = new XStringFormat();
format.Alignment = XStringAlignment.Center;
format.LineAlignment = XLineAlignment.Far;
var font = new XFont("Verdana", 10, XFontStyle.Bold);
foreach (var pdfFile in pdfFiles)
{
PdfDocument inputPdfDocument = PdfReader.Open(pdfFile.File, PdfDocumentOpenMode.Import);
outputPdfDocument.Version = inputPdfDocument.Version;
foreach (PdfPage page in inputPdfDocument.Pages)
{
var newPage = outputPdfDocument.Pages.Add(page);
// Write student name on each page
XGraphics gfx = XGraphics.FromPdfPage(newPage);
XRect box = newPage.MediaBox.ToXRect();
box.Inflate(0, -10);
gfx.DrawString(String.Format("{0}", pdfFile.Student),
font, XBrushes.Red, box, format);
}
}
outputPdfDocument.Save(outputFilePath);
}
I send an array of different pdf files but in result I have a first pdf file cloned several times.
I tried many things: AddPage, InsertPage in different ways...
I made sure that files are different and almost broke my head
Pdf Sharp + MigrDoc
Version: 1.32.43334.0 (got from NuGet)
Thank you.