public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //open document Document document = new Document(dataDir+ "input.pdf"); //create link Page page = document.Pages[1]; LinkAnnotation link = new LinkAnnotation(page, new Aspose.Pdf.Rectangle(100, 100, 300, 300)); link.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green); link.Action = new GoToRemoteAction(dataDir + "blank.pdf", 1); page.Annotations.Add(link); //save updated document document.Save(dataDir + "output.pdf"); }
public static void Run() { // ExStart:CreateDocumentLink // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_LinksActions(); // Open document Document document = new Document(dataDir+ "CreateDocumentLink.pdf"); // Create link Page page = document.Pages[1]; LinkAnnotation link = new LinkAnnotation(page, new Aspose.Pdf.Rectangle(100, 100, 300, 300)); link.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green); link.Action = new GoToRemoteAction(dataDir + "RemoveOpenAction.pdf", 1); page.Annotations.Add(link); dataDir = dataDir + "CreateDocumentLink_out.pdf"; // Save updated document document.Save(dataDir); // ExEnd:CreateDocumentLink Console.WriteLine("\nDocument link created successfully.\nFile saved at " + dataDir); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_LinksActions(); //open document Document document = new Document(dataDir+ "CreateDocumentLink.pdf"); //create link Page page = document.Pages[1]; LinkAnnotation link = new LinkAnnotation(page, new Aspose.Pdf.Rectangle(100, 100, 300, 300)); link.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green); link.Action = new GoToRemoteAction(dataDir + "blank.pdf", 1); page.Annotations.Add(link); //save updated document document.Save(dataDir + "CreateDocumentLink_out.pdf"); }
static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // Add page Page page = new Page(PaperFormat.A4); pdfDocument.Pages.Add(page); // Set Url action URIAction action = new URIAction(new Uri("https://bytescout.com")); // Add link annotation LinkAnnotation linkAnnotation = new LinkAnnotation(action, 20, 20, 150, 25); // Set highlight mode linkAnnotation.HighlightingMode = LinkAnnotationHighlightingMode.Outline; // Set color linkAnnotation.Color = new ColorRGB(0, 0, 255); // Add Link page.Annotations.Add(linkAnnotation); // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open result document in default associated application (for demo purpose) ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf"); processStartInfo.UseShellExecute = true; Process.Start(processStartInfo); }
public static void Run() { // ExStart:AddHyperlink // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_LinksActions(); // Open document Document document = new Document(dataDir + "AddHyperlink.pdf"); // Create link Page page = document.Pages[1]; // Create Link annotation object LinkAnnotation link = new LinkAnnotation(page, new Aspose.Pdf.Rectangle(100, 100, 300, 300)); // Create border object for LinkAnnotation Border border = new Border(link); // Set the border width value as 0 border.Width = 0; // Set the border for LinkAnnotation link.Border = border; // Specify the link type as remote URI link.Action = new GoToURIAction("www.aspose.com"); // Add link annotation to annotations collection of first page of PDF file page.Annotations.Add(link); // Create Free Text annotation FreeTextAnnotation textAnnotation = new FreeTextAnnotation(document.Pages[1], new Aspose.Pdf.Rectangle(100, 100, 300, 300), new DefaultAppearance(Aspose.Pdf.Text.FontRepository.FindFont("TimesNewRoman"), 10, System.Drawing.Color.Blue)); // String to be added as Free text textAnnotation.Contents = "Link to Aspose website"; // Set the border for Free Text Annotation textAnnotation.Border = border; // Add FreeText annotation to annotations collection of first page of Document document.Pages[1].Annotations.Add(textAnnotation); dataDir = dataDir + "AddHyperlink_out.pdf"; // Save updated document document.Save(dataDir); // ExEnd:AddHyperlink Console.WriteLine("\nHyperlink added successfully.\nFile saved at " + dataDir); }
public static bool Open(Annotation a) { TextAnnotation note1 = a as TextAnnotation; if (note1 != null) { return(new TextAnnotationDlg(note1).ShowDialog() == DialogResult.OK); } LinkAnnotation note2 = a as LinkAnnotation; if (note2 != null) { return(new FileLinkAnnotationDlg(note2).ShowDialog() == DialogResult.OK); } SketchAnnotation note3 = a as SketchAnnotation; if (note3 != null) { return(new SketchAnnotationDlg(note3).ShowDialog() == DialogResult.OK); } return(false); }
/** * Creates annotation, type of annotation is taken from given properties */ public static Annotation CreateAnnotation(Document doc, Page page, int index, AnnotationProperties props) { Annotation ann = null; int addAfter = index - 1; switch (props.Subtype) { case "Line": ann = new LineAnnotation(page, props.BoundingRect, props.StartPoint, props.EndPoint, addAfter); break; case "Circle": ann = new CircleAnnotation(page, props.BoundingRect, addAfter); break; case "Square": ann = new SquareAnnotation(page, props.BoundingRect, addAfter); break; case "FreeText": ann = new FreeTextAnnotation(page, props.BoundingRect, "", addAfter); break; case "PolyLine": ann = new PolyLineAnnotation(page, props.BoundingRect, props.Vertices, addAfter); break; case "Polygon": ann = new PolygonAnnotation(page, props.BoundingRect, props.Vertices, addAfter); break; case "Link": ann = new LinkAnnotation(page, props.BoundingRect, addAfter); break; case "Ink": ann = new InkAnnotation(page, props.BoundingRect, addAfter); break; case "Underline": ann = new UnderlineAnnotation(page, addAfter, props.Quads); break; case "Highlight": ann = new HighlightAnnotation(page, addAfter, props.Quads); break; default: throw new Exception("Logic error"); } AnnotationAppearance app = new AnnotationAppearance(doc, ann); app.CaptureAnnotation(); app.Properties.SetFrom(props); app.Properties.Dirty = true; app.UpdateAppearance(); app.ReleaseAnnotation(); return(ann); }
public static void Run() { // ExStart:CreateApplicationLink // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_LinksActions(); // Open document Document document = new Document(dataDir + "CreateApplicationLink.pdf"); // Create link Page page = document.Pages[1]; LinkAnnotation link = new LinkAnnotation(page, new Aspose.Pdf.Rectangle(100, 100, 300, 300)); link.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green); link.Action = new LaunchAction(document, dataDir + "CreateApplicationLink.pdf"); page.Annotations.Add(link); dataDir = dataDir + "CreateApplicationLink_out_.pdf"; // Save updated document document.Save(dataDir); // ExEnd:CreateApplicationLink Console.WriteLine("\nApplication link created successfully.\nFile saved at " + dataDir); }
static void Main(string[] args) { Console.WriteLine("PDFObject Sample:"); // ReSharper disable once UnusedVariable using (Library lib = new Library()) { String sInput = Library.ResourceDirectory + "Sample_Input/sample_links.pdf"; String sOutput = "PDFObject-out.pdf"; if (args.Length > 0) { sInput = args[0]; } if (args.Length > 1) { sOutput = args[1]; } Console.WriteLine("Input file: " + sInput + ". Writing to output " + sOutput); Document doc = new Document(sInput); Page page = doc.GetPage(0); LinkAnnotation annot = (LinkAnnotation)page.GetAnnotation(1); URIAction uri = (URIAction)annot.Action; // Print some info about the URI action, before we modify it Console.WriteLine("Initial URL: " + uri.URI); Console.WriteLine("Is Map property: " + uri.IsMap); // Modify the URIAction // // A URI action is a dictionary containing: // Key: S Contents: a name object with the value "URI" (required) // Key: URI Contents: a string object for the uniform resource locator (required) // Key: IsMap Contents: a boolean for whether the link is part of a map (optional) // (see section 8.5.3, "Action Types", of the PDF Reference) // // We will change the URI entry and delete the IsMap entry for this dictionary PDFDict uri_dict = uri.PDFDict; // Extract the dictionary // Create a new string object PDFString uri_string = new PDFString("http://www.google.com", doc, false, false); uri_dict.Put("URI", uri_string); // Change the URI (replaces the old one) uri_dict.Remove("IsMap"); // Remove the IsMap entry // Check that we deleted the IsMap entry Console.WriteLine("Does this dictionary have an IsMap entry? " + uri_dict.Contains("IsMap")); doc.Save(SaveFlags.Full, sOutput); doc.Close(); // Check the modified contents of the link doc = new Document(sOutput); page = doc.GetPage(0); annot = (LinkAnnotation)page.GetAnnotation(1); uri = (URIAction)annot.Action; Console.WriteLine("Modified URL: " + uri.URI); Console.WriteLine("Is Map property (if not present, defaults to false): " + uri.IsMap); } }
static void Main(string[] args) { Console.WriteLine("Actions Sample:"); using (Library lib = new Library()) { String sOutput = "../Actions-out.pdf"; Console.WriteLine("Initialized the library."); Document doc = new Document(); using (Path newpath = new Path()) { // Create a PDF page which is the same size of the image. Rect pageRect = new Rect(0, 0, 100, 100); Page docpage = doc.CreatePage(Document.BeforeFirstPage, pageRect); Console.WriteLine("Created page."); // Create our first link with a URI action LinkAnnotation newLink = (LinkAnnotation)docpage.CreateAnnotation("Link", new Rect(1.0, 2.0, 3.0, 4.0)); Console.WriteLine(newLink.ToString()); doc.BaseURI = "http://www.datalogics.com"; URIAction uri = new URIAction("/products/pdfl/pdflibrary.asp", false); Console.WriteLine("Action data: " + uri.ToString()); newLink.Action = uri; docpage.AddAnnotation(-2, newLink); // Create a second link with a GoTo action LinkAnnotation secondLink = (LinkAnnotation)docpage.CreateAnnotation("Link", new Rect(5.0, 6.0, 7.0, 8.0)); Rect r = new Rect(5, 5, 100, 100); GoToAction gta = new GoToAction(new ViewDestination(doc, 0, "FitR", r, 1.0)); Console.WriteLine("Action data: " + gta.ToString()); secondLink.Action = gta; docpage.AddAnnotation(-2, secondLink); // Read some URI properties Console.WriteLine("Extracted URI: " + uri.URI); if (uri.IsMap) { Console.WriteLine("Send mouse coordinates"); } else { Console.WriteLine("Don't send mouse coordinates"); } // Change the URI properties doc.BaseURI = "http://www.datalogics.com"; uri.URI = "/products/pdfl/pdflibrary.asp"; uri.IsMap = true; Console.WriteLine("Complete changed URI:" + doc.BaseURI + uri.URI); if (uri.IsMap) { Console.WriteLine("Send mouse coordinates"); } else { Console.WriteLine("Don't send mouse coordinates"); } // Testing gta Console.WriteLine("Fit type of destination: " + gta.Destination.FitType.ToString()); Console.WriteLine("Rectangle of destination: " + gta.Destination.DestRect.ToString()); Console.WriteLine("Zoom of destination: " + gta.Destination.Zoom.ToString()); Console.WriteLine("Page number of destination: " + gta.Destination.PageNumber.ToString()); doc.Save(SaveFlags.Full, sOutput); } } }
static void Main(string[] args) { Console.WriteLine("AnnotationCopyPaste Sample:"); using (Library lib = new Library()) { Console.WriteLine("Initialized the library."); String sInput1 = "../../Resources/Sample_Input/sample_annotations.pdf"; String sInput2 = "../../Resources/Sample_Input/Layers.pdf"; String sOutput = "../AnnotationCopyPaste-out.pdf"; if (args.Length > 0) { sInput1 = args[0]; } Document sourceDoc = new Document(sInput1); if (args.Length > 1) { sInput2 = args[1]; } Document destinationDoc = new Document(sInput2); if (args.Length > 2) { sOutput = args[2]; } Console.WriteLine("Copying annotations from " + sInput1 + " into " + sInput2 + " and writing to " + sOutput); Page sourcePage = sourceDoc.GetPage(0); Page destinationPage = destinationDoc.GetPage(0); int nAnnots = sourcePage.NumAnnotations; // find each link annotation on the first page of the source document and // copy them to the first page of the destination document for (int i = 0; i < nAnnots; i++) { Annotation ann = sourcePage.GetAnnotation(i); if (ann.Subtype == "Link") { Rect linkRect = ann.Rect; Point linkCenter = new Point(); // find the center of the link linkCenter.H = linkRect.Left + linkRect.Width / 2; linkCenter.V = linkRect.Bottom + linkRect.Height / 2; try { // copy the annotation to the destination and center it on // the center point of the original annotation. // // This may throw an ApplicationException if it cannot // copy/paste the annotation, in either case the message in // the exception will specify which operation (copy or paste) // that it could not complete. LinkAnnotation copiedLink = ((LinkAnnotation)ann).CopyTo(destinationPage, linkCenter); } catch (ApplicationException ae) { Console.WriteLine(ae.Message); } } } destinationDoc.Save(SaveFlags.Full, sOutput); } }
static void Main(string[] args) { using (Library lib = new Library()) { String sFileSpec = "../../Resources/Sample_Input/ducky.pdf"; String sOutput = "../RemoteGoToActions-out.pdf"; if (args.Length > 0) { sFileSpec = args[0]; } if (args.Length > 1) { sOutput = args[1]; } Console.WriteLine("Writing to output " + sOutput + ". Using " + sFileSpec + " as file specification"); Document doc = new Document(); // Standard letter size page (8.5" x 11") Rect pageRect = new Rect(0, 0, 612, 792); Page docpage = doc.CreatePage(Document.BeforeFirstPage, pageRect); Console.WriteLine("Created page."); LinkAnnotation newLink = new LinkAnnotation(docpage, new Rect(153, 198, 306, 396)); Console.WriteLine("Created new Link Annotation"); // RemoteGoToActions need a FileSpecification and a RemoteDestination. // // The FileSpecification specifies which file should be opened when the LinkAnnotation is "clicked" // // The RemoteDestination specifies a particular view (page number, Fit type, rectangle, and zoom level) // to display when the file in the FileSpecification is opened. Remember page numbers start at 0. // // FileSpecification objects, RemoteDestination objects, and RemoteGoToActions // must be associated with a Document. The association happens at object creation time and cannot be changed. // // FileSpecifications and RemoteDestinations are associated with the Document that is passed in the constructor. // RemoteGoToActions are associated with the same Document as the RemoteDestination used to create it. // // When creating a RemoteGoToAction, make sure that the FileSpecification and RemoteDestination are both // associated with the same Document, or an exception will be thrown. // FileSpecifications can take either a relative or an absolute path. It is best to specify // a relative path if the document is intended to work across multiple platforms (Windows, Linux, Mac) FileSpecification fileSpec = new FileSpecification(doc, sFileSpec); Console.WriteLine("Path to remote document : " + fileSpec.Path); RemoteDestination remoteDest = new RemoteDestination(doc, 0, "XYZ", new Rect(0, 0, 4 * 72, 4 * 72), 1.5); Console.WriteLine("When the Link is clicked the remote document will open to : "); Console.WriteLine("Page Number : " + remoteDest.PageNumber); Console.WriteLine("zoom level : " + remoteDest.Zoom); Console.WriteLine("fit type : " + remoteDest.FitType); Console.WriteLine("rectangle : " + remoteDest.DestRect.ToString()); // Now create the RemoteGoToAction from the fileSpec and the RemoteDestination RemoteGoToAction remoteAction = new RemoteGoToAction(fileSpec, remoteDest); // assign the RemoteGoToAction to the LinkAnnotation newLink.Action = remoteAction; doc.Save(SaveFlags.Full, sOutput); } }
static void Main(string[] args) { Console.WriteLine("LinkAnnotations Sample:"); using (Library lib = new Library()) { Console.WriteLine("Initialized the library."); String sInput = Library.ResourceDirectory + "Sample_Input/sample.pdf"; String sOutput = "../LaunchActions-out.pdf"; if (args.Length > 0) { sInput = args[0]; } if (args.Length > 1) { sOutput = args[1]; } Console.WriteLine("Input file: " + sInput + ". Writing to output " + sOutput); Document doc = new Document(sInput); Page docpage = doc.GetPage(0); LinkAnnotation newLink = new LinkAnnotation(docpage, new Rect(1.0, 2.0, 3.0, 4.0)); // Test some link features newLink.NormalAppearance = newLink.GenerateAppearance(); Console.WriteLine("Current Link Annotation version = " + newLink.AnnotationFeatureLevel.ToString()); newLink.AnnotationFeatureLevel = 1.0; Console.WriteLine("New Link Annotation version = " + newLink.AnnotationFeatureLevel.ToString()); // Test the destination setting ViewDestination dest = new ViewDestination(doc, 0, "XYZ", doc.GetPage(0).MediaBox, 1.5); dest.DestRect = new Rect(0.0, 0.0, 200.0, 200.0); Console.WriteLine("The new destination rectangle: " + dest.DestRect.ToString()); dest.FitType = "FitV"; Console.WriteLine("The new fit type: " + dest.FitType); dest.Zoom = 2.5; Console.WriteLine("The new zoom level: " + dest.Zoom.ToString()); dest.PageNumber = 1; Console.WriteLine("The new page number: " + dest.PageNumber.ToString()); newLink.Destination = dest; newLink.Highlight = HighlightStyle.Invert; if (newLink.Highlight == HighlightStyle.Invert) { Console.WriteLine("Invert highlighting."); } doc.Save(SaveFlags.Full, sOutput); } }
/** * Mouse up handler. * All annotation transformation is performed in mouse move handler. * This handler is for context menu calls, and for finishing annotation tracking. */ public override void MouseUp(MouseEventArgs e, System.Drawing.Point location) { captured = false; if (!docView.EditPermission) { return; } if (e.Button == MouseButtons.Right) { if (docView.ActiveAnnotation != null) { ContextMenu currentContextMenu = null; switch (docView.ActiveAnnotation.Properties.Subtype) { case "FreeText": currentContextMenu = textAnnotationContextMenu; break; case "Link": currentContextMenu = linkAnnotationContextMenu; break; default: currentContextMenu = shapeAnnotationContextMenu; break; } if (currentContextMenu != null) { UpdateMenuItems(currentContextMenu); currentContextMenu.Show(docView.Parent, e.Location); } } } else { docView.EditCheckPoint(); if (e.Button == MouseButtons.Left && Control.ModifierKeys == Keys.Control && (docView.ActiveAnnotation != null || cachedIndex != -1)) { BaseAnnotationEditor editor = docView.EditAnnotations[cachedIndex]; if (editor is LinkAnnotationEditor) { LinkAnnotation annot = editor.Annotation as LinkAnnotation; if (annot.Action is URIAction) { URIAction act = annot.Action as URIAction; System.Diagnostics.Process.Start(act.URI); } else if (annot.Action is RemoteGoToAction) { RemoteGoToAction action = annot.Action as RemoteGoToAction; FileSpecification spec = action.FileSpecification; string fullPath = System.IO.Path.GetFullPath(spec.Path); if (System.IO.File.Exists(fullPath)) { System.Diagnostics.Process.Start(fullPath); } } else if (annot.Action is GoToAction || annot.Destination != null) { GoToAction action = (annot.Action as GoToAction); ViewDestination dest = action == null ? annot.Destination : action.Destination; if (dest != null) { docView.GoToDestionation(dest); } } } } } }
private void parseAnnotations() { for (int i = 0; i < _array.Count; ++i) { PDFDictionary annotDict = _array[i] as PDFDictionary; if (annotDict != null) { if (annotDict["IRT"] == null) { PDFName subtype = annotDict["Subtype"] as PDFName; if (subtype != null) { Annotation annot = null; switch (subtype.GetValue()) { case "Text": annot = new TextAnnotation(annotDict, _owner); break; case "Link": annot = new LinkAnnotation(annotDict, _owner); break; case "FreeText": annot = new FreeTextAnnotation(annotDict, _owner); break; case "Line": annot = new LineAnnotation(annotDict, _owner); break; case "Square": annot = new SquareAnnotation(annotDict, _owner); break; case "Circle": annot = new CircleAnnotation(annotDict, _owner); break; case "Polygon": annot = new PolygonAnnotation(annotDict, _owner); break; case "PolyLine": annot = new PolylineAnnotation(annotDict, _owner); break; case "Highlight": annot = new HighlightAnnotation(annotDict, _owner); break; case "Underline": annot = new UnderlineAnnotation(annotDict, _owner); break; case "Squiggly": annot = new SquigglyAnnotation(annotDict, _owner); break; case "StrikeOut": annot = new StrikeOutAnnotation(annotDict, _owner); break; case "Stamp": annot = new RubberStampAnnotation(annotDict, _owner); break; case "Caret": annot = new CaretAnnotation(annotDict, _owner); break; case "Ink": annot = new InkAnnotation(annotDict, _owner); break; case "FileAttachment": annot = new FileAttachmentAnnotation(annotDict, _owner); break; case "Sound": annot = new SoundAnnotation(annotDict, _owner); break; case "Movie": annot = new MovieAnnotation(annotDict, _owner); break; case "Screen": annot = new ScreenAnnotation(annotDict, _owner); break; case "3D": annot = new ThreeDAnnotation(annotDict, _owner); break; case "Widget": PDFName ft = annotDict["FT"] as PDFName; if (ft == null) { PDFDictionary parent = annotDict["Parent"] as PDFDictionary; if (parent != null) { ft = parent["FT"] as PDFName; } } if (ft != null) { switch (ft.GetValue()) { case "Tx": annot = new EditBox(annotDict, _owner); break; case "Ch": uint flag = getFlag(annotDict); if ((flag >> 17) % 2 != 0) { annot = new ComboBox(annotDict, _owner); } else { annot = new ListBox(annotDict, _owner); } break; case "Btn": flag = getFlag(annotDict); if ((flag >> 16) % 2 != 0) { annot = new PushButton(annotDict, _owner); } else if ((flag >> 15) % 2 != 0) { annot = new RadioButton(annotDict, _owner); } else { annot = new CheckBox(annotDict, _owner); } break; } } break; } if (annot != null) { annot.SetPage(_page, false); _annotations.Add(annot); } } } } } }