» Archive for the 'tutorial' Category

PdftoTiff-Free windows software to convert PDF to Tiff

Thursday, February 14th, 2008 by rubypdf

This is just a example that show how to convert all pages of a given pdf to single page tiffs(to a given folder).
it uses pdftoppm(part of xpdf) and pnmtotiff(part of netpbm).
If you do not want download xpdf and netpbm but want to have a test, please download it here(pdftotiff0.1, 730K), it only includes pdftoppm.exe, pnmtotiff.exe, libnetpbm10.dll, jpeg62.dll, libtiff3.dll, zlib1.dll and a batch file.
btw, base on this example, you can easily implement pdftojpeg, pdftopng, pdftojbig, pdftotiffcmyk and so on.

rem create folder
md %2
rem convert pdf page to ppm
pdftoppm -r 100 %1 %2\1
rem convert ppm to tiff
for %%i in (%2\*.ppm) do echo pnmtotiff -color %%i>%2\%%~ni.tif
rem delete ppm
del /q %2\*.ppm

reference,
xpdf
NetPbm for Windows

PdftoImage-Convert PDF to Image by using PdfRenderer library

Wednesday, January 30th, 2008 by rubypdf

Bases on PDF Renderer library, we can easily develop many useful tools. Here is a example I wrote today, the aim is converting every pages of a pdf to images (png, if you need other format, you can use JAI).

import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
 
import javax.imageio.ImageIO;
 
import com.sun.pdfview.PDFFile;
import com.sun.pdfview.PDFPage;
 
 
public class Pdf2Image {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if(args.length!=2)
		{
			System.err.println("Usage:Pdf2Image pdf imageFolder");
			return;
		}
		File file = new File(args[0]);
		RandomAccessFile raf;
		try {
			raf = new RandomAccessFile(file, "r");
 
			FileChannel channel = raf.getChannel();
			ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
			PDFFile pdffile = new PDFFile(buf);
			// draw the first page to an image
			int num=pdffile.getNumPages();
			for(int i=0;i<num;i++)
			{
				PDFPage page = pdffile.getPage(i);
 
				//get the width and height for the doc at the default zoom				
				int width=(int)page.getBBox().getWidth();
				int height=(int)page.getBBox().getHeight();				
 
				Rectangle rect = new Rectangle(0,0,width,height);
				int rotation=page.getRotation();
				Rectangle rect1=rect;
				if(rotation==90 || rotation==270)
					rect1=new Rectangle(0,0,rect.height,rect.width);
 
				//generate the image
				BufferedImage img = (BufferedImage)page.getImage(
							rect.width, rect.height, //width & height
							rect1, // clip rect
							null, // null for the ImageObserver
							true, // fill background with white
							true  // block until drawing is done
					);
 
				ImageIO.write(img, "png", new File(args[1]+i+".png"));
			}
		} 
		catch (FileNotFoundException e1) {
			System.err.println(e1.getLocalizedMessage());
		} catch (IOException e) {
			System.err.println(e.getLocalizedMessage());
		}
	}
}

Source Code of PDF2Image

How to Make Adobe Reader Remember Your Page

Wednesday, January 16th, 2008 by rubypdf

Adobe reader 8 supports “Restore last view settings when reopening documents”, so you can easily remember the page number that you read last time(as well as the zoom and pan settings). But by default, it does not enable the feature, so need we do some configure, the steps are as follow,
Click Edit > Preferences, choose Documents, and then check the box marked, “Restore last view settings when reopening documents.
Free free to have a look the screen shots.

bookmark_1.jpg bookmark_2.jpg

That’s it! Sometimes the best hacks are the simplest ones.

If your Adobe Reader version is lower than 8.0, please try this javascript plugin,

Download bookmark_page.js-1.0.zip. Unzip it, and then copy it into your Acrobat or Reader JavaScripts directory. Restart Acrobat/Reader, and bookmark_page.js will add new items to your View menu(from screen shot, you can find there are 4 menus under rotate view menu). bookmark_3.jpg