PdfGeneratedDocumentImportPages Method |
Namespace: Atalasoft.PdfDoc.Generating
public void ImportPages( Stream stm, ImportOptions importOptions = null, SecureString userPassword = null, SecureString ownerPassword = null )
Imported pages will be added to Pages.
If Form in current document is null and imported document contains form, imported document form will be set in current document form.
If Form in current document is not null and imported document does not contain form, current document form will not change.
If Form in current document is not null and imported document contains form, current document form will not change, but fields will be merged.
On merging fields, fields collections will be compared. If both collections contain fields with equal fully qualified names, FormFieldsConflictHandler will be called to resolve the conflict.
If FormFieldsConflictHandler is not set, by default, all fields with equal fully qualified names and same field types are merged:
public void CombinePdfForms() { using (var stm = File.OpenRead(@"TwoPagesForm.pdf")) using (var genDoc = new PdfGeneratedDocument(stm)) using (var streamForImport = File.OpenRead(@"docWithForms.pdf")) { genDoc.ImportPages(streamForImport, new ImportOptions { FormFieldsConflictHandler = ResolveFormFieldsConflict }); using (var outStm = File.Create("CombinedForm.pdf")) genDoc.Save(outStm); } } private void ResolveFormFieldsConflict(object s, FormFieldsConflictEventArgs a) { if (a.AreFieldTypesEqual) { a.ConflictResolution = FormFieldsConflictResult.KeepCurrentFieldAndMergeChildren; return; } // generate new name for field a.ExternalField.FieldName = "new" + a.ExternalField.FieldName; a.ConflictResolution = FormFieldsConflictResult.KeepBoth; }