/// <summary> /// PDF link annotation constructor /// </summary> /// <param name="Page">Associated page</param> /// <param name="AnnotRect">Annotation rectangle</param> /// <param name="WebLink">Weblink</param> public PdfAnnotation ( PdfPage Page, PdfRectangle AnnotRect, PdfWebLink WebLink ) : base(Page.Document) { // annotation subtype Dictionary.Add("/Subtype", "/Link"); // action reference dictionary Dictionary.AddIndirectReference("/A", WebLink); // constructor helper method ContructorHelper(Page, AnnotRect); // exit return; }
//////////////////////////////////////////////////////////////////// /// <summary> /// Add weblink to this page /// </summary> /// <param name="WeblinkArea">Weblink area</param> /// <param name="WebLinkStr">Hyperlink string</param> /// <remarks> /// <para> /// The four position arguments are in relation to the /// bottom left corner of the paper. /// If web link is empty, ignore this call. /// </para> /// <para> /// For more information go to <a href="http://www.codeproject.com/Articles/570682/PDF-File-Writer-Csharp-Class-Library-Version#WeblinkSupport">2.7 Web Link Support</a> /// </para> /// </remarks> //////////////////////////////////////////////////////////////////// public void AddWebLink ( PdfRectangle WeblinkArea, String WebLinkStr ) { // if web link is empty, ignore this call if (String.IsNullOrWhiteSpace(WebLinkStr)) { return; } // create weblink action or reuse duplicate PdfWebLink WebLinkAction = PdfWebLink.AddWebLink(Document, WebLinkStr); // create PdfObject for annotation PdfAnnotation Annotation = new PdfAnnotation(this, WeblinkArea, WebLinkAction); // exit return; }
/// <summary> /// PdfAnnotation constructor /// </summary> /// <param name="AnnotPage">Page object</param> /// <param name="AnnotRect">Annotation rectangle</param> /// <param name="AnnotAction">Annotation action</param> internal PdfAnnotation ( PdfPage AnnotPage, PdfRectangle AnnotRect, AnnotAction AnnotAction ) : base(AnnotPage.Document) { // save arguments this.AnnotPage = AnnotPage; this.AnnotRect = AnnotRect; this.AnnotAction = AnnotAction; // annotation subtype Dictionary.Add("/Subtype", AnnotAction.Subtype); // area rectangle on the page Dictionary.AddRectangle("/Rect", AnnotRect); // annotation flags. value of 4 = Bit position 3 print Dictionary.Add("/F", "4"); // border style dictionary. If /BS with /W 0 is not specified, the annotation will have a thin border Dictionary.Add("/BS", "<</W 0>>"); // web link if (AnnotAction.GetType() == typeof(AnnotWebLink)) { Dictionary.AddIndirectReference("/A", PdfWebLink.AddWebLink(Document, ((AnnotWebLink)AnnotAction).WebLinkStr)); } // jump to destination else if (AnnotAction.GetType() == typeof(AnnotLinkAction)) { if (Document.LinkAnnotArray == null) { Document.LinkAnnotArray = new List <PdfAnnotation>(); } Document.LinkAnnotArray.Add(this); } // display video or play sound else if (AnnotAction.GetType() == typeof(AnnotDisplayMedia)) { var DisplayMedia = ((AnnotDisplayMedia)AnnotAction).DisplayMedia; // action reference dictionary Dictionary.AddIndirectReference("/A", DisplayMedia); // add page reference Dictionary.AddIndirectReference("/P", AnnotPage); // add annotation reference DisplayMedia.Dictionary.AddIndirectReference("/AN", this); } // file attachment else if (AnnotAction.GetType() == typeof(AnnotFileAttachment)) { // add file attachment reference var File = (AnnotFileAttachment)AnnotAction; Dictionary.AddIndirectReference("/FS", File.EmbeddedFile); if (File.Icon != FileAttachIcon.NoIcon) { // icon Dictionary.AddName("/Name", File.Icon.ToString()); } else { // no icon var XObject = new PdfXObject(Document, AnnotRect.Right, AnnotRect.Top); Dictionary.AddFormat("/AP", "<</N {0} 0 R>>", XObject.ObjectNumber); } } // add annotation object to page dictionary var KeyValue = AnnotPage.Dictionary.GetValue("/Annots"); if (KeyValue == null) { AnnotPage.Dictionary.AddFormat("/Annots", "[{0} 0 R]", ObjectNumber); } else { AnnotPage.Dictionary.Add("/Annots", ((string)KeyValue.Value).Replace("]", string.Format(" {0} 0 R]", ObjectNumber))); } // exit }