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
  • submit to reddit
Cormac Reynolds 11/08/14
2357 views
0 replies

5 Cool Gadgets to Come from Kickstarter

Over the last period of time we’ve seen some awesome tech innovations thanks to these crowdbacked projects and many have come to fruition and are now sold across the web.

Avinash Babu11/08/14
1549 views
0 replies

Controlling Appliances Using Java and IoT

The proliferation of internet-connected devices, from cars to heart monitors that interact without human intervention, is creating new possibilities in data gathering, predictive analytics and IT automation. Smart Home, Smart Refrigerator, Connected cars, etc., are some of the IoT gadgets that have come up and created hype in the market.

//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")
Evan Leybourn11/07/14
84 views
0 replies

Introduction to Scrum - Released under Creative Commons

As part of an ongoing release of all my training material, I am releasing "Introduction to Scrum" under a Creative Commons Attribution Share-Alike license. That is, you are free to share, copy, and adapt any part of this training course for...

Highq Collaborate11/07/14
431 views
0 replies

Enterprise collaboration news: October 2014 round-up

The festive season seems to start earlier and earlier each year, and this year the early-onset holiday spirit seems to have brought with it speculation about what’s to come in the future. Below are three areas of projections we’ve picked out of October’s news cycle.

Adi Gaskell11/07/14
347 views
0 replies

Bringing vocal collaboration to document sharing

Earlier this month I looked at a new collaboration service called Talko. The service, which was developed by former Microsoft chief architect Ray Ozzie, aims to bring the spoken word into the kind of collaboration tools that have become common in our workplaces.

Mark Morrell11/07/14
299 views
0 replies

SharePoint, Office 365 and moving to the Cloud

I was asked by Fredric Landqvist, my good friend and Information Architecture genius, to contribute to a series of posts on the challenges organisations face as they move from having online content and tools hosted firmly on their estate to renting space in the cloud.

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.regex.Pattern;


public class RegexHashMap<V> implements Map<String, V>
{
	private class PatternMatcher
	{
		private final String regex;
		private final Pattern compiled;
		
		PatternMatcher(String name)
		{
			regex = name;
			compiled = Pattern.compile(regex);
			
		}
				
		boolean matched(String string)
		{
			if(compiled.matcher(string).matches())
			{
				ref.put(string, regex);
				return true;
			}
			return false;
		}
	}
	/**
	 * Map of input to pattern
	 */
	private final Map<String, String> ref;
	
	/**
	 * Map of pattern to value
	 */
	private final Map<String, V> map;
	
	/**
	 * Compiled patterns
	 */
	private final List<PatternMatcher> matchers;
	
	@Override
	public String toString()
	{
		return "RegexHashMap [ref=" + ref + ", map=" + map + "]";
	}

	/**
	 * 
	 */
	public RegexHashMap()
	{
		ref = new WeakHashMap<>();
		map = new HashMap<>();
		matchers = new ArrayList<>();
	}
			
	/**
	 * Returns the value to which the specified key pattern is mapped, or null if this map contains no mapping 
 		for the key pattern
	 */
	@Override
	public V get(Object weakKey)
	{
		if(!ref.containsKey(weakKey))
		{
			for(PatternMatcher matcher : matchers)
			{
				if(matcher.matched((String) weakKey))
				{
					break;
				}
			}
			
		}
		if(ref.containsKey(weakKey))
		{
			return map.get(ref.get(weakKey));
			
		}
		return null;
	}
	
	/**
	 * Associates a specified regular expression to a particular value
	 */
	@Override
	public V put(String key, V value)
	{
		V v = map.put(key, value);
		if (v == null)
		{
			matchers.add(new PatternMatcher(key));
		}
		return v;
		
	}

	/**
	 * Removes the regular expression key
	 */
	@Override
	public V remove(Object key) 
	{
		V v = map.remove(key);
		if(v != null)
		{
			for(Iterator<PatternMatcher> iter = matchers.iterator(); iter.hasNext();)
			{
				PatternMatcher matcher = iter.next();
				if(matcher.regex.equals(key))
				{
					iter.remove();
					break;
				}
			}
			
			for(Iterator<Entry<String, String>> iter = ref.entrySet().iterator(); iter.hasNext();)
			{
				Entry<String, String> entry = iter.next();
				if(entry.getValue().equals(key))
				{
					iter.remove();
				}
			}
		}
		return v;
        
    }
	/**
	 * Set of view on the regular expression keys
	 */
	@Override
	public Set<java.util.Map.Entry<String, V>> entrySet()
	{
		return map.entrySet();
	}

	@Override
	public void putAll(Map<? extends String, ? extends V> m) 
	{
		for(Entry<? extends String, ? extends V> entry : m.entrySet())
		{
			put(entry.getKey(), entry.getValue());
		}
    }

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

	@Override
	public boolean isEmpty()
	{
		return map.isEmpty();
	}

	/**
	 * Returns true if this map contains a mapping for the specified regular expression key.
	 */
	@Override
	public boolean containsKey(Object key)
	{
		return map.containsKey(key);
	}
	
	/**
	 * Returns true if this map contains a mapping for the specified regular expression matched pattern.
	 * @param key
	 * @return
	 */
	public boolean containsKeyPattern(Object key)
	{
		return ref.containsKey(key);
	}

	@Override
	public boolean containsValue(Object value)
	{
		return map.containsValue(value);
	}

	@Override
	public void clear()
	{
		map.clear();
		matchers.clear();
		ref.clear();
	}
	
	/**
	 * Returns a Set view of the regular expression keys contained in this map.
	 */
	@Override
	public Set<String> keySet()
	{
		return map.keySet();
	}
	
	/**
	 * Returns a Set view of the regex matched patterns contained in this map. The set is backed by the map, so changes to 
 		the map are reflected in the set, and vice-versa.
	 * @return
	 */
	public Set<String> keySetPattern()
	{
		return ref.keySet();
	}

	@Override
	public Collection<V> values()
	{
		return map.values();
	}
	
	/**
	 * Produces a map of patterns to values, based on the regex put in this map
	 * @param patterns
	 * @return
	 */
	public Map<String, V> transform(List<String> patterns)
	{
		for(String pattern : patterns)
		{
			get(pattern);
		}
		
		Map<String, V> transformed = new HashMap<>();
		for(Entry<String, String> entry : ref.entrySet())
		{
			transformed.put(entry.getKey(), map.get(entry.getValue()));
		}
		return transformed;
		
	}
	public static void main(String...strings)
	{
		RegexHashMap<String> rh = new RegexHashMap<>();
		rh.put("[o|O][s|S][e|E].?[1|2]", "This is a regex match");
		rh.put("account", "This is a direct match");
		System.out.println(rh);
		System.out.println("get:ose-1 -> "+rh.get("ose-1"));
		System.out.println("get:OSE2 -> "+rh.get("OSE2"));
		System.out.println("get:OSE112 -> "+rh.get("OSE112"));
		System.out.println("get:ose-2 -> "+rh.get("ose-2"));
		System.out.println("get:account -> "+rh.get("account"));
		System.out.println(rh);
	}

}
Erich Styger11/07/14
715 views
0 replies

USB CDC with the FRDM-K64F, finally!

Sometimes I think that a problem should be solvable in a few minutes, and then it turns out that it lingers around for months. Very, very frustrating! Such a thing is getting the USB 4.1.1 stack running on the FRDM-K64F board. I have that board since April 2014, and it took me 7 months to get the FSL USB stack running on it.

Deon Thomas11/07/14
23984 views
11 replies

A Good Programmer: Why You Need to Avoid Being One

I’ve worked with what I consider to be good software programmers but are they really good programmers? What makes them so good? (and maybe, are they just average?)

John Cook11/07/14
4391 views
0 replies

How well does sample range estimate range?

I’ve been doing some work with Focused Objective lately, and today the following question came up in our discussion. If you’re sampling from a uniform distribution, how many samples do you need before your sample range has an even chance of covering 90% of the population range?

Joydeep Das11/07/14
995 views
0 replies

Understanding the Execution Plan [When Table JOIN Occurs Part-III]

Continuing our journey here we see some others operators exist in our execution plan. Here is the query and Execution Plan that we are working from couple of weeks.

Rick Delgado11/06/14
431 views
0 replies

The Special Security Considerations For Flash Storage

Protecting data on flash storage is something all companies should strive for. Flash array storage performs better than hard drive, is more easily scalable, and faster, so figuring out how to secure it will help a business protects its assets better. With more secure operations, organizations will be able to focus on other endeavors to move forward with confidence.

Michael Georgiou11/06/14
10983 views
8 replies

Why JavaScript Is and Will Continue to Be the First Choice of Programmers

The software industry is constantly evolving. Many languages that were cutting edge just a few years ago either look outdated or have been made completely redundant today. But not JavaScript.

Adi Gaskell11/06/14
669 views
0 replies

Are we too obsessed with idea generation?

Recently I was notified of a new project called Ideapod, which is branding itself as a social network for ideas. The aim is that people will share their ideas, via a short and pithy 1,000 character limited post, albeit one that can be embellished with photos, videos and the like.

Oscar Berg11/06/14
887 views
0 replies

5 ways your organization shouldn’t approach social

Many organizations see no big change in the existing ways of working after deploying social tools or social collaboration initiatives.

Adi Gaskell11/06/14
555 views
0 replies

Why digital natives need support if they’re to transform the workplace

The millennial generation have quite a hefty weight on their shoulders. There are many that think that this digital native generation will herald a new dawn in the workplace.

Bloomfire Marketing11/06/14
354 views
0 replies

How to Automate the Boring Parts of Your Business

You’re an entrepreneur because you love what you do. But do you also love all of the time-heavy admin that comes with running a business? If you’re reading this article, I’m guessing your answer is: not likely.

Christopher Blake11/06/14
366 views
0 replies

How IBM Connections Cloud & Microsoft Office 356 Collaborative Environments are NOT the same

While both IBM Connections Cloud & MSFT Office 365 provide essentially similar features, which platform or product set is; * easier to use, Microsoft Office 365 or IBM Connections Cloud? * more likely to be used and integrated into people’s work practices, * more likely to drive the change required away from eMail as a traditional method of distributing files and collaboration, towards more productive knowledge capture, management and collaboration?