Zagadnienie scalania PDF w ItextSharp (po scaleniu plików PDF nie zachowują ich wartości)

Próbujemy połączyć trzy pliki PDF za pomocą ITextSharp. Problem po scaleniu możemy uzyskać dane tylko z pierwszego pliku PDF, podczas gdy pozostałe dwa pliki PDF nie zachowują swoich wartości.

Wszystkie te pliki PDF mają tę samą strukturę (tzn. Używają tych samych szablonów z różnymi danymi), więc moim założeniem jest, że mają te same pola (AcroFields), które mogą stwarzać ten problem podczas łączenia.

Oto kod scalający:

public void MergeFiles(string destinationFile, string[] sourceFiles)
    {
        try
        {
            int f = 0;
            string outFile = destinationFile;
            Document document = null;
            PdfCopy writer = null;
            while (f < sourceFiles.Length)
            {
                // Create a reader for a certain document
                PdfReader reader = new PdfReader(sourceFiles[f]);
                // Retrieve the total number of pages
                int n = reader.NumberOfPages;
                //Trace.WriteLine("There are " + n + " pages in " + sourceFiles[f]);
                if (f == 0)
                {
                    // Step 1: Creation of a document-object
                    document = new Document(reader.GetPageSizeWithRotation(1));
                    // Step 2: Create a writer that listens to the document
                    writer = new PdfCopy(document, new FileStream(outFile, FileMode.Create));
                    // Step 3: Open the document
                    document.Open();
                }
                // Step 4: Add content
                PdfImportedPage page;
                for (int i = 0; i < n; )
                {
                    ++i;
                    if (writer != null)
                    {
                        page = writer.GetImportedPage(reader, i);
                        writer.AddPage(page);
                    }
                }

                PRAcroForm form = reader.AcroForm;
                if (form != null)
                {
                    if (writer != null)
                    {
                        writer.CopyAcroForm(reader);
                    }
                }

                f++;
            }
            // Step 5: Close the document
            if (document != null)
            {
                document.Close();
            }
        }
        catch (Exception)
        {
            //handle exception
        }
    }

Nazywa się to następująco:

    string[] sourcenames = { @"D:\1.pdf", @"D:\2.pdf", @"D:\3.pdf" };
    string destinationname = @"D:\pdf\mergeall\merge3.pdf";
    MergeFiles(destinationname, sourcenames);

questionAnswers(1)

yourAnswerToTheQuestion