如果我对这个Syntex错了,请纠正我 [英] Can Please Correct Me If I Am Wrong With This Syntex

查看:116
本文介绍了如果我对这个Syntex错了,请纠正我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请检查



  dynamic  AnnotationReferencedPage = PdfReader.GetPdfObject( (PRIndirectReference)AnnotationAction.GetAsArray(PdfName.D).ArrayList( 1 )); 





运行时错误





非可调成员'iTextSharp.text.pdf.PdfArray .ArrayList'不能像方法一样使用







 PdfReader R = 默认(PdfReader); 
int PageCount = 0 ;
PdfDictionary PageDictionary = 默认(PdfDictionary);
PdfArray Annots = 默认(PdfArray);

// '//打开我们的阅读器
R = new PdfReader(BaseFile);
// '//获取页面cont
PageCount = R.NumberOfPages ;

// '//遍历每一页
< span class =code-keyword> for ( int I = 1 ; I < span class =code-keyword>< = PageCount; I ++)
{
// '//获取当前页面
PageDictionary = R.GetPageN(I);

// '//获取当前页面的所有注释
Annots = PageDictionary.GetAsArray(PdfName.ANNOTS);

// '//确保我们有一些东西
if ((Annots == null )||(Annots.Length == 0 ))
继续;

// '//遍历每个注释

foreach object A_loopVariable in Annots.ArrayList)
{
PdfObject A =(PdfObject)A_loopVariable;

// '//我不完全理解这一点,但我认为这会变成间接引用实际对象,但我可能错了
// '//无论如何,将特定于itext的对象转换为通用PDF对象
dynamic AnnotationDictionary =(PdfDictionary)PdfReader.GetPdfObject(A);

// '//确保此注释有链接
if (!AnnotationDictionary.Get(PdfName.SUBTYPE).Equals(PdfName.LINK))
继续;

// '//确保此批注有行动
if (AnnotationDictionary.Get(PdfName.A)== null
继续;

// '//获取当前注释的动作
dynamic AnnotationAction = AnnotationDictionary.GetAsDict(PdfName.A);

// '//测试它是否是命名操作,例如/ FIRST,/最后等等
如果(AnnotationAction.Get(PdfName.S).Equals(PdfName.NAMED))
{
Trace.Write( GOTO:);
if (AnnotationAction.Get(PdfName.N).Equals(PdfName.FIRSTPAGE))
{
Trace.WriteLine(< span class =code-digit> 1
);
}
else if (AnnotationAction.Get(PdfName.N).Equals (PdfName.NEXTPAGE))
{
Trace.WriteLine(Math.Min(I + 1 ,PageCount));
// '//任何超出文档末尾的链接都应该转到最后一页
}
else if (AnnotationAction.Get(PdfName。 N).Equals(PdfName.LASTPAGE))
{
Trace.WriteLine(PageCount);
}
else if (AnnotationAction.Get(PdfName.N).Equals (PdfName.PREVPAGE))
{
Trace.WriteLine(Math.Max(I - 1 1 ));
// '//在第一页应该转到第一页之前的任何链接
}


// '//否则请参阅如果它是一个GOTO页面动作

}
// 这里我发现有一些动作
其他 如果(AnnotationAction) .Get(PdfName.S)。Equals(PdfName.GOTO))
{
// '//确保它有一个目的地
if (AnnotationAction.GetAsArray(PdfName.D)== null
继续;




// '//AnnotationAction.GetAsArray(PdfName.D)获取目的地
// '/ /AnnotationAction.GetAsArray(PdfName.D).ArrayList(0)获取目标的间接引用部分(.ArrayList(1)具有拟合选项)
// '// DirectCast(AnnotationAction.GetAsArray(PdfName.D).ArrayList(0),PRIndirectReference)将其转换为PRIndirectReference
// '//整行获取实际页面对象(实际上我认为它可以是任何类型的pdf对象但我没有测试过。)
// '// BIG NOTE:此行REA应该有更多的健全性检查

动态 AnnotationReferencedPage = PdfReader.GetPdfObject((PRIndirectReference)AnnotationAction .GetAsArray(PdfName.D).ArrayList( 0 ));
Trace.Write( GOTO:);
// '//重新循环主文档中的所有页面,将它们与此页面进行比较
for int J = 1 ; J < = PageCount; J ++)
{
if (AnnotationReferencedPage.Equals(R.GetPageN(J)))
{

Trace.WriteLine(J);
break ; // TODO:可能不正确。是:退出
}
}
}

解决方案

  public  List< PdfObject> ArrayList {
get {
return arrayList;
}
}



iTextSharp 的源代码中可以看出 ArratList PdfObjects 的列表,而不是真正的数组 - 肯定不是方法。

To了解列表< t>< / t> ,请点击此处 - http://msdn.microsoft.com/en-us/library/6sh2ey19(v = vs.110).aspx [ ^ ]

要遍历所有引用,请尝试这个

 List< PdfObject> ArrayList = AnnotationAction.GetAsArray(PdfName.D).ArrayList; 
foreach (PdfObject oAnnot in ArrayList)
{
// 在原始文档中找到页面......或者您想要的任何内容......
}


Please check

dynamic AnnotationReferencedPage = PdfReader.GetPdfObject((PRIndirectReference)AnnotationAction.GetAsArray(PdfName.D).ArrayList(1));



Run Time Error


Non-invocable member 'iTextSharp.text.pdf.PdfArray.ArrayList' cannot be used like a method




PdfReader R = default(PdfReader);
            int PageCount = 0;
            PdfDictionary PageDictionary = default(PdfDictionary);
            PdfArray Annots = default(PdfArray);

            //'//Open our reader
            R = new PdfReader(BaseFile);
            //'//Get the page cont
            PageCount = R.NumberOfPages;

            //'//Loop through each page
            for (int I = 1; I <= PageCount; I++)
            {
                //'//Get the current page
                PageDictionary = R.GetPageN(I);

                //'//Get all of the annotations for the current page
                Annots = PageDictionary.GetAsArray(PdfName.ANNOTS);

                //'//Make sure we have something
                if ((Annots == null) || (Annots.Length == 0))
                    continue;

                //'//Loop through each annotation

                foreach (object A_loopVariable in Annots.ArrayList)
                {
                    PdfObject A = (PdfObject)A_loopVariable;
                    
                    //'//I do not completely understand this but I think this turns an Indirect Reference into an actual object, but I could be wrong
                    //'//Anyway, convert the itext-specific object as a generic PDF object
                    dynamic AnnotationDictionary = (PdfDictionary)PdfReader.GetPdfObject(A);

                    //'//Make sure this annotation has a link
                    if (!AnnotationDictionary.Get(PdfName.SUBTYPE).Equals(PdfName.LINK))
                        continue;

                    //'//Make sure this annotation has an ACTION
                    if (AnnotationDictionary.Get(PdfName.A) == null)
                        continue;

                    //'//Get the ACTION for the current annotation
                    dynamic AnnotationAction = AnnotationDictionary.GetAsDict(PdfName.A);

                    //'//Test if it is a named actions such as /FIRST, /LAST, etc
                    if (AnnotationAction.Get(PdfName.S).Equals(PdfName.NAMED))
                    {
                        Trace.Write("GOTO:");
                        if (AnnotationAction.Get(PdfName.N).Equals(PdfName.FIRSTPAGE))
                        {
                            Trace.WriteLine(1);
                        }
                        else if (AnnotationAction.Get(PdfName.N).Equals(PdfName.NEXTPAGE))
                        {
                            Trace.WriteLine(Math.Min(I + 1, PageCount));
                            //'//Any links that go past the end of the document should just go to the last page
                        }
                        else if (AnnotationAction.Get(PdfName.N).Equals(PdfName.LASTPAGE))
                        {
                            Trace.WriteLine(PageCount);
                        }
                        else if (AnnotationAction.Get(PdfName.N).Equals(PdfName.PREVPAGE))
                        {
                            Trace.WriteLine(Math.Max(I - 1, 1));
                            //'//Any links the go before the first page should just go to the first page
                        }


                        //'//Otherwise see if its a GOTO page action

                    }
// Here I am finding that has some action 
                    else if (AnnotationAction.Get(PdfName.S).Equals(PdfName.GOTO))
                    {
                        //'//Make sure that it has a destination
                        if (AnnotationAction.GetAsArray(PdfName.D) == null)
                            continue;




                        //'//AnnotationAction.GetAsArray(PdfName.D) gets the destination
                        //'//AnnotationAction.GetAsArray(PdfName.D).ArrayList(0) get the indirect reference part of the destination (.ArrayList(1) has fitting options)
                        //'//DirectCast(AnnotationAction.GetAsArray(PdfName.D).ArrayList(0), PRIndirectReference) turns it into a PRIndirectReference
                        //'//The full line gets us an actual page object (actually I think it could be any type of pdf object but I have not tested that).
                        //'//BIG NOTE: This line really should have a bunch more sanity checks in place
                        
                        dynamic AnnotationReferencedPage = PdfReader.GetPdfObject((PRIndirectReference)AnnotationAction.GetAsArray(PdfName.D).ArrayList(0));
                        Trace.Write("GOTO:");
                        //'//Re-loop through all of the pages in the main document comparing them to this page
                        for (int J = 1; J <= PageCount; J++)
                        {
                            if (AnnotationReferencedPage.Equals(R.GetPageN(J)))
                            {
                                
                                Trace.WriteLine(J);
                                break; // TODO: might not be correct. Was : Exit For
                            }
                        }
                    }

解决方案

public List<PdfObject> ArrayList {
       get {
           return arrayList;
       }
}


From the source code of iTextSharp it's clear that ArratList is a List of PdfObjects and not really an array - for sure not a method.
To learn about List<t></t>, read here - http://msdn.microsoft.com/en-us/library/6sh2ey19(v=vs.110).aspx[^]
To loop over all the references try this

List<PdfObject> ArrayList = AnnotationAction.GetAsArray(PdfName.D).ArrayList;
foreach(PdfObject oAnnot in ArrayList)
{
  // find the page in original document...or whatever you want...
}


这篇关于如果我对这个Syntex错了,请纠正我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆