Sunday, December 2, 2007

[Tech tips] Convert a scanned book pdf file (A3) into a sequence of individual pages (A4)

I recently needed to scan sections of a book, and compile them into a pdf file. Scanning is much faster if I scan two pages at a time (i.e. both pages, with the book flat on the scanner glass). However, the final pdf needed to be one book page per one pdf page.



I couldn't find any utilities or Acrobat functions to split scanned pdf pages in half, so I quickly wrote my own simple JavaScript for this purpose. (I have significant Java programming experience, but this was my first practical use of JavaScript--I hope I haven't made any stupid mistakes.)

Feel free to use it and modify it-- it would be great if you can post any improvements/corrections.


Script
/* Adobe Acrobat JavaScript for dividing A3 scanned pdf to A4 of half width*/

var inch = 72; var centimeter = 28.3464567;
/* ==========================*/
/* Modify the following four variables based on your own document properties */
/* Units are specified in points (i.e. 1 inch = 72 points) */
/* ==========================*/
var cropFromTop = 0.5 * centimeter;
var cropFromBottom = 3 * centimeter;
/*Smaller LR crop margin (e.g. right crop for odd pages)*/
var cropFromLRSmaller = 1 * centimeter;
/*Bigger LR crop margin (e.g. left crop for odd pages)*/
var cropFromLRBigger = 22 * centimeter;
/* ==========================*/

var originalNumPages = this.numPages;

/*the following loop processes pages from the back of the document*/
/*note that page indexes are 0-based, as is the java convention*/
/* (i.e. first page is page 0)*/
for (var i=originalNumPages-1; i >= 0; i--) {

//First: insert a duplicate page after page i
this.insertPages({
nPage: i,
cPath: this.path,
nStart: i,
nEnd: i
});

//Second: crop page i and page i+1 so that they only show the right or left half, respectively
var aRect = this.getPageBox({
cBox: "Media",
nPage: i
});
//var width = aRect[2] - aRect[0];
//var height = aRect[1] - aRect[3];

var cropOddArray =
new Array( aRect[0] + cropFromLRSmaller,
aRect[1] - cropFromTop,
aRect[2] - cropFromLRBigger,
aRect[3] + cropFromBottom);
var cropEvenArray =
new Array( aRect[0] + cropFromLRBigger,
aRect[1] - cropFromTop,
aRect[2] - cropFromLRSmaller,
aRect[3] + cropFromBottom);

this.setPageBoxes({
cBox: "Media",
nStart: i,
nEnd: i,
rBox: cropOddArray
});
this.setPageBoxes({
cBox: "Media",
nStart: i + 1,
nEnd: i + 1,
rBox: cropEvenArray
});

}




How to use the script

First, open the batch processing dialog box.



Make a new batch processing sequence.



Choose "select commands" to populate the processing sequence.



Add an "execute JavaScript" command to the processing sequence. (By the way, here, I rotate the pdf before the cropping procedure, and afterwards, run OCR.) Select the "execute JavaScript" command, and press "Edit."



Paste the JavaScript code from above into the dialog box. Don't forget to set the document margins within the script (four variables) to meet your particular needs.



The batch processing sequence should now work, when run.



Further information

Acrobat JavaScript Guide and Reference Manual
About page crop boxes

Friday, August 31, 2007

[Tech tips] How to set external monitor to primary monitor on Toshiba Portege M200

System: Toshiba Portege M200 tablet/laptop running Windows XP Tablet 2005 (SP2 equiv.)
Displays: Tablet screen (1050x1400), LCD (1280x1024)
Software: UltraVNC Viewer Win32 1.0.2
Driver: NVIDIA driver downloaded from Toshiba site (v. 6.14??)



I have been using UltraVNC to connect to my institute's application servers over VNC, but my docked tablet/LCD dual monitor setup was causing problems for the UltraVNC client. It would keep trying to put its window on my tablet screen (primary screen), which is usually oriented in portrait view, and had problems when I moved the window over to the LCD monitor (secondary screen). When I moved the window over like this, for some reason, the VNC client screen within the UltraVNC client was clipped at 1050 pixels, and everything to the right was just black (the tablet screen is 1050 pixels wide in portrait orientation).

Anyway, I was looking for a way to switch my primary and secondary monitors (i.e. in Display Properties-Settings, the option "Use this device as the primary monitor" is disabled by default for monitor 2), even though this option is disabled in the default Toshiba setup of the NVIDIA drivers.

The following solution is what I found on the net, and it seems to work fine now (i.e. external monitor 2 can be set to primary). For the Toshiba driver distribution, you have to first run the self-extracting archive file, and then terminate the installation once everything is extracted. Then, edit the .inf file in the extracted directory as described below, then, manually run the setup program in the extracted directory.



In the [nv_SoftwareDeviceSettings] section of your inf, add the following lines (or modify them if they're already there):

HKR,, IgnoreHWSelectedDeviceInSpanningMode, %REG_DWORD%, 1
HKR,, DevicesConnected, %REG_DWORD%, 255
HKR,, DualViewAllow2ndViewAsPrimary, %REG_DWORD%, 1
HKR,, DualViewAllowNonDFPAsPrimary,%REG_DWORD%, 1
HKR,, NvCplConfiguration, %REG_DWORD%, 0

Note: Some infs have more than one SofwareDeviceSettings section, customized for different cards. Make sure you modify the right one, or else modify all of them to be sure.

In the [nv_ControlPanelSettings] section of your inf, add or modify the following lines:

HKLM,"Software\NVIDIA Corporation\Global\NVTweak", NvCplDisableSpanControls,%REG_DWORD%, 0
HKLM,"Software\NVIDIA Corporation\Global\NVTweak", NvCplDualViewAllowNonDFPAsPrimary, %REG_DWORD%, 1
HKLM,"Software\NVIDIA Corporation\Global\NVTweak", NvCplDualviewMoveDesktopIcons,%REG_DWORD%, 1

Reinstall and you should be all set.

Friday, August 10, 2007

[Tech Tips] Problems with Mozy restore

I was all enthusiastic when I heard about Mozy, a new online backup service that was offering 2GB for free. Since I was just in the process of relocating from the US to Germany, and was also writing my PhD thesis at the same time, I enrolled as a second-line backup method (the first backup being an external harddisk mirror). Boy was I disappointed.

Actually, the backing up itself was no problem. It even went so well, that I shelled out the $5 a month to get unlimited storage, and also backed up all of my critical data files. That was apparently my mistake. I had 31 GB in my Mozy account, when my computer crashed (which is prone to happen when you are writing PhD theses).



The short version of the story is, I still can't restore all of my files, after over a month of pestering them.

Their system works this way--when you want to restore your files, you choose the files on their web interface, and then ask their servers to create a restore set, which is a self-extracting archive. Once this restore set is created, you get an email and can go back to their website to download it.

Well, what happens when I try to create a "restore set" to download is their servers invariably cut the process short, and I only get a portion (on the worst try, 2 MB) worth of files. Technical support has repeatedly notified me that it is a "bug" in their program and they will fix it very soon... but 40 days later, I still do not have my restore files. Luckily, my first-line backup (external harddisk) saved me, but from experience, I strongly advise against putting too much faith into Mozy (or perhaps any other service). You should definitely try out the restore process beforehand, before you actually need it.

Customer support has been lousy. Of course, I probably would not count as their best customer (I mean, 30 GB for $5/mo is a bargain), but still, when it comes to backing up critical data, you do wish they were more responsive. Every time I contact them, a new person (with a generic name--I wonder if they are contractors in India or Kenya) tells me that the problem will be solved very soon, and then nothing until I email them again. This has continued for well over a month.



40 days and counting... if they snap out of it and get their act together, I will post again here.

In the meantime, I have started using Carbonite instead. Their interface has a shell extention, and so you can browse your backed-up files in real time, in the Windows Explorer. Right now, I have uploaded 27 GB, and all of the files seem alright in Windows Explorer, so I am assuming that all is well. I will try a full restore some time soon.

Saturday, March 24, 2007

[Tech tips] Using AOL mail with IMAP

AOL/AIM is presently the only free webmail service by a large provider that allows IMAP access. I use my AIM account via IMAP to transfer large files from my primary school address, which only allows 20 MB!

Access Your AOL® & AIM® Mail Any Way and Anywhere You Want It!

P.S. I also forward everything I get to a gmail address, which provides easy search and large quota. Yahoo now provides infinite quota, so I have also set my gmail address to forward to Yahoo. Now, with duplicate and triplicate backups, I should have no worries (aside from big brother knowing about every stupid email conversation I have).

Saturday, February 3, 2007

[Tech tips] Package Reloading for Mathematica Development

One problem with developing in Mathematica has been that some operations, such as data I/O and iterative number crunching, were pretty slow. This has been resolved with J/Link, which allows very transparent use of Java classes. (If you write decent number-crunching code in Java, it runs nearly as fast as in C. It also speeds up the coding process, since Java is 100% portable, and the architecture encourages good, modular programming.)

Another problem was that you were limited to the Notebook interface. This was resolved by the GUI kit (which, by the way, seems much more stable than the horrible GUIDE module in Matlab). You can also use J/Link to integrate Mathematica with any Java interface that you program. It also allows you to take advantage of the vast amount of free Java code available online. This gives you complete universality (unlike Matlab, Mathematica can be called directly from Java. Matlab can call Java, but calling Matlab from Java is not well supported at all.)

A third problem was the lack of of a good IDE environment for programming .m files (which are Mathematica scripts, which share syntax with the Mathematica notebook .nb files). Wolfram has made a good start in addressing this by creating the Wolfram Workbench. Since it is based on Eclipse, it is already much more flexible and universal than Matlab (although, given the Mathematica integration with Swing, NetBeans may have been a better choice in the long run).



The problem I will address today is related to the development cycle. When you are developing a Mathematica .m package, it is often necessary to test new versions of a function repeatedly. You can just quit the Kernel and reload the package you are working on, but sometimes, you have a time-consuming calculation upstream of the function in question, and you do not want to throw away all the upstream results stored in memory each time you test a new version of your code.

Unfortunately, as of version 5.2, Mathematica does not provide a function to "unload" a package, or in effect to reverse the commands Needs["..."] or Get["..."] (<<). (There is a standard add-on package, cleanslate.m, in \AddOns\ExtraPackages\Utilities of the standard installation.)



The following minimal code block "un-Needs" all relevant packages and reloads the newest version of each.

Begin["Global`"];
Remove["XXX`Package1`*"];
Remove["XXX`Package2`*"];
...

$ContextPath=DeleteCases[$ContextPath,"XXX`Package1`"];
$ContextPath=DeleteCases[$ContextPath,"XXX`Package2`"];
...
Unprotect[$Packages];
$Packages=DeleteCases[$Packages,"XXX`Package1`"];
$Packages=DeleteCases[$Packages,"XXX`Package2`"];
...
Protect[$Packages];

Get["XXX`Package1`"];
Get["XXX`Package2`"];
End[];


The Begin["Global`"]...End[] is necessary if you insert this code block into a Package, with its own context.

I inserted this segment into the package body of the package which is run by ExecutionBuildCommand[] in Wolfram Workbench every time a package .m file is saved.

Now, every time I save an .m file in Wolfram Workbench, the proper .m files are unloaded and reloaded automatically, so that in the Mathematica notebook window, I can just evaluate the command again and get results from the new code.

Thursday, January 25, 2007

[Tech tips] Fixing an overheating Toshiba Portegé M200 tablet PC (2)

This is an additional note to a previous post. It is a tip on how to orient the tablet when using it upright (i.e. using it as a tablet on a book stand as depicted below, or held in your lap).

I have found out that the Portegé M200 tablet runs much cooler (and quieter) when the left side (nearest to tab key) or the back side (nearest to function keys) faces up (towards the ceiling) than if the right/bottom side faces up.

GOOD ORIENTATIONS... back side up / left side up


BAD ORIENTATIONS... front side up / right side up


The reason is easy to understand given the design of the cooling system (see pictures). Hot coolant rises up, so coolant circulates much better if the radiator is physically higher than the CPU. If you do the opposite, the heat will tend to rise towards the CPU, away from the radiator, and cooling will be less efficient.

Even if you use the tablet flat on a desk, tilting it slightly in the above orientations, with a book or something, should help to cool it too (I haven't tested this).

Monday, January 22, 2007

[Tech tips] Fixing an overheating Toshiba Portegé M200 tablet PC

[rough translation from Japanese]

I've been using my Portegé M200 tablet PC (sold in Japan as dynabook SS M200) for over a year now. It's followed me around the world, and runs through almost all of my waking hours, so it's amazing that it came this far without a hitch.

Just recently, I'd noticed that the fan was running all the time, and the exhaust was pretty hot. Then, all of a sudden, in the middle of a calculation, it just shut down without any warning. No blue screen or anything, the fan just ramped up for a second, and then everything went black, as if I had pulled the cord and removed the battery. I restarted the computer, but it would only run for a few minutes before dying in exactly the same way. I tried running it with low CPU clock, and it ran fine without this problem.

Given this, I diagnosed overheating, and proceeded to clean the cooling system. This computer does not have a fan directly on top of the CPU, but instead, leads the heat to a radiator on the very edge of the computer, and blows air through this radiator. (Photo: The X-shape bracket on the lower left is holding down the CPU. The copper heat conduit tube leads to the radiator on the lower left corner. This radiator is cooled by the main fan.)


I took out the fan and found a huge buildup of dust on the inside edge of the radiator. There was so much stuff there, completely blocking the radiator, that it's a surprise it even ran at all.(Photo: Yellow arrow, area where dust was found. Blue arrow, dust removed with a Q tip.)


After this procedure, the tablet is running just fine.

(to be continued)



+ Opening your notebook will probably void your warranty. Open at your own risk. It should be very easy to fry a chip or two with static.

+ When opening, don't forget the little screw hidden underneath the battery, and the screw in the harddisk case cover. There's another small fan on the lower plate, so carefully remove its lead from the motherboard when taking off the bottom cover.