» Archive for January, 2008

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

Aspspider Reopen Free Asp.net 2.0 Hosting registration

Sunday, January 27th, 2008 by rubypdf

I just found aspspider reopened the free asp.net 2.0 hosting registration, it still supports Ms Sql Server Express 2005, but limits 10M space and automatically insert Kontera ad script.
btw, I installed ASProxy(a web proxy developed in ASP.NET 2.0) on my new registered one. And my another one has some PDF creation and manipulation demos base on iTextSharp.

Sun Releases 100% Java PDF Renderer and Viewer

Sunday, January 27th, 2008 by rubypdf

What is it?

The PDF Renderer is just what the name implies: an open source, all Java library which renders PDF documents to the screen using Java2D. Typically this means drawing into a Swing panel, but it could also draw to other Graphics2D implementations. We hope you will come up with cool things to do with it that we never thought of.

PDF is one of the core file formats of the Internet, so it is very important for Java programmers to be able to both read and write PDFs. Great open source libraries like iText have long handled the writing half, but until now there has not been a good way to read PDFs using open source Java libraries. It could be used to draw on top of PDFs, share them over a network, convert PDFs to PNG images, or maybe even project PDFs into a 3D scene.

Note, the PDFRenderer does not generate PDF documents, instead it views them. To generate PDFs you should try iText or one of many other great Java libraries.

What can I use it for?

Some ideas to get you started:

  • view PDFs in your own app
  • print-preview before exporting PDF files
  • render PDFs to PNGs in a server-side web application
  • view PDFs in a 3D scene
  • draw on top of PDFs and annotate them in a networked viewer

What are the runtime requirements?

The PDF Renderer requires Java 5 (Java SE 1.5). It has no other dependencies

Getting Started

Since this is the first release we don’t have much content yet. You can download the code using CVS,
read the javadocs, or try out the viewer demo. Also, please join the dev or user’s mailing list.

Our examples page has some sample code to opening PDFs in Swing, as an image, and other basic usages.

The SwingLabs PDF Renderer was originally written in 2003 by researchers at Sun Labs for an internal collaboration tool called Sun Labs Meeting Suite. It was originally targeted at output from OpenOffice, and so can support most OpenOffice PDF exports.

Sun engineer Joshua Marinacci says: “Several of us inside the desktop Java team here at Sun have been working hard on getting this released and now it’s finally here.”

“Go check it out at pdf-renderer.dev.java.net.” he adds. 

PDF is the standard way of exchanging non-interactive documents on the web, Marinacci reminds.  Everything from tax forms to clip art can be stored in PDFs. Mac OSX makes heavy use of PDF both as an asset format (the many widget images found in Aqua) and also as an ideal archive format using AppleScript workflows. PDF is everywhere.

“Once a PDF is created you know with great certainty that it will display and print exactly as you want on any platform,” he says, adding:

“Hmm. Write a PDF once and run it anywhere? Sounds like a good fit for Java! Combined with PDF writing libraries (like iText), you can do pretty much anything you want with PDFs.”

reference:
https://pdf-renderer.dev.java.net/
Sun Releases Open Source 100% Java PDF Renderer/Viewer