/** * <summary>Creates a launcher.</summary> * <param name="context">Document context.</param> * <param name="target">Either a <see cref="FileSpecification"/> or a <see cref="WinTarget"/> * representing either an application or a document.</param> */ public Launch( Document context, PdfObjectWrapper target ) : base(context, PdfName.Launch) { Target = target; }
private void SetColor( PdfName key, DeviceColor value ) { BaseDataObject[key] = PdfObjectWrapper.GetBaseObject(value); }
public T Get <T>( PdfString key ) where T : PdfObjectWrapper { PdfObjectWrapper names = Get(typeof(T)); return((T)names.GetType().GetProperty("Item", BindingFlags.Public | BindingFlags.Instance).GetValue(names, new object[] { key })); }
public MediaClipData( PdfObjectWrapper data, string mimeType ) : base(data.Document, PdfName.MCD) { Data = data; MimeType = mimeType; TempFilePermission = TempFilePermissionEnum.Always; }
public Link( Page page, RectangleF box, string text, PdfObjectWrapper target ) : base(page, PdfName.Link, box, text) { Target = target; }
public PdfObjectWrapper Get( Type type, PdfString key ) { PdfObjectWrapper namedObjects = Get(type); return((PdfObjectWrapper)namedObjects.GetType().GetMethod("get_Item", BindingFlags.Public | BindingFlags.Instance).Invoke(namedObjects, new object[] { key })); }
/** * <summary>Registers a named object.</summary> * <param name="name">Object name.</param> * <param name="object">Named object.</param> * <returns>Registered named object.</returns> */ public T Register <T>( PdfString name, T @object ) where T : PdfObjectWrapper { PdfObjectWrapper namedObjects = Names.Get(@object.GetType()); namedObjects.GetType().GetMethod("set_Item", BindingFlags.Public | BindingFlags.Instance).Invoke(namedObjects, new object[] { name, @object }); return(@object); }
/** * <summary>Drops the object from this document context.</summary> */ public void Decontextualize( PdfObjectWrapper obj ) { if (obj.File != File) { return; } obj.Delete(); }
/** * <summary>Clones the object within this document context.</summary> */ public PdfObjectWrapper Contextualize( PdfObjectWrapper obj ) { if (obj.File == File) { return(obj); } return((PdfObjectWrapper)obj.Clone(this)); }
/** * <summary>Updates the specified trailer.</summary> * <remarks>This method has to be called just before serializing the trailer object.</remarks> */ protected void UpdateTrailer(PdfDictionary trailer, IOutputStream stream) { // File identifier update. FileIdentifier identifier = PdfObjectWrapper.Wrap <FileIdentifier>(trailer[PdfName.ID]); if (identifier == null) { trailer[PdfName.ID] = (identifier = new FileIdentifier()).BaseObject; } identifier.Update(this); }
/** * <summary>Clones the object within this document context.</summary> */ public PdfObjectWrapper Include( PdfObjectWrapper obj ) { if (obj.File == File) { return(obj); } return((PdfObjectWrapper)obj.Clone(this)); }
/** * <summary>Deletes the object from this document context.</summary> */ public void Exclude( PdfObjectWrapper obj ) { if (obj.File != File) { return; } obj.Delete(); }
public static void SetAdditionalAction(PdfObjectWrapper <PdfDictionary> wrapper, PdfName key, iText.Kernel.Pdf.Action.PdfAction action) { PdfDictionary dic; PdfObject obj = wrapper.GetPdfObject().Get(PdfName.AA); if (obj != null && obj.IsDictionary()) { dic = (PdfDictionary)obj; } else { dic = new PdfDictionary(); } dic.Put(key, action.GetPdfObject()); wrapper.GetPdfObject().Put(PdfName.AA, dic); }
public Screen( Page page, drawing::RectangleF box, String text, Rendition rendition ) : base(page, PdfName.Screen, box, text) { Render render = new Render(this, Render.OperationEnum.PlayResume, rendition); { // Adding preview and play/pause control... /* * NOTE: Mouse-related actions don't work when the player is active; therefore, in order to let * the user control the rendering of the media clip (play/pause) just by mouse-clicking on the * player, we can only rely on the player's focus event. Furthermore, as the player's focus can * only be altered setting it on another widget, we have to define an ancillary field on the * same page (so convoluted!). */ string playerReference = "__player" + ((PdfReference)render.BaseObject).ObjectNumber; Document.Form.Fields.Add(new TextField(playerReference, new Widget(page, new drawing::RectangleF(box.X, box.Y, 0, 0)), "")); // Ancillary field. render.Script = RenderScript.Replace(PlayerPlaceholder, playerReference); } Actions.OnPageOpen = render; if (rendition is MediaRendition) { PdfObjectWrapper data = ((MediaRendition)rendition).Clip.Data; if (data is FileSpecification) { // Adding fallback annotation... /* * NOTE: In case of viewers which don't support video rendering, this annotation gently * degrades to a file attachment that can be opened on the same location of the corresponding * screen annotation. */ FileAttachment attachment = new FileAttachment(page, box, text, (FileSpecification)data); BaseDataObject[PdfName.T] = PdfString.Get(((FileSpecification)data).Path); // Force empty appearance to ensure no default icon is drawn on the canvas! attachment.BaseDataObject[PdfName.AP] = new PdfDictionary(new PdfName[] { PdfName.D, PdfName.R, PdfName.N }, new PdfDirectObject[] { new PdfDictionary(), new PdfDictionary(), new PdfDictionary() }); } } }
/// <summary> /// Adds an additional action to the provided /// <see cref="iText.Kernel.Pdf.PdfObjectWrapper{T}"/> /// < /// <see cref="iText.Kernel.Pdf.PdfDictionary"/> /// > wrapper. /// </summary> /// <param name="wrapper">the wrapper to add an additional action to</param> /// <param name="key"> /// a /// <see cref="iText.Kernel.Pdf.PdfName"/> /// specifying the name of an additional action /// </param> /// <param name="action"> /// the /// <see cref="PdfAction"/> /// to add as an additional action /// </param> public static void SetAdditionalAction(PdfObjectWrapper <PdfDictionary> wrapper, PdfName key, iText.Kernel.Pdf.Action.PdfAction action) { PdfDictionary dic; PdfObject obj = wrapper.GetPdfObject().Get(PdfName.AA); bool aaExists = obj != null && obj.IsDictionary(); if (aaExists) { dic = (PdfDictionary)obj; } else { dic = new PdfDictionary(); } dic.Put(key, action.GetPdfObject()); dic.SetModified(); wrapper.GetPdfObject().Put(PdfName.AA, dic); if (!aaExists || !dic.IsIndirect()) { wrapper.GetPdfObject().SetModified(); } }
private void PrintBookmarks( Bookmarks bookmarks ) { if (bookmarks == null) { return; } foreach (Bookmark bookmark in bookmarks) { // Show current bookmark! Console.WriteLine("Bookmark '" + bookmark.Title + "'"); Console.Write(" Target: "); PdfObjectWrapper target = bookmark.Target; if (target is Destination) { PrintDestination((Destination)target); } else if (target is actions::Action) { PrintAction((actions::Action)target); } else if (target == null) { Console.WriteLine("[not available]"); } else { Console.WriteLine("[unknown type: " + target.GetType().Name + "]"); } // Show child bookmarks! PrintBookmarks(bookmark.Bookmarks); } }
public override void Run( ) { // 1. Opening the PDF file... string filePath = PromptFileChoice("Please select a PDF file"); using (files::File file = new files::File(filePath)) { Document document = file.Document; // 2. Link extraction from the document pages. TextExtractor extractor = new TextExtractor(); extractor.AreaTolerance = 2; // 2 pt tolerance on area boundary detection. bool linkFound = false; foreach (Page page in document.Pages) { if (!PromptNextPage(page, !linkFound)) { Quit(); break; } IDictionary <RectangleF?, IList <ITextString> > textStrings = null; linkFound = false; // Get the page annotations! PageAnnotations annotations = page.Annotations; if (!annotations.Exists()) { Console.WriteLine("No annotations here."); continue; } // Iterating through the page annotations looking for links... foreach (Annotation annotation in annotations) { if (annotation is Link) { linkFound = true; if (textStrings == null) { textStrings = extractor.Extract(page); } Link link = (Link)annotation; RectangleF linkBox = link.Box; // Text. /* * Extracting text superimposed by the link... * NOTE: As links have no strong relation to page text but a weak location correspondence, * we have to filter extracted text by link area. */ StringBuilder linkTextBuilder = new StringBuilder(); foreach (ITextString linkTextString in extractor.Filter(textStrings, linkBox)) { linkTextBuilder.Append(linkTextString.Text); } Console.WriteLine("Link '" + linkTextBuilder + "' "); // Position. Console.WriteLine( " Position: " + "x:" + Math.Round(linkBox.X) + "," + "y:" + Math.Round(linkBox.Y) + "," + "w:" + Math.Round(linkBox.Width) + "," + "h:" + Math.Round(linkBox.Height) ); // Target. Console.Write(" Target: "); PdfObjectWrapper target = link.Target; if (target is Destination) { PrintDestination((Destination)target); } else if (target is actions::Action) { PrintAction((actions::Action)target); } else if (target == null) { Console.WriteLine("[not available]"); } else { Console.WriteLine("[unknown type: " + target.GetType().Name + "]"); } } } if (!linkFound) { Console.WriteLine("No links here."); continue; } } } }