Saturday, April 9, 2011

Saving EPS files from Powerpoint

The newer versions of Microsoft Powerpoint (2007+) offer a simple and intuitive interface to quickly create nice illustrations. It would be really nice if you could use this to create diagrams for paper submissions to conferences/journals.
If you want to import pptx diagrams into your papers, typically, the best way is to export as pdf (Microsoft has an export to pdf plugin). Now you could simply import the pdf images in your Latex file, and things work pretty well.
The only hitch is that many conference templates enforce eps images. Now most paths that convert pptx->pdf->eps completely mess up the image. Sometimes the pdf may be converted into a Huge bitmap in the eps file. We certainly don't want that. Here is a technique that you can use to directly convert pptx drawings to eps, while keeping the vector format. No more "Yuck! Bitmap..." comments from your advisor :) ... and you don't have to tell Microsoft Haters that you used Powerpoint :) and that you converted it to eps using tools that come by default with Windows ;)

Anyway, before I begin, here are the places from where I picked up this info (everything is just a web-search away):
http://people.csail.mit.edu/dalleyg/faqs/20010425.html
http://www.sketchpad.net/postscript-printer-winxp-1.htm

Note: I am using Win7 & Office 2010, so some things may be a bit different in other versions.

Now the first step is to create an EPS File Printer. (Yes you can do that)
Go to 'Control Panel'->'Devices and Printers'->[Right Click]->'Add a Printer'
Click 'Add a local printer'.
Choose 'Use an existing port'->'FILE: Print to File'
Pick some printer that has a 'PS' suffix to it.
Now this may take some trial and error to find a color printer with decent number of options.


You can print a test page and check if things are working now. (Just save the page as a .eps file). To view this, you may need to install GhostScript & GhostView on Windows. Linux should have this by default.

Now to prepare the PPT diagram for printing:
Create a blank presentation.
Select 'Design' -> 'Slide Orientation' -> 'Portrait'
(This is the only limitation I came across. In Landscape mode, the EPS printer rotates the image through 270 degrees)
Select 'Design' -> 'Page Setup'
Setup the page dimensions here (This should be the boundary of your diagram)

Now copy-paste the actual drawing into this slide from wherever you created it.
(The reason for this is, if you draw first and then rescale the page size, it will stretch the diagram. Maybe there is a workaround for this.)

Now select 'Print', and pick the PS printer from the list.
Select 'Printer Properties'->'Advanced'

Setup the PostScript options as shown in this screenshot:

The Postscript output option should be EPS.
Postscript language level be 1 (could be higher I suppose, but this is safer)
TrueType font download options: Outline (This converts fonts to curves I guess. Play around with other options if you want, but stay away from 'Bitmap' of course).

As shown in the next image, set the Paper Size to 'Postscript custom page size'. Keep this the same as your Slide dimensions, because this will be the size of the CropBox in the EPS file.


Now we are all set. Just click 'Print' and save the file with a .eps extension.
GhostView correctly rendered this file for me, and the file size was reasonable.

Note however, that eps is limited in its ability to handle transparency (i think there is no transparency whatsoever), and gradients, so try to use solid colors in the drawings.

Let me know how this goes for you :)

Thursday, April 7, 2011

How to use Windows Phone 7 Marketplace in India

Having recently 'procured' a HTC HD7, I was hoping to post a review of some sort on this blog. But none of my review plans (for this phone, the PS3 and a few PC games) seem to materialize in any reasonable time frame, so here are some tricks for anyone finding themselves in the less than desirable position of owning a Windows Phone 7 device in India.

[ Feel free to skip over this next part. Just scroll over to the 'End of Rant' below ]

Well, here is the fundamental problem: Smartphones are not much if you can't run applications on them. And Microsoft decided that it would be a very prudent move to sell WP7 phones in India, without any app-store support. (FYI, Microsoft has screwed over users in many countries like this, so this is certainly not a special case).

Here is how things typically play out:
Step1: You shell out 25,000/- for a WP7 of your choice.
Step2: You start the phone, and it tells you to sign in with your 'Live ID'. You can create one if you don't have it. I have a Hotmail account since the Stone age, and decided to use that.
Step3: You decide you want some apps, and click on the Marketplace icon. You are greeted with a message that says 'Marketplace is not yet available in your country/region'
Step4: Ah! But we are clever, no? Simply have to change the country to 'USA'. The country is tied to your Live ID. Once you create it, you can't change the country. So, we go and create a new Live ID. I, for instance, am a retired Sith Lord living a peaceful life in Kansas...
Step5: Oops. You can't change the first Live ID that you used in the phone. It is now inexorably tied to the phone. What do we do now?
Step6: Factory Reset the phone. This will clear everything (all photos,videos,music,downloaded apps, mail, settings...the whole shebang) And how do we do that? Quite intuitive really. Go to Settings -> about -> reset your phone. ('About'?!! seriously Microsoft??)
Step7: Now you enter your new Live ID details. This works great on your phone, except that you can't really buy any apps because everything is listed in Dollars, and Microsoft does not support credit cards outside your region. Now all you need is an obliging chap with an American credit card. Yeah right...

[ End of Rant ]

Now for the good news: There actually IS an app-store for India, where everything is listed in INR and leprechauns stash heaps of gold at the ends of rainbows.
The problem is that the Phone does not seem to acknowledge its existence. The only way to access this store is through Zune Software (MS equivalent of iTunes).
You can login on Zune, using your India based Live ID, and it will (sometimes) show you the Marketplace.
I say Sometimes, because Zune has this nasty habit of setting some registry entries that removes India (IN) from the list of valid Marketplace regions. There is a nice hack described HERE, to overcome it.

A short summary of the registry tweak:
Go to this registry key: HKEY_CURRENT_USER\Software\Microsoft\Zune\Features

Here you will see the codes of the following countries in 3 entries:
AT,AU,BE,CA,CH,DE,ES,FR,GB,IE,IT,MX,NL,NZ,SG,US

Just add IN to all the entries, so they become: AT,AU,BE,CA,CH,DE,ES,FR,GB,IE,IT,MX,NL,NZ,SG,US,IN

These guys have even made a helpful reg file: Here

Now for my trick: When you purchase/download apps from Zune Marketplace, they don't always turn up on your phone. Infact, the phone starts downloading these apps in its download manager, and sometimes the downloads stop due to network errors or whatever. Typically, you would simply resume the download by going to the Marketplace through your phone. But you can't open the official Marketplace app on your phone...

The trick is to simply install a 3rd party marketplace app through Zune (there are 3 or 4 marketplace search apps which should install fairly quickly). HTC phones come preloaded with 'HTC Hub' from which you can access some apps. Just find an app listed on one of these marketplace apps, download that app from Zune Software on your PC (while your phone is connected of course), and now you should see a 'check install' button on that app, in your 3rd party marketplace app on the phone.
Clicking this takes you to the Download manager, where you can resume/pause/cancel (oh wait, no you can't cancel downloads... another brilliant feature).

Anyway, if someone knows a better way to get the Marketplace working properly in India, do let me know...

Tuesday, January 4, 2011

Automating tasks in Outlook using VB for Applications

It has been ages since I wrote anything on this blog...
Since a lot of people at work may be using the Outlook mail client, I thought it would be useful to introduce the scripting capabilities that Visual Basic for Applications (VBA) offers in Outlook. (This is also the first post where I will be using the code->HTML converter from Notepad++. Trying this as an alternative to vim. Let me know what you think.)

This post demonstrates a simple script to delete duplicate emails in an Outlook folder. While this seems quite specific, it should present enough info for you to get started with VBA for Outlook. So here goes:

Hmm, why would anyone want to do Visual Basic scripting in Outlook??

I have long been a proponent of VBA (Visual Basic for Applications), specially in MS Excel and CorelDraw, but only recently have I got my hands dirty with Outlook.

The problem I faced a while back was that I accidentally created two copies of every email in my conversations folder. There being around 250 items to sift through, I decided it would be better to spend a half hour learning how to write Outlook macros, than to find and delete the duplicate items.

So, lets get down to business. To write a macro in Outlook, go to Tools->Macros->Visual Basic Editor.

In the Project window, select Project1->Microsoft Office Outlook->ThisOutlookSession. You should be presented with a code window, where you will write the macro.

The macro will be a VB subroutine. In this post, I will discuss how to write a macro that moves only duplicate emails to some folder of your choice (maybe trash). We could delete the emails instead, but I usually refrain from writing destructive statements in code, atleast until it is fully tested ;)

Before we start off, this is the URL that I referred to for help: http://support.microsoft.com/?kbid=208520

I will provide the code listing below, with inline comments (comment lines start with an apostrophe in VB).

'We start off with the name of the subroutine,
'Also make it public, so outlook can access it.
'Sub means Subroutine
Public Sub deleteDuplicateMails()

'Now for some variable declarations.
'Note that this is not needed in VB, but
'its a good practice, and also helps VB to
'autocomplete your code.
Dim oldEmail As MailItem, newEmail As MailItem
Dim i As Integer, dupcount As Integer, totalcount As Integer
Dim folder1 As Folder, folder2 As Folder
Dim myfolder As Folder, dupfolder As Folder

'Now, we need to access the folders where
'emails are stored. The following lines do that.

'This is to help VB access the stuff inside outlook
'MAPI is "Messaging Application Programming Interface"
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")

'Note: I am assuming these folders and subfolders
'already exist. The code won't run otherwise.
'We could make it more robust, and create
'the folders here, but thats too much work :P

'set the source folder
Set folder1 = olns.Folders("Personal Folders")
'go to subfolder inside folder1
Set myfolder = folder1.Folders("Conversations")

'set the destination folder
Set folder2 = folder1.Folders("Deleted Items")
'again, we want a subfolder here
Set dupfolder = folder2.Folders("Conversations")


'sort items based on sent-on date and time
Set myitems = myfolder.Items
myitems.Sort "[SentOn]", olAscending

'iterate through mails, checking for duplicates
totalcount = myitems.Count
dupcount = 0

'start from end and go towards first item, deleting duplicates from the end
For i = totalcount - 1 To 1 Step -1 'assuming there are atleast 2 emails
Set oldEmail = myitems(i)
Set newEmail = myitems(i + 1)

'check if 2 emails are same
If (oldEmail.ConversationTopic = newEmail.ConversationTopic) And _
(oldEmail.SentOn = newEmail.SentOn) _
Then
'no short circuit of boolean expressions, so we have inner if statement
'len(oldEmail.Body): comparing message length, faster than full string compare
If (Len(oldEmail.Body) = Len(newEmail.Body)) Then
dupcount = dupcount + 1
newEmail.Move dupfolder
End If
End If

Next i

MsgBox "Duplicates: " & dupcount

'clean up any references
Set myitems = Nothing
Set myfolder = Nothing
Set dupfolder = Nothing
Set folder2 = Nothing
Set folder1 = Nothing
Set olns = Nothing
Set ol = Nothing
End Sub

And that completes the code. VBA can be used to write all kinds of neat macros that speed up day to day tasks. Finding duplicate mails is just one of them.