I have a small project that requires extracting several Unicode characters from a Word document as uncompressed high-resolution screenshots. The only problem is that I don't have Word -- nor do I run any operating system that can run Word.
Has anyone solved a similar problem? Are there any Win32::Com gurus who know the magic invocations to dump a few dozen Kana characters to images? I suspect a decent hacker could do this in 15 minutes or so, much better than the 10 hours it would take -- if I had the tools -- to convert these manually.
Drop me a line at chromatic at oreilly dot com if that's you.
#!/usr/bin/perl -w
use strict;
use Win32::Clipboard;
use Win32::GuiTest qw(FindWindowLike SetForegroundWindow SendKeys);
# Find an open Word document
my @windows = FindWindowLike(0, qr/Microsoft Word/);
# Bring Word to the foreground (with focus)
for (@windows) {
SetForegroundWindow($_);
SendKeys('%{PRTSCR}'); # Alt Print Screen
}
# Get the image from the clipboard.
my $screen = Win32::Clipboard::GetBitmap()
or die "No image captured: $!\n";
# Print the image to a file.
open BITMAP, "> screen.bmp" or die "Couldn't open bitmap file: $!\n";
binmode BITMAP;
print BITMAP $screen;
close BITMAP;
__END__
If you needed screenshots of them, could you not get the characters you needed from the PDF Unicode Charts at unicode.org? Just a thought.
Re:Could you get the characters elsewhere?
chromatic on 2004-08-18T16:14:15
Yes, that would work. However, with a couple of hundred characters, the amount of time and energy necessary for that would have been as much as the first option (entering them manually as screenshots).
Fortunately, Andrew wrote a macro and Jessamyn figured out a way to copy and paste through a different application. Problem solved.