Saturday, June 18, 2011

Extracting images from a PDF

I had a 140 page PDF and wanted each page as an image. Each page happened to be a scanned image, so it was as simple as extracting all images from the PDF.

Install PDF utilities
sudo apt-get install poppler-utils
Save images as jpg using pdfimages
pdfimages -j file.pdf imagename
You can also save as ppm images, which are larger than jpg but are lossless
pdfimages file.pdf imagename

Rotating Multiple Images

I had 140 images that needed to be rotated, batch style. I didn't want to rotate them one by one. I used Imagemagick to rotate them via the command line. You could also use the Nautilus Image Converter which adds Resize and Rotate Images to the context menu of images.

Install Imagemagick:
sudo apt-get install imagemagick
Rotate 90 degrees (files will be overwritten!):
mogrify -rotate 90 *.jpg
If you don't want the original files overwritten, use convert instead:
convert -rotate 90 *.jpg
Alternately, install the Nautilus Image Converter.
sudo apt-get install nautilus-image-converter
Log out / in or restart for the context menu items to show up in Nautilus. Select all the images you want to rotate, right-click and select Rotate Images.


Change the settings and rotate!

Combining PDF files with Pdftk

A user manual I downloaded was split into about 20 pages, and I wanted it combined into a single document.

Pdftk did the job.

After looking at the official examples, and since all of my PDF's were numbered sequentially, I successfully combined them all using a wildcard:
pdftk *.pdf cat output combined.pdf
If they are not numbered sequentially, you'll have to include each filename:
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
If you prefer a GUI, install PDF Chain.

Saturday, June 4, 2011

Compacting a Windows 7 Virtualbox vdi Disk Image

When you add data within a dynamically-sized Guest OS, the vdi file gets larger in the Host OS. When you delete data from within the Guest OS, the vdi file does not get smaller but retains its size. You can compact it to reduce the size and save disk space.

Most of these steps I grabbed from oracle's blog: http://blogs.oracle.com/virtualbox/entry/how_to_compact_your_virtual

  1. Within the Guest OS, delete any files you don't need. Also, run a full system cleanup (I like bleachbit).
  2. Defrag using whatever tool you prefer (I used Smart Defrag)
  3. Download SDelete, and run the following command to zero out free space:
sdelete -c
  1. Shutdown the Guest OS.
  2. From the Host OS, run:
VBoxManage modifyhd Windows7.vdi --compact
And you're done!

Virtualbox Windows 7 guest OS inaccessible after upgrade to 4.0.8

I upgraded Virtualbox to v4.0.8. The Windows 7 Guest OS booted up and shut down with no problems. The second time I tried to boot, I got the following error in the main Virtualbox window, and it said the OS was inaccessible:

Location: '/home/user/.VirtualBox/Machines/W7/W7.vbox', line 142 (3), column 36.
/home/vbox/vbox-4.0.8/src/VBox/Main/src-server/MachineImpl.cpp[679] (nsresult Machine::registeredInit()).
Result Code:
NS_ERROR_FAILURE (0x80004005)
Component:
VirtualBox
Interface:
IVirtualBox {d2de270c-1d4b-4c9e-843f-bbb9b47269ff}


This ticket solve the issue: http://www.virtualbox.org/ticket/8948

I had to edit the .vbox file to remove a "strange" character at the line specified above and once back in the Guest OS, edit the registry to fix the issue.

1. Go to HKLM\SOFTWARE\Oracle\VirtualBox Guest Additions
2. Create a string key VersionEx (use exactly this spelling)
3. Give it a reasonable value
4. Shut down the VM.

Getting VPN to work in Virtualbox Windows 7 guest OS

By default, NAT was the default Network setting for the Windows 7 guest OS. The VPN connection would not work until I changed it to Bridged Adapter.