Pourquoi la référence d'Objet n'est pas définie à une instance d'un objet à l'erreur lors de la fusion des fichiers?

J'ai utilisé cette méthode pour fusionner deux fichiers.

private static string AppendToDocument(string FirstSource, string SecondSource, string NewFileName)
        {

            try
            {
                String first_source = FirstSource;
                String second_source = SecondSource;
                String pathout = NewFileName;

                PdfReader reader = new PdfReader(first_source);
                PdfReader reader1 = new PdfReader(second_source);
                PdfStamper stamper = new PdfStamper(reader1, new FileStream(pathout, FileMode.Create));

                PdfImportedPage page = stamper.GetImportedPage(reader, 1);

                stamper.InsertPage(2, reader.GetPageSizeWithRotation(2));

                PdfContentByte pb = stamper.GetUnderContent(2);
                pb.AddTemplate(page, 0, 0);

                stamper.Close();

                return pathout;
            }
            catch (Exception ex)
            {

                throw ex;
            }

}

Mais il déclenche une erreur à

 stamper.InsertPage(2, reader.GetPageSizeWithRotation(2));

Erreur: Objet de référence non définie à une instance d'un objet.

FirstSource= "E:\\E Drive\\Files\\Projects- 22 Jul 2019\\FilesNew\\Projects.UI\\Downloads\\Certificates\\CoverLetter17Sep2019104850.pdf"

SecondSource= E:\\E Drive\\Files\\Projects- 22 Jul 2019\\FilesNew\\Projects.UI\\Downloads\\Certificates\\38-Tank Lorry Report-VISP-ISB-R-1104-0218-38 (GLT-9275).pdf

NewFileName= "E:\\E Drive\\Files\\Projects- 22 Jul 2019\\FilesNew\\Projects.UI\\Downloads\\Certificates\\InspectionReport17Sep2019104857.pdf"

Trace De La Pile:

?stamper.GetType()

Trace:

{Name = "PdfStamper" FullName = "iTextSharp.text.pdf.PdfStamper"}
    [System.RuntimeType]: {Name = "PdfStamper" FullName = "iTextSharp.text.pdf.PdfStamper"}
    base: {Name = "PdfStamper" FullName = "iTextSharp.text.pdf.PdfStamper"}
    Assembly: {itextsharp, Version=5.5.13.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca}
    AssemblyQualifiedName: "iTextSharp.text.pdf.PdfStamper, itextsharp, Version=5.5.13.0, Culture=neutral, PublicKeyToken=8354ae6d2174ddca"
    Attributes: Public | BeforeFieldInit
    BaseType: {Name = "Object" FullName = "System.Object"}
    ContainsGenericParameters: false
    DeclaringMethod: 'stamper.GetType().DeclaringMethod' threw an exception of type 'System.InvalidOperationException'
    DeclaringType: null
    FullName: "iTextSharp.text.pdf.PdfStamper"
    GenericParameterAttributes: 'stamper.GetType().GenericParameterAttributes' threw an exception of type 'System.InvalidOperationException'
    GenericParameterPosition: 'stamper.GetType().GenericParameterPosition' threw an exception of type 'System.InvalidOperationException'
    GenericTypeArguments: {System.Type[0]}
    GUID: {ffa1f650-fa63-3f85-94a9-ffd899355047}
    HasElementType: false
    IsAbstract: false
    IsAnsiClass: true
    IsArray: false
    IsAutoClass: false
    IsAutoLayout: true
    IsByRef: false
    IsClass: true
    IsCOMObject: false
    IsConstructedGenericType: false
    IsContextful: false
    IsEnum: false
    IsExplicitLayout: false
    IsGenericParameter: false
    IsGenericType: false
    IsGenericTypeDefinition: false
    IsImport: false
    IsInterface: false
    IsLayoutSequential: false
    IsMarshalByRef: false
    IsNested: false
    IsNestedAssembly: false
    IsNestedFamANDAssem: false
    IsNestedFamily: false
    IsNestedFamORAssem: false
    IsNestedPrivate: false
    IsNestedPublic: false
    IsNotPublic: false
    IsPointer: false
    IsPrimitive: false
    IsPublic: true
    IsSealed: false
    IsSecurityCritical: false
    IsSecuritySafeCritical: false
    IsSecurityTransparent: true
    IsSerializable: false
    IsSpecialName: false
    IsUnicodeClass: false
    IsValueType: false
    IsVisible: true
    MemberType: TypeInfo
    Module: {itextsharp.dll}
    Namespace: "iTextSharp.text.pdf"
    ReflectedType: null
    StructLayoutAttribute: {System.Runtime.InteropServices.StructLayoutAttribute}
    TypeHandle: {System.RuntimeTypeHandle}
    TypeInitializer: null
    UnderlyingSystemType: {Name = "PdfStamper" FullName = "iTextSharp.text.pdf.PdfStamper"}

Mise à jour: j'ai updatd la Trace de la pile comme demandé. De bien vouloir vérifier. C'est pour ?stamper.GetType(). J'ai essayé de faire, mais coulnd pas.

Mise à jour:

'reader.GetPageSizeWithRotation(2)' a déclenché une exception de type 'System.NullReferenceException'

-1
2019-09-17 08:49:20
source
0 réponses

Voir d'autres questions sur les étiquettes