DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets

  • submit to reddit

Recent Snippets

                    package com.pky.com;

public class StaticExample {
	public static String company = "Infosys Limited";
	public String name;
	public int id;

	public StaticExample(String name, int id) {
		this.name = name;
		this.id = id;
	}

	public void show() {
		System.out.println("Employee Name :" + name + "\nEmployee Id :" + id
				+ "\nEmployee company :" + company);
	}

	public static void main(String arg[]) {
		StaticExample se = new StaticExample("Pradeep Yadav", 99231);
		se.show();

	}
}


Output :

Employee Name :Pradeep Yadav
Employee Id :99231
Employee company :Infosys Limited                
                    Here we are using OR operator so it will return only unique value. If you need to add duplicacy too use + operator. 

#!/usr/local/bin/ruby -w


class Abc

  def display

      arr1=Array(1..10);

      arr2=Array(7..15);

      arr3=arr1|arr2;

      puts "Elements of third array are :";

      arr3.each{|i| puts i};

 
 end

end

abc=Abc.new

abc.display

Output :
Elements of third array are :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

                
                    package com.pk.com;

public class Example {
	public static void main(String[] args) {
		String s = "abc";
		String s2 = "abc";
		String s3 = new String("abc");
		if (s == s2)
			System.out.println("true");
		else
			System.out.println("false");
		if (s.equals(s2))
			System.out.println("true");
		else
			System.out.println("false");
		if (s == s3)
			System.out.println("true");
		else
			System.out.println("false");
		if (s.equals(s3))
			System.out.println("true");
		else
			System.out.println("false");
	}

}
                
                    //[C#]

/* Create a DataTable object (Employee) and add columns to it (Employee_ID, 
  * Employee_Name, Gender).   
  */
DataTable dt = new DataTable("Employee");
dt.Columns.Add("Employee_ID", typeof(Int32));
dt.Columns.Add("Employee_Name", typeof(string));
dt.Columns.Add("Gender", typeof(string));
//Add 2 rows into the DataTable object programmatically
DataRow dr = dt.NewRow();
dr[0] = 1;
dr[1] = "John Smith";
dr[2] = "Male";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 2;
dr[1] = "Mary Miller";
dr[2] = "Female";
dt.Rows.Add(dr);
// Create Document instance
Document doc = new Document();
doc.Pages.Add();
// Initializes a new instance of the Table
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
//Set column widths of the table
table.ColumnWidths = "40 100 100 100";
// Set the table border color as LightGray
table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
// set the border for table cells
table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
table.ImportDataTable(dt, true, 0, 1, 3, 3);

// Add table object to first page of input document
doc.Pages[1].Paragraphs.Add(table);
// Save updated document containing table object
doc.Save("c:/pdftest/DataIntegrated.pdf");

//[VB.NET]

'**************************************************************************
'* Create a DataTable object (Employee) and add columns to it (Employee_ID, 
'* Employee_Name, Gender).   
'**************************************************************************
Dim dt As DataTable = New DataTable("Employee")
dt.Columns.Add("Employee_ID", System.Type.GetType("System.Int32"))
dt.Columns.Add("Employee_Name", System.Type.GetType("System.String"))
dt.Columns.Add("Gender", System.Type.GetType("System.String"))
'Add 2 rows into the DataTable object programmatically
Dim dr As DataRow = dt.NewRow()
dr(0) = 1
dr(1) = "John Smith"
dr(2) = "Male"
dt.Rows.Add(dr)

dr = dt.NewRow()
dr(0) = 2
dr(1) = "Mary Miller"
dr(2) = "Female"
dt.Rows.Add(dr)

' Create Document instance
Dim doc As Document = New Document()
doc.Pages.Add()
' Initializes a new instance of the Table
Dim table As Aspose.Pdf.Table = New Aspose.Pdf.Table()
'Set column widths of the table
table.ColumnWidths = "40 100 100 100"
' Set the table border color as LightGray
table.Border = New Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5F, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray))
' set the border for table cells
table.DefaultCellBorder = New Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5F, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray))
table.ImportDataTable(dt, True, 0, 1, 3, 3)

' Add table object to first page of input document
doc.Pages(1).Paragraphs.Add(table)
' Save updated document containing table object
doc.Save("c:/pdftest/DataIntegrated.pdf")

                
                    // MainWindow.xaml

<Window x:Class="Basic_CameraViewer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="550" Width="550" 
        ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
    <Grid>
        <GroupBox Header="Connect to USB camera" Height="100" Width="150"
                  HorizontalAlignment="Left" VerticalAlignment="Top">
            <Grid>
                <Button Content="Connect" Width="75" Margin="32,19,0,0" 
                        HorizontalAlignment="Left" VerticalAlignment="Top"
                        Click="ConnectUSBCamera_Click"/>
                <Button Content="Disconnect" Width="75" Margin="32,46,0,0"
                        HorizontalAlignment="Left" VerticalAlignment="Top"
                        Click="DisconnectUSBCamera_Click"/>
            </Grid>
        </GroupBox>

        <Grid Name="CameraBox" Margin="10,105,10,166"/>

        <GroupBox Header="Function" Height="160" Width="542" Margin="0,360,0,0"
                  HorizontalAlignment="Left" VerticalAlignment="Top" >
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <ListBox Grid.Column="1" Name="ConnectedClientList"/>
                <GroupBox Grid.Column="0" Header="Set Listen Address">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <Grid Grid.Row="0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="3*"/>
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0" Content="Address"/>
                            <TextBox Grid.Column="1" Height="25" Name="IpAddressText"/>
                        </Grid>
                        <Grid Grid.Row="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="3*"/>
                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0" Content="Port"/>
                            <TextBox Grid.Column="1" Height="25" Name="PortText"/>
                        </Grid>
                        <Grid Grid.Row="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Button Grid.Column="0" Content="Start" 
                                    HorizontalAlignment="Center" VerticalAlignment="Center" 
                                    Width="75" Click="StartServer_Click"/>
                            <Button Grid.Column="1" Content="Stop" 
                                    HorizontalAlignment="Center" VerticalAlignment="Center" 
                                    Width="75" Click="StopServer_Click" />
                        </Grid>
                    </Grid>
                </GroupBox>
            </Grid>
        </GroupBox>
    </Grid>
</Window>

// MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Ozeki.Media.IPCamera;
using Ozeki.Media.MediaHandlers;
using Ozeki.Media.MediaHandlers.Video;
using Ozeki.Media.MJPEGStreaming;
using Ozeki.Media.Video.Controls;

namespace Basic_CameraViewer
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private VideoViewerWPF _videoViewerWpf;

        private BitmapSourceProvider _provider;

        private IIPCamera _ipCamera;

        private WebCamera _webCamera;

        private MediaConnector _connector;

        private MyServer _server;

        private IVideoSender _videoSender;

        public MainWindow()
        {
            InitializeComponent();

            _connector = new MediaConnector();

            _provider = new BitmapSourceProvider();

            _server = new MyServer();

            SetVideoViewer();
        }

        private void SetVideoViewer()
        {
            _videoViewerWpf = new VideoViewerWPF
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                Background = Brushes.Black
            };
            CameraBox.Children.Add(_videoViewerWpf);

            _videoViewerWpf.SetImageProvider(_provider);
        }

        #region USB Camera Connect/Disconnect

        private void ConnectUSBCamera_Click(object sender, RoutedEventArgs e)
        {
            _webCamera = WebCamera.GetDefaultDevice();
            if (_webCamera == null) return;
            _connector.Connect(_webCamera, _provider);
            _videoSender = _webCamera;

            _webCamera.Start();
            _videoViewerWpf.Start();
        }

        private void DisconnectUSBCamera_Click(object sender, RoutedEventArgs e)
        {
            if (_webCamera == null) return;
            _videoViewerWpf.Stop();

            _webCamera.Stop();
            _webCamera.Dispose();

            _connector.Disconnect(_webCamera, _provider);
        }
        #endregion

        private void GuiThread(Action action)
        {
            Dispatcher.BeginInvoke(action);
        }

        private void StartServer_Click(object sender, RoutedEventArgs e)
        {
            var ipadress = IpAddressText.Text;
            var port = int.Parse(PortText.Text);
            _server.VideoSender = _videoSender;

            _server.OnClientCountChanged += server_OnClientCountChanged;

            _server.Start();
            _server.SetListenAddress(ipadress, port);
        }

        void server_OnClientCountChanged(object sender, EventArgs e)
        {
            GuiThread(() =>
            {
                ConnectedClientList.Items.Clear();

                foreach (var client in _server.ConnectedClients)
                    ConnectedClientList.Items.Add("End point: " +
                        client.TransportInfo.RemoteEndPoint);
            });
        }

        private void StopServer_Click(object sender, RoutedEventArgs e)
        {
            _server.OnClientCountChanged -= server_OnClientCountChanged;
            _server.Stop();
        }
    }
}                
                        /** Receives info about opened and closed TopComponents from window system.
     */
    private static class WindowRegistryL implements PropertyChangeListener {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (TopComponent.Registry.PROP_TC_OPENED.equals(name)) {
                addFile((TopComponent) evt.getNewValue());
            }
        }
    }                
                    package com.sun.enterprise.resource.pool.datastructure;

import com.sun.appserv.connectors.internal.api.PoolingException;
import com.sun.enterprise.resource.ResourceHandle;
import com.sun.enterprise.resource.allocator.ResourceAllocator;
import com.sun.enterprise.resource.pool.ResourceHandler;
import com.sun.enterprise.resource.pool.datastructure.strategy.ResourceSelectionStrategy;
import com.sun.logging.LogDomains;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;

public class NonBlockingDataStructure implements DataStructure {

    private ResourceSelectionStrategy strategy;
    private final ResourceHandler handler;
    private final AtomicInteger maxSize;

    private final ConcurrentLinkedQueue<ResourceHandle> freeResourceHandles = new ConcurrentLinkedQueue<ResourceHandle>();
    private final ConcurrentLinkedQueue<ResourceHandle> allResourceHandles = new ConcurrentLinkedQueue<ResourceHandle>();

    protected final static Logger _logger =
            LogDomains.getLogger(NonBlockingDataStructure.class, LogDomains.RSR_LOGGER);

    public NonBlockingDataStructure(String parameters, int maxSize,
                                    ResourceHandler handler, String strategyClass) {
        this.maxSize = new AtomicInteger(maxSize);
        this.handler = handler;
        initializeStrategy(strategyClass);
        if (_logger.isLoggable(Level.FINEST)) {
            _logger.log(Level.FINEST, "pool.datastructure.rwlockds.init");
        }
    }

    private void initializeStrategy(String strategyClass) {
        //TODO
    }

    @Override
    public void setMaxSize(int i) {
        this.maxSize.set(i);
    }

    @Override
    public int addResource(ResourceAllocator resourceAllocator, int count) throws PoolingException {
        if(_logger.isLoggable(Level.FINE)){
            _logger.fine("addResource for "+count+" resources.");
        }
        int addedResourceHandles = 0;
        try {
            for (int i = 0; i < count && allResourceHandles.size() < maxSize.get(); i++) {
                ResourceHandle handle = handler.createResource(resourceAllocator);
                allResourceHandles.offer(handle);
                freeResourceHandles.offer(handle);
                addedResourceHandles++;
            }
        } catch (Exception e) {
            PoolingException pe = new PoolingException(e.getMessage());
            pe.initCause(e);
            throw pe;
        }
        if(_logger.isLoggable(Level.FINE)){
            _logger.fine("addResource added "+addedResourceHandles+" resources.");
        }
        return addedResourceHandles;
    }

    @Override
    public ResourceHandle getResource() {
        ResourceHandle resourceHandle = freeResourceHandles.poll();
        if (resourceHandle != null) {
            resourceHandle.setBusy(true);
            if(_logger.isLoggable(Level.FINE)){
                _logger.fine("getResource found resource.");
            }
        }
        return resourceHandle;
    }

    @Override
    public void removeResource(ResourceHandle resourceHandle) {
        if(_logger.isLoggable(Level.FINE)){
            _logger.fine("removeResource called.");
        }
        allResourceHandles.remove(resourceHandle);
        freeResourceHandles.remove(resourceHandle);
        handler.deleteResource(resourceHandle);
    }

    @Override
    public void returnResource(ResourceHandle resourceHandle) {
        if(_logger.isLoggable(Level.FINE)){
            _logger.fine("returnResource called.");
        }
        resourceHandle.setBusy(false);
        freeResourceHandles.offer(resourceHandle);
    }

    @Override
    public int getFreeListSize() {
        return freeResourceHandles.size();
    }

    @Override
    public void removeAll() {
        if(_logger.isLoggable(Level.FINE)){
            _logger.fine("removeAll called.");
        }
        Iterator<ResourceHandle> it = allResourceHandles.iterator();
        while (it.hasNext()) {
            ResourceHandle next = it.next();
            freeResourceHandles.remove(next);
            handler.deleteResource(next);
            it.remove();
        }
    }

    @Override
    public int getResourcesSize() {
        return allResourceHandles.size();
    }

    @Override
    public ArrayList<ResourceHandle> getAllResources() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
                
                    //Applying Protection on a PPTX Shapes 

//[Android]

//Open the desired presentation
PresentationEx pTemplate = new PresentationEx("AddingSlides.pptx");

//Slide object for holding temporary slides
SlideEx slide;

//Shape object for holding temporary shapes
ShapeEx shape;

//Traversing through all the slides in presentation
for(int slCount=0;slCount<pTemplate.getSlides().getCount();slCount++)
{
	//Accessing the slide in the presentation
	slide = pTemplate.getSlides().get_Item(slCount);
	
	//Traversing through all the shapes in the slides
	for (int count = 0; count < slide.getShapes().getCount(); count++)
	{
	    shape = slide.getShapes().get_Item(count);

	    //if shape is Autoshape
	    if (shape instanceof AutoShapeEx)
	    {
	        //Type casting to Auto shape and getting auto shape lock
	        AutoShapeEx Ashp = (AutoShapeEx)shape;
	        AutoShapeLockEx AutoShapeLock = Ashp.getShapeLock();

	        //Applying shapes locks
	        AutoShapeLock.setNoMove(true);
	        AutoShapeLock.setNoSelect(true);
	        AutoShapeLock.setNoResize(true);
	    }

	    //if shape is group shape
	    else if (shape instanceof GroupShapeEx)
	    {
	        //Type casting to group shape and getting group shape lock
	        GroupShapeEx Group = (GroupShapeEx)shape;
	        GroupShapeLockEx groupShapeLock = Group.getShapeLock();

	        //Applying shapes locks
	        groupShapeLock.setNoMove(true);
	        groupShapeLock.setNoSelect(true);
	        groupShapeLock.setNoResize(true);
	    }

	    //if shape is Connector shape
	    else if (shape instanceof ConnectorEx )
	    {
	        //Type casting to connector shape and getting connector shape lock
	        ConnectorEx Conn = (ConnectorEx)shape;
	        ConnectorLockEx ConnLock = Conn.getShapeLock();

	        //Applying shapes locks
	        ConnLock.setNoMove(true);
	        ConnLock.setNoSelect(true);
	        ConnLock.setNoResize(true);
	    }

	    //if shape is picture frame
	    else if (shape instanceof PictureFrameEx)
	    {
	        //Type casting to picture frame shape and getting picture frame shape lock
	        PictureFrameEx Pic = (PictureFrameEx)shape;
	        PictureFrameLockEx PicLock = Pic.getShapeLock();

	        //Applying shapes locks
	        PicLock.setNoMove(true);
	        PicLock.setNoSelect(true);
	        PicLock.setNoResize(true);
	    }
	}
}

//Saving the presentation file
pTemplate.write("locked.pptx");

//Removing Protection from the Presentation 

//Protection applied using Aspose.Slides for Android can only be removed with Aspose.Slides. To unlock a shape, set the value of the applied lock to false. The code sample that follows shows how to unlock shapes in a locked presentation.

//[Android]

//Open the desired presentation
PresentationEx pTemplate = new PresentationEx("locked.pptx");

//Slide object for holding temporary slides
SlideEx slide;

//Shape object for holding temporary shapes
ShapeEx shape;

//Traversing through all the slides in presentation
for(int slCount=0;slCount<pTemplate.getSlides().getCount();slCount++)
{
	//Accessing the slide in the presentation
	slide = pTemplate.getSlides().get_Item(slCount);
	
	//Traversing through all the shapes in the slides
	for (int count = 0; count < slide.getShapes().getCount(); count++)
	{
	    shape = slide.getShapes().get_Item(count);

	    //if shape is Autoshape
	    if (shape instanceof AutoShapeEx)
	    {
	        //Type casting to Auto shape and getting auto shape lock
	        AutoShapeEx Ashp = (AutoShapeEx)shape;
	        AutoShapeLockEx AutoShapeLock = Ashp.getShapeLock();

	        //Applying shapes locks
	        AutoShapeLock.setNoMove(false);
	        AutoShapeLock.setNoSelect(false);
	        AutoShapeLock.setNoResize(false);
	    }

	    //if shape is group shape
	    else if (shape instanceof GroupShapeEx)
	    {
	        //Type casting to group shape and getting group shape lock
	        GroupShapeEx Group = (GroupShapeEx)shape;
	        GroupShapeLockEx groupShapeLock = Group.getShapeLock();

	        //Applying shapes locks
	        groupShapeLock.setNoMove(false);
	        groupShapeLock.setNoSelect(false);
	        groupShapeLock.setNoResize(false);
	    }

	    //if shape is Connector shape
	    else if (shape instanceof ConnectorEx )
	    {
	        //Type casting to connector shape and getting connector shape lock
	        ConnectorEx Conn = (ConnectorEx)shape;
	        ConnectorLockEx ConnLock = Conn.getShapeLock();

	        //Applying shapes locks
	        ConnLock.setNoMove(false);
	        ConnLock.setNoSelect(false);
	        ConnLock.setNoResize(false);
	    }

	    //if shape is picture frame
	    else if (shape instanceof PictureFrameEx)
	    {
	        //Type casting to picture frame shape and getting picture frame shape lock
	        PictureFrameEx Pic = (PictureFrameEx)shape;
	        PictureFrameLockEx PicLock = Pic.getShapeLock();

	        //Applying shapes locks
	        PicLock.setNoMove(false);
	        PicLock.setNoSelect(false);
	        PicLock.setNoResize(false);
	    }
	}
}

//Saving the presentation file
pTemplate.write("Unlocked.pptx");
                
                    //Set Link Target to a Page in the Same Document

//The following code snippet shows you how to update a link in a PDF file and set its target to the second page of the document.

//C# Code Sample

// Load the PDF file
Document doc = new Document("Source.pdf");
// Get the first link annotation from first page of document
LinkAnnotation linkAnnot = (LinkAnnotation)doc.Pages[1].Annotations[1];
// Modification link: change link destination
GoToAction goToAction = (GoToAction)linkAnnot.Action;
// Specify the destination for link object
// The first parameter is document object, second is destination page number.
// The 5ht argument is zoom factor when displaying the respective page. When using 2, the page will be displayed in 200% zoom
goToAction.Destination = new Aspose.Pdf.InteractiveFeatures.XYZExplicitDestination(doc,1, 1, 2, 2);
// Save the document with updated link
doc.Save("PDFLINK_Modified_output.pdf");

//VB.NET Code Sample

' Load the PDF file
Dim doc As Document = New Document("source.pdf")
' Get the first link annotation from first page of document
Dim linkAnnot As LinkAnnotation = CType(doc.Pages(1).Annotations(1), LinkAnnotation)
' Modification link: change link destination
Dim goToAction As Aspose.Pdf.InteractiveFeatures.GoToAction = CType(linkAnnot.Action, Aspose.Pdf.InteractiveFeatures.GoToAction)
' Specify the destination for link object
' The first parameter is document object, second is destination page number.
' The 5ht argument is zoom factor when displaying the respective page. When using 2, the page will be displayed in 200% zoom
goToAction.Destination = New Aspose.Pdf.InteractiveFeatures.XYZExplicitDestination(doc, 1, 1, 2, 2)
' Save the document with updated link
doc.Save("PDFLINK_Modified_output.pdf") 

//Set Link Destination to a Web Address

//To update the hyperlink so that it points the web address, instantiate the GoToURIAction object and pass it to the LinkAnnotation's Action property. The following code snippet shows how to update a link in a PDF file and set its target to a web address.

//C# Code Sample

// Load the PDF file
Document doc = new Document("Source.pdf");
// Get the first link annotation from first page of document
LinkAnnotation linkAnnot = (LinkAnnotation)doc.Pages[1].Annotations[1];
// Modification link: change link action and set target as web address
linkAnnot.Action = new GoToURIAction("www.aspose.com");
// Save the document with updated link
doc.Save("PDFLINK_Modified_output.pdf");

//VB.NET Code Sample

' Load the PDF file
Dim doc As Document = New Document("source.pdf")
' Get the first link annotation from first page of document
Dim linkAnnot As LinkAnnotation = CType(doc.Pages(1).Annotations(1), LinkAnnotation)
' Modification link: change link action and set target as web address
linkAnnot.Action = New Aspose.Pdf.InteractiveFeatures.GoToURIAction("www.aspose.com")
' Save the document with updated link
doc.Save("PDFLINK_Modified_output.pdf")
 
//Set Link Target to Another PDF File

//The following code snippet shows how to update a link in a PDF file and set its target to another PDF file.

//C# Code Sample

Document document = new Document("c:/pdftest/This is a test Zoom Fit Page.pdf");
LinkAnnotation linkAnnot = (LinkAnnotation)document.Pages[1].Annotations[1];

GoToRemoteAction goToR = (GoToRemoteAction)linkAnnot.Action;
// Next line update destination, do not update file
goToR.Destination = new XYZExplicitDestination(document, 2, 0, 0, 1.5);
// Next line update file
goToR.File = new FileSpecification("c:/pdftest/PDFInput (1).pdf");

document.Save("c:/pdftest/ResultantFile.pdf");

//VB.NET Code Sample

Dim document As Document = New Document("c:/pdftest/This is a test Zoom Fit Page.pdf")
Dim linkAnnot As LinkAnnotation = TryCast(document.Pages(1).Annotations(1), LinkAnnotation)

Dim goToR As InteractiveFeatures.GoToRemoteAction = TryCast(linkAnnot.Action, InteractiveFeatures.GoToRemoteAction)
' Next line update destination, do not update file
goToR.Destination = New InteractiveFeatures.XYZExplicitDestination(document, 2, 0, 0, 1.5)
' Next line update file
goToR.File = New FileSpecification("c:/pdftest/PDFInput (1).pdf")

document.Save("c:/pdftest/ResultantFile.pdf")

//Update LinkAnnotation text color

//The Link annotation does not contain text. Text is placed in the contents of the page under the annotation. Therefore in order to change color of the text, we need to replace color of the page text instead of trying change color of the annotation. The following code snippet shows how to update the color of link annotation in PDF file.

//C# Code Sample

Document doc = new Document("AsposeCaseExample.pdf");
foreach (Annotation annotation in doc.Pages[1].Annotations)
{
    if (annotation is LinkAnnotation)
    {
        //search text under the annotation
        TextFragmentAbsorber ta = new TextFragmentAbsorber();
        Rectangle rect = annotation.Rect;
        rect.LLX -= 10;
        rect.LLY -= 10;
        rect.URX += 10;
        rect.URY += 10;
        ta.TextSearchOptions = new TextSearchOptions(rect);
        ta.Visit(doc.Pages[1]);
        //change color of the text.
        foreach (TextFragment tf in ta.TextFragments)
        {
            tf.TextState.ForegroundColor = Color.Red;
        }
    }
 
}
doc.Save("output.pdf");

//VB.NET Code Sample

Dim doc As Document = New Document("AsposeCaseExample.pdf")
For Each annotation As Aspose.Pdf.InteractiveFeatures.Annotations.Annotation In doc.Pages(1).Annotations

    If TypeOf annotation Is InteractiveFeatures.Annotations.LinkAnnotation Then

        'search text under the annotation
        Dim ta As Aspose.Pdf.Text.TextFragmentAbsorber = New Aspose.Pdf.Text.TextFragmentAbsorber()
        Dim rect As Aspose.Pdf.Rectangle = annotation.Rect
        rect.LLX -= 10
        rect.LLY -= 10
        rect.URX += 10
        rect.URY += 10
        ta.TextSearchOptions = New TextSearchOptions(rect)
        ta.Visit(doc.Pages(1))
        'change color of the text.
        For Each tf As Aspose.Pdf.Text.TextFragment In ta.TextFragments

            tf.TextState.ForegroundColor = Color.Red
        Next
    End If

Next
doc.Save("output.pdf")