Issue concatenating documents

Questions, comments and suggestions concerning VintaSoft PDF .NET Plug-in.

Moderator: Alex

Post Reply
Posts: 56
Joined: Mon Dec 02, 2019 11:19 pm

Issue concatenating documents

Post by IntegraMike »

Hello, we are trying to convert some functionality from another library over to your library so we can consolidate all of our PDF processing to one toolkit. One of the things we do is combine 2 documents and then update the form field names so that matching names on the second document are renamed. This prevents us from automatically updating information on documents that were added if we re-fill the fields on the parent document.

Unfortunately, when calling AddDocument the InteractiveForm (specifically InteractiveForm.Fields) in the parent document is not updated. I found a workaround for this using an image viewer, adding the child pages and calling SaveSync after each document is concatenated, but we're doing this as a batch process in the background and it's too slow for production. Is there something we can do to get the InteractiveForm to update after calling AddDocument.

Rough Example Code off the top of my head:

Code: Select all

private void ConcatenateDocuments(string parentDocumentPath, List<string> childDocumentPaths)
    PdfDocument parentDocument = new PdfDocument(parentDocumentPath);

    foreach (string childDocumentPath in childDocumentPaths)
        PdfDocument childDocument = new PdfDocument(childDocumentPath);
        foreach (FormField field in childDocument.InteractiveForm.Fields)
        	// The problem happens here because the parentDocument.InteractiveForm does not get updated when we
        	// add the second document, so the check doesn't behave when the third document and on are added.
                if (parentDocument.InteractiveForm.Fields.Contains(e => e.Name == field.Name))
                	// Rename the child fields before adding them. Note that what we're doing is a little more complicated
                	// than this because we need to make sure the renamed value doesn't exist in the parent as well, but
                	// this is close enough to explain what we're trying to do. If _?2 exists, we use _?3 and so on.
                	field.Name = field.Name + _?2;
Any guidance you can offer us would be greatly appreciated.

Posts: 64
Joined: Wed Jul 23, 2008 2:47 pm

Re: Issue concatenating documents

Post by Yuri »

Hello Mike,

To concatenate documents with interactive form you should use Vintasoft.Imaging.Pdf.Processing.PdfDocumentCopyCommand class.

This command allows to set the interactive form fields container (field group), where the interactive form field tree from target PDF document must be added to the source PDF document (Vintasoft.Imaging.Pdf.Processing.PdfDocumentCopyCommand.SetInteractiveFormFieldsContainer(string)).

Please see an example in documentation: ... mmand.html
Post Reply