C#でitext7を使って、inkannotationを作りたいです

タグの編集
投稿者 snowmansnow  (社会人) 投稿日時 2022/8/16 21:07:40
こんばんは、
 C# について、質問させて頂きたいです
  visualstudio2019で、nugetからitext7をインストールしています。
  クラスライブラリを作って、anycpu対象で、excel2016(32bit)から動かしています。

  他のアノテーションはなんとか動くのですが、インクアノテーションが動きません
   (下記★2行を取り換えると、ラインは動いてインクが動かない状態です。)

  
using System;
using iText.Kernel.Colors;
using iText.Kernel.Pdf;
using iText.Kernel.Geom;
using System.Runtime.InteropServices;
using iText.Layout;
using System.Collections.Generic;
using iText.Kernel.Pdf.Annot;

namespace ClassLibraryCS4_itext7Annotation01
{

    [Guid(InkAnno01.ClassId)]

        public class InkAnno01
        {
            //  COM用のGUID値
            public const string ClassId = "546A61CE-0FE4-4748-8561-2F87635896E4";

        public string MarginValue(string src, string dest, int p)
        {

            //Initialize PDF document
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
        
            //Creating a Document
            Document document = new Document(pdfDoc);

            //Creating a PdfPage
            PdfPage page = pdfDoc.GetPage(p);


            //creating PdfInkAnnotation object
            Rectangle rect = new Rectangle(105, 790, 64, 10);

            float[] floatArray = new float[] { 40, 300, 60, 100, 90, 50, 140, 300 };

            //PdfArray inklist = new PdfArray(floatArray);
            PdfArray inklist = new PdfArray(new float[]  { 40, 300, 60, 100, 90, 50, 140, 300 });
 
            PdfInkAnnotation annotation = new PdfInkAnnotation(rect,inklist);
            //PdfLineAnnotation annotation = new PdfLineAnnotation(rect, floatArray);
            //★★ここを上下取り換えるとラインアノテーションでは、動きます
      //inklistの代入がおかしいのでは?と思っています

            // Set arrow's border style 
            PdfDictionary borderStyle = new PdfDictionary();
            borderStyle.Put(PdfName.S, PdfName.S);
            borderStyle.Put(PdfName.W, new PdfNumber(5));
            annotation.SetBorderStyle(borderStyle);

            //Setting color of the PdfInkAnnotation
            annotation.SetColor(new DeviceRgb(0xf8, 0x9b, 0x22));

            //Setting title to the PdfInkAnnotation
            annotation.SetTitle(new PdfString("iText"));

            //Setting name to the PdfInkAnnotation
            annotation.SetName(new PdfString("myInk2"));

            //Setting contents of the PdfInkAnnotation
            annotation.SetContents("Hi");

            //Adding annotation to the page
            page.AddAnnotation(annotation);
            //Closing the document
            document.Close();

                return "done";
            }
        }
    }

以前に面倒見たもらった、inkpictureのstrokeに似てる気がするのですが、
どこを直したら良いのかわからず、お聞きしたいです。
VBではないのですが、宜しくお願いします。


投稿者 snowmansnow  (社会人) 投稿日時 2022/8/17 21:28:49

 こんばんは、
  クラスライブラリなので、呼び出しVBAがあります。
 
Sub GetHelloAnnotation()
 
  Dim wp2 As New InkAnno01
 
  Dim html As String
  Dim SRC As String
  Dim DES As String
  Dim page As Integer
  page = 4
  '追加するページ。(1が1ページ) 
  SRC = "C:\ほげほげ\元の.PDF"
  DES = "C:\ほげほげ\追加した.PDF"
  html = wp2.MarginValue(SRC, DES, page)
  MsgBox html
  
End Sub

です。よろしくお願いします。
投稿者 snowmansnow  (社会人) 投稿日時 2022/8/28 15:42:11

 こんにちは、
   誰もかまってくれなかったので、独学で試行錯誤しました。

using System;
using System.Windows.Forms;
using iText.Kernel.Colors;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Annot;
using Rectangle = iText.Kernel.Geom.Rectangle;

namespace WindowsFormsApp_PdfInkAnnoCS
{
    public partial class Form1Line11 : Form
    {
        public Form1Line11()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            String SRC = "C:/ほげほげ/元.PDF";

            String DEST = "C:/ほげほげ/追加.PDF";

            int p = 1;
            //Initialize PDF document
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST));

                //Creating a PdfPage
                PdfPage page = pdfDoc.GetPage(p);

                //creating PdfLineAnnotation object
                Rectangle rect = new Rectangle(0, 0, 0, 0);

            float[][] inklist = new float[8][];
            inklist[0] = new float[2];                 
            inklist[1] = new float[2];                 
            inklist[2] = new float[2];
            inklist[3] = new float[2];
            inklist[4] = new float[2];
            inklist[5] = new float[2];
            inklist[6] = new float[2];
            inklist[7] = new float[2];
            inklist[0][0] = 100;                     
            inklist[0][1] = 0;                    
            inklist[1][0] = 130;                     
            inklist[1][1] = 30;                    
            inklist[2][0] = 50;                    
            inklist[2][1] = 50;                    
            inklist[3][0] = 70;                   
            inklist[3][1] = 70;
            inklist[4][0] = 100;
            inklist[4][1] = 100;
            inklist[5][0] = 240;
            inklist[5][1] = 200;
            inklist[6][0] = 70;
            inklist[6][1] = 200;
            inklist[7][0] = 100;
            inklist[7][1] = 0;

            PdfArray outer = new PdfArray();
            PdfArray inner = new PdfArray();

            for (int k = 0; k < inklist.Length; ++k)
            {
                float[] deep = inklist[k];
                for (int j = 0; j < deep.Length; ++j)
                {
                    inner.Add(new PdfNumber(deep[j]));
                }
               
            }
            outer.Add(inner);
            //dummy
            outer.Add(inner);

            PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rect, outer);

            // Set arrow's border style 
            PdfDictionary borderStyle = new PdfDictionary();
                borderStyle.Put(PdfName.S, PdfName.S);
                borderStyle.Put(PdfName.W, new PdfNumber(3));
                inkAnnotation.SetBorderStyle(borderStyle);

                //Setting color of the PdfLineAnnotation
                inkAnnotation.SetColor(ColorConstants.RED);

                //Setting title to the PdfLineAnnotation
                inkAnnotation.SetTitle(new PdfString("iText"));

                //Setting contents of the PdfLineAnnotation
                inkAnnotation.SetContents("Hi welcome to finddevguides");

                //Adding annotation to the page
                page.AddAnnotation(inkAnnotation);

            //Closing the document
            pdfDoc.Close();

            }
        }
    }


フォームアプリケーションです。
一応動きます。
一人はつらいです。また宜しくお願いします。

投稿者 るきお  (社会人) 投稿日時 2022/8/28 21:24:33
こんにちは。

> 一人はつらいです。また宜しくお願いします。
ちょっとニッチなのですよね。アドバイスできる人がとても少ないことをやっていると思います。

> 他のアノテーションはなんとか動くのですが、インクアノテーションが動きません
ご質問が「インクアノテーション」が何か知っていることが前提になっていますよね。
これで、もうほどんトの人が脱落します。

本文には PDF を編集しようとしているという情報も記載されていませんね。
記載してもわかる人は少ないと思いますが。

> 動きません
この「動きません」という表現も曲者で、
エラーが出るのでるのか、エラーは出ないけど想定と結果が異なるのかがわかりません。

想定と結果が異なる場合はさらに面倒で、それならば「想定」は何で、「結果」は何なのかが読み取れません。

つまり、PDF のインクアノテーションのことを知っていて、C#で iText の知識がある人が、「動かない」とはどういう状況か推理したり、会話したりしないとアドバイスできないわけです。

実は私はインクアノテーションというものを知らなかったので、少し調べて、ご提示のプログラムを動かしてみました。少しいじったかもしれません。やってみると、アノテーション自体は追加されたようですが、PDFのページ上には何も変化がない状態でした。インクアノテーションを知らないので、本来はどのような状態が正なのかわかりませんでした。名前からすると何かインクでお絵描きのようなグラフィックが追加されるのかなと推測して、調べてみましたが、結局解決できなかったので回答には至りませんでした。

一方、うまくうごかないプログラムを掲載していただいている点はとてもよかったです。これがあるので私も実際に試してみることができました。ただ、引数の src と dest に何を指定すればよいか最初わからなかったので呼び出しれもあるとなおよかったです。

今後も、PDFやiTextの分野では回答できる人はほとんどいないと思いますが、プログラム例を載せたり、何をやろうとしているのか、「動かない」という表現をもっと具体化するなどすると多少は回答が付きやすくなるかもしれません。
投稿者 るきお  (社会人) 投稿日時 2022/8/28 21:27:45
そうえいば、VBAでCOMとして呼び出そうとしているところもニッチですね。これも回答率が下がる要因になりそうです。

今回はVBAやCOMのところで悩んでいるわけではないと思うので、純粋に C# だけで動作確認できるプログラムを作って、それを投稿した方が良かったと思います。
投稿者 snowmansnow  (社会人) 投稿日時 2022/8/28 22:04:00

 こんばんは、るきお様
  お返事ありがとうございます

  JAVASCRIPTやVBAやC#など、いろいろ出来る事を試して、煮詰まっていたので、
  質問の仕方が悪くて申し訳ございません。

  動かない表現も、稚拙で申し訳ございません。
  PDFで、「手書きのメモのようなもの(インクアノテーション)」をマウスなどで書き込めるのですが、
  るきお様のVB中学校で、魔界の仮面弁士様に教えてもらったinkpictureのように、プログラムで
  既存のインクアノテーションを変更したり、新規に描画したかったです。
  用紙を縮小すると、FLATTENという命令でアノテーションをベタ画像に変換しなくてはならないので、
  そうではなく、アノテーションも縮小して、再描画したいという目的も重ねてありました。
  
  ますは、新規で描画しようと思ったのですが、仲間の、「線の(ラインアノテーション)」は描画できる
  ようでしたが、インクアノテーションは、なにも描画されず、その件が「動かない」という表現に
  なったと思います。

  ラインアノテーションは、配列を代入しますが、インクアノテーションはPDFARRAYという
  専用の配列?を代入しなくてはならず、その次元管理方法が不明でしたので、
  そこが原因なのでは?と推測していました。

  VBAが好きなので、C#やVB.NETを使うときも、クラスライブラリを多用するのは、私の好みで、
  御教授頂く時に、自分の好みを押し付けて申し訳ございません。回答がつかなかったので、
  少し、自分でも気になりましたので、今回はフォームアプリケーションに変更させて頂きました。

  itextもJAVA時代から好んで使っていたので、itext7のdotnet版をそのまま使っていました。
  掲示板でも特殊なアプリの話をしてるように見える時がございましたので、ここの掲示板で
  C#関係のアプリの御教授をいただければ、と思いました。

  PDFを画像にする話は、魔界の仮面弁士様に面倒見てもらいましたし、itextも、C#の文法の話なら
  御教授いただけるかもしれないので、懲りずに、また質問させて頂くかもしれません。
  
  つたない質問やプログラムを、試して下さる労力と時間に足しになるように頑張りますので、
  また、御教授、御返事お願いします。

  PDFARRAYの次元管理は、配列をまとめてADDする事を組み合わせる事で可能だったので、
  今回の動くプログラムになりました。

  検索エンジンで、インクアノテーションの加工に興味ある方が辿り着けて、参考になるといいな、
  と思います。

  こんな感じでした。また宜しくお願いします。


















投稿者 snowmansnow  (社会人) 投稿日時 2022/9/1 21:40:28

 こんばんは、検索でたどり着いた方用に
 あるPDFのアノテーションを他のPDFに平行移動する例を載せます。
 試作品なので、状況によってはエラーがでるかもしれません
 良かったら見てみてください
using System;
using System.Windows.Forms;
using iText.Kernel.Pdf;
using iText.Kernel.Colors;
using iText.Kernel.Pdf.Annot;
using Rectangle = iText.Kernel.Geom.Rectangle;

namespace WindowsFormsApp_PdfInkAnnoCS
{
    public partial class Form1Line31 : Form
    {
        public Form1Line31()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            String SRC = "C:ほげほげ/平行移動の元.PDF";
            int p = 1;
            PdfDocument pdfDoc3 = new PdfDocument(new PdfReader(SRC));
            PdfPage page2 = pdfDoc3.GetPage(p);
            PdfDictionary pageDict = page2.GetPdfObject();
            PdfArray annots = pageDict.GetAsArray(PdfName.Annots);
            if (annots != null)
            {
                for (int i = 0; i < annots.Size(); i++)
                {
                    PdfDictionary annodic = annots.GetAsDictionary(i);
                    changeDict(annodic, PdfName.InkList);
                }
            }
            pdfDoc3.Close();
        }
        public void changeDict(PdfDictionary annodic2, PdfName CNAME)
        {
            if (annodic2 == null)
            {
                return;
            }
            changeInk(annodic2, annodic2.GetAsArray(CNAME));
        }
        public void changeInk(PdfDictionary annodic3, PdfArray array)
        {
            if (array == null)
            {
                return;
            }
            PdfArray annodicRect = annodic3.GetAsArray(PdfName.InkList);
            PdfArray outer = new PdfArray();
            for (int k = 0; k < annodicRect.Size(); ++k)
            {
                PdfArray inner = new PdfArray();
                PdfArray inner2 = annodicRect.GetAsArray(0);
                for (int j = 0; j < inner2.Size(); ++j)
                {
                    inner.Add(new PdfNumber((inner2.GetAsNumber(j).FloatValue() + (float)120.0)));
                }
                outer.Add(inner);
                //outer.Add(inner);
            }
            String SRC2 = "C:/ほげほげ/平行移動先.PDF";
            String DEST2 = "C:/ほげほげ/平行移動結果.PDF";
            int p2 = 1;
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC2), new PdfWriter(DEST2));
            PdfPage page = pdfDoc.GetPage(p2);
            Rectangle rect = new Rectangle(0, 0, 0, 0);
            PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rect, outer);
            // Set arrow's border style 
            PdfDictionary borderStyle = new PdfDictionary();
            borderStyle.Put(PdfName.S, PdfName.S);
            borderStyle.Put(PdfName.W, new PdfNumber(3));
            inkAnnotation.SetBorderStyle(borderStyle);
            inkAnnotation.SetColor(ColorConstants.RED);
            inkAnnotation.SetTitle(new PdfString("iText"));
            inkAnnotation.SetContents("Hi welcome");
            page.AddAnnotation(inkAnnotation);
            pdfDoc.Close();
        }
    }
}
投稿者 魔界の仮面弁士  (社会人) 投稿日時 2022/9/2 13:42:15
> String SRC = "C:ほげほげ/平行移動の元.PDF";
C:\AAA\BBB.PDF と
C:AAA\BBB.PDF は、
必ずしも同じファイルを意味するものではありません。

(PDFReader クラスが、それらを同じパスとして扱うかどうかは把握していませんが)

Directory.SetCurrentDirectory(@"C:\");
Directory.CreateDirectory(@"C:\はげ\");
Directory.CreateDirectory(@"C:\まげ\");
Directory.CreateDirectory(@"C:\まげ\はげ\");
File.WriteAllText(@"C:\はげ\ひげ.TXT""100");
File.WriteAllText(@"C:\まげ\はげ\ひげ.TXT""200");

Directory.SetCurrentDirectory(@"C:\まげ");
string s1 = File.ReadAllText(@"C:はげ\ひげ.TXT");   // 200
string s2 = File.ReadAllText(@"C:\はげ\ひげ.TXT");  // 100
投稿者 snowmansnow  (社会人) 投稿日時 2022/9/2 20:24:02

 こんばんは、魔界の仮面弁士様
  るきお様とともに、いつもありがとうございます。元気でます。

  ごめんなさい
   String SRC = "C:ほげほげ/平行移動の元.PDF";は

   String SRC = "C:/ほげほげ/平行移動の元.PDF";の間違いです。
   手で直したので、間違いました。皆さんごめんなさい。

   nullエラーを回避するのに、サブルーチンで回避するやり方しかできませんで、
   似たような2重の回避になってしまいました・・・
   何か、別の回避はございますでしょうか?

   煮詰まり続けてたので、希望通り動く事を目標に、頑張りました。
   実用化には、ほど遠いのですが、がんばります。

   

投稿者 snowmansnow  (社会人) 投稿日時 2022/10/5 22:02:45

 こんばんは
 http://hanatyan.sakura.ne.jp/logbbs1/wforum.cgi?mode=allread&no=7969&page=0
 https://learn.microsoft.com/ja-jp/dotnet/api/system.runtime.interopservices.varenum?redirectedfrom=MSDN&view=net-6.0
 を参考に、
 Double配列をExcelのVBA(Excel2016 32bit)からC#のクラスライブラリに渡して、
 inkアノテーションを描画する例が出来ました。
 でも、同時にSRCやDESTのStringも一緒に渡すやり方がわかりません。
 教えて頂けるとありがたいです。
 rucio様に、クラスライブラリや、itextだと回答が付きづらいとアドバイス頂いたのですが、宜しくお願いしたいです。
 複数渡しのインターフェース?が良くわかりません。  


  VBAは
 
  Sub GetInkDouble()
  Dim HogeIF As ClassLibrary1_ink_CL.IHogehoge2
  Set HogeIF = New ClassLibrary1_ink_CL.Hogehoge2
  Dim d(5) As Double
  d(0) = 10.5
  d(1) = 300.5
  d(2) = 50.78
  d(3) = 60.66
  d(4) = 160.66
  d(5) = 260.66
  Call HogeIF.HogeMethod2(d)
  End Sub
  


 C#のクラスライブラリは、
 
using System;
using System.Runtime.InteropServices;
using iText.Kernel.Colors;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Annot;
using Rectangle = iText.Kernel.Geom.Rectangle;

namespace ClassLibrary1_ink_CL
{
    //http://hanatyan.sakura.ne.jp/logbbs1/wforum.cgi?mode=allread&no=7969&page=0

    [Guid("CEAB527D-54CB-4758-A62E-47E01951C94A")]
    public interface IHogehoge2
    {
        void HogeMethod2(
            [MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_R8)]
            ref Double[] array);
    }

    [Guid("37B5CF9B-81EF-4BAA-80C2-EB9CA27816AF")]
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("ClassLibrary1_ink_CL.Hogehoge.1")]
    public class Hogehoge2 : IHogehoge2
    {
        /// <summary>配列の各要素を、それぞれ倍の値にします。</summary>
        /// <param name="array">byteの1次元配列</param>
        public void HogeMethod2(ref Double[] array)
        {
            String SRC = "C:/ほげほげ/読み込む.PDF";

            String DEST = "C:/ほげほげ/書き出す.PDF";

            int p = 1;
            //Initialize PDF document
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST));

            //Creating a PdfPage
            PdfPage page = pdfDoc.GetPage(p);

            //creating PdfLineAnnotation object
            Rectangle rect = new Rectangle(0, 0, 0, 0);

            PdfArray outer = new PdfArray();
            PdfArray inner = new PdfArray();

            for (int k = 0; k < array.Length; ++k)
            {
              inner.Add(new PdfNumber(array[k]));
            }
            outer.Add(inner);
            //dummy
            outer.Add(inner);

            PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rect, outer);

            // Set arrow's border style 
            PdfDictionary borderStyle = new PdfDictionary();
            borderStyle.Put(PdfName.S, PdfName.S);
            borderStyle.Put(PdfName.W, new PdfNumber(3));
            inkAnnotation.SetBorderStyle(borderStyle);

            //Setting color of the PdfLineAnnotation
            inkAnnotation.SetColor(ColorConstants.RED);

            //Setting title to the PdfLineAnnotation
            inkAnnotation.SetTitle(new PdfString("iText"));

            //Setting contents of the PdfLineAnnotation
            inkAnnotation.SetContents("Hi welcome to finddevguides");

            //Adding annotation to the page
            page.AddAnnotation(inkAnnotation);

            //Closing the document
            pdfDoc.Close();
        }
    }
}

  
 
 です。
   宜しくお願いします。

投稿者 るきお  (社会人) 投稿日時 2022/10/8 10:50:24
こんにちは。

過去のやりとりに、追加で質問するのではなく、新しく投稿することをお勧めします。
コンテキスト(状況)に依存した書き込みは回答しにくいのです。

コンテキストに依存した書き込みの例
・先日の件ですが… (→先日の件を知っていないと回答しにくい)
・この前の○○プログラムで追加で質問です。→(この前の○○プログラムを知っていないと回答しにくい)


なぜ、コンテキストに依存した書き込みは回答しにくいかというと、過去のコンテキストを理解してから、ご質問を検討する必要があるからです。
もしかすると、理解する必要はないのかもしれませんが、それでも「先日の件です」のように書かれていると、理解する必要があるように思ってしまします。

多くの回答者は無償でアドバイスするので、回答に時間がかかりそうな質問はスルーするかよくても後回しします。

このようなことは質問者と回答者の両方に利益がないので、コンテキストに依存しないことを強くお勧めします。

ちなみに、私は1週間くらいたつと私が回答・コメントしたご質問でも内容はほとんど忘れています…。

今回のご質問はさらに、iTextなどが使われていて、余計に回答を付きづらくしています。
iTextと直接関係がない質問であれば、iTextを使わない標準の機能だけで質問したほうが良いです。

このように機能を切り分けることは、問題解決やデバッグの基本です。難しい問題をできるだけシンプルな問題に分割して個別に解決していきます。この過程で、理解が深まり本質的な問題がわかることが多いです。
そのような作業をして、その分割したシンプルな問題を質問するのが最良の技術的な質問の利用方法です。
(繰り返しますが、質問のために分割するのではなく、分割してシンプル化することが問題解決やデバッグの基本なのです。)

今回の場合、ご質問は VBAからC#の自作ライブラリのメソッドを呼び出すときに、引数でVBA側のDouble型の配列とString型の値を渡す方法でしょうか? 
(であれば、そのような質問をこの投稿とは別に新規に行っていただくのがコンテキストに依存しない良い質問方法です。)

あと、この掲示板は個人のチャットではないので、できましたら個人あてに質問することはお控えください。
投稿者 snowmansnow  (社会人) 投稿日時 2022/10/9 09:42:02

  おはようございます。るきお様
>今回の場合、ご質問は VBAからC#の自作ライブラリのメソッドを呼び出すときに、
>引数でVBA側のDouble型の配列とString型の値を渡す方法でしょうか?]
はい、その通りの状態でした。
C#に関する質問だと、こちらで面倒みてくれるのではと思いました。

VB.NETとC#が、頭の中で、ごっちゃになって、C#なのに、「as String」とか書いてエラーになり、
C#のインターフェースでは、複数の引数が使えないと勘違いして、御質問してしまいました。
今回の質問は、「ref Double[] array, String SRC, String DEST」というように
C#の書き方をする事で解決できました。

質問の仕方の注意ありがとうございます。
要点を簡潔に切り分けて、回答して頂ける方々や、見てくれる方々にわかりやすくするように注意します。何度も、ごめんなさい。

自分なりで解決した内容を一応貼り付けます。
VBA
Sub GetInkDouble3()
 
 Dim HogeIF As ClassLibrary1_ink_CL.IHogehoge3
 Set HogeIF = New ClassLibrary1_ink_CL.Hogehoge3
  
  Dim d(5) As Double
  
  d(0) = 10.5
  d(1) = 300.5
  d(2) = 50.78
  d(3) = 60.66
  d(4) = 160.66
  d(5) = 260.66
  
  Dim src As String
  Dim dest As String
  Dim p As Long

  
   src = "C:/ほげほげ/読み込む.PDF"
  dest = "C:/ほげほげ/書き出す.PDF"
  p = 1
  
  Call HogeIF.HogeMethod3(d, src, dest, p)
  
End Sub

C#が
using System;
using System.Runtime.InteropServices;
using iText.Kernel.Colors;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Annot;
using Rectangle = iText.Kernel.Geom.Rectangle;

namespace ClassLibrary1_ink_CL
{
    [Guid("EF2CEEAD-04CB-4A86-896C-C8878A16A711")]
    public interface IHogehoge3
    {
        void HogeMethod3(ref Double[] array, String SRC, String DEST, int p);
    }
    [Guid("D3868E78-0ABA-4BB5-B22E-4DF4BFDD3F7B")]
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("ClassLibrary1_ink_CL.Hogehoge.1")]
    public class Hogehoge3 :IHogehoge3
    {
  
        public void HogeMethod3(ref Double[] array,String SRC,String DEST, int p)
        {
            //Initialize PDF document
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST));

            //Creating a PdfPage
            PdfPage page = pdfDoc.GetPage(p);

            //creating PdfLineAnnotation object
            Rectangle rect = new Rectangle(0, 0, 0, 0);

            PdfArray outer = new PdfArray();
            PdfArray inner = new PdfArray();

            for (int k = 0; k < array.Length; ++k)
            {
                inner.Add(new PdfNumber(array[k]));
            }
            outer.Add(inner);
            //dummy
            outer.Add(inner);

            PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rect, outer);

            // Set arrow's border style 
            PdfDictionary borderStyle = new PdfDictionary();
            borderStyle.Put(PdfName.S, PdfName.S);
            borderStyle.Put(PdfName.W, new PdfNumber(3));
            inkAnnotation.SetBorderStyle(borderStyle);

            //Setting color of the PdfLineAnnotation
            inkAnnotation.SetColor(ColorConstants.RED);

            //Setting title to the PdfLineAnnotation
            inkAnnotation.SetTitle(new PdfString("iText"));

            //Setting contents of the PdfLineAnnotation
            inkAnnotation.SetContents("Hi welcome to finddevguides");

            //Adding annotation to the page
            page.AddAnnotation(inkAnnotation);

            //Closing the document
            pdfDoc.Close();
          
        }
    }
}


です
皆さんごめんなさい。気を付けますね。