How to not lose notes added to PDF when merging PDF's with PDFSharp

Viewed 122

I am using PDFSharp to merge multiple PDF documents saved on temp and network locations to then print them as one single task. But it has come to my attention that when a PDF has some notes added to it that they become lost after the merge.

I am using the following Method's to merge the PDF's. (input is a list with file locations.)

public string CombinePdf(List<string> files)
{
    PdfDocument outDoc = new PdfDocument();

    foreach(string file in files)
    {
        using (PdfDocument pdfDocument = PdfReader.Open(FormatPath(file), PdfDocumentOpenMode.Import, PdfReadAccuracy.Strict))
        {
            CopyPages(pdfDocument, outDoc);
        }
    }

    string outPdfFileName = $"{Guid.NewGuid()}.pdf";
    string outPdfPath = Path.Combine(Path.GetTempPath(), outPdfFileName);

    outDoc.Save(outPdfPath);

    return outPdfPath;
}

private void CopyPages(PdfDocument from, PdfDocument to)
{
    for (int i = 0; i < from.PageCount; i++)
    {
        to.AddPage(from.Pages[i]);
    }
}
0 Answers
Related