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"; } } }