Click or drag to resize

PdfGeneratedDocumentImportPages Method

Imports pages and associated resources from PDF stream.

Namespace:  Atalasoft.PdfDoc.Generating
Assembly:  Atalasoft.PdfDoc (in Atalasoft.PdfDoc.dll) Version: 11.4.0.9.0.377 (.NET 4.5.2, x86)
Syntax
public void ImportPages(
	Stream stm,
	ImportOptions importOptions = null,
	SecureString userPassword = null,
	SecureString ownerPassword = null
)

Parameters

stm
Type: System.IOStream
importOptions (Optional)
Type: Atalasoft.PdfDoc.MergeFormsImportOptions
Options for importing the PDF document. This parameter may be .
userPassword (Optional)
Type: System.SecuritySecureString
The user password to open the document.
ownerPassword (Optional)
Type: System.SecuritySecureString
The owner password to open the document.
Remarks

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:

  • current field of current form is not changed;
  • all child fields of external field added to children collection of current field.

Examples
Sample for merging fields with same type and renaming fields with different types
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;
}
See Also