投稿者 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ではないのですが、宜しくお願いします。