投稿者 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();
        }
    }
}

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