Pages

Saturday, January 8

JESUS YOUTH JUBILEE INTERNATIONAL CONFERENCE

hai friends here iam sharing some pictures which i take during the Jesus Youth International Jubilee conference 2010.

JESUS YOUTH JUBILEE CONFERENCE 2010 PHOTOS











jesus youth jubilee conference photos

how to convert pdf to jpeg or pdf to jpg using java program

hai friends today iam sharing some example to convert a pdf file to jpeg using java program. below java program will helpful to convert a pdf document to jpeg or jpg image.i think this code will helpful to somebody who want to convert pdf to jpeg file.

package johnmukkad.tk;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.Vector;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;

import multivalent.Behavior;
import multivalent.Context;
import multivalent.Document;
import multivalent.Node;
import multivalent.std.adaptor.pdf.PDF;

public class PDFToJPEG extends HttpServlet {

public PDFToJPEG(){

}
/*public static void main(String args[]) {
File outfile = new File("file1.jpg");

try {

PDF pdf = (PDF) Behavior.getInstance("AdobePDF", "AdobePDF", null,
null, null);
File file = new File("test2.pdf");
pdf.setInput(file);

Document doc = new Document("doc", null, null);
pdf.parse(doc);
doc.clear();

doc.putAttr(Document.ATTR_PAGE, Integer.toString(1));
pdf.parse(doc);

Node top = doc.childAt(0);
doc.formatBeforeAfter(200, 200, null);
int w = top.bbox.width;
int h = top.bbox.height;
BufferedImage img = new BufferedImage(w, h,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = img.createGraphics();
g.setClip(0, 0, w, h);

g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
Context cx = doc.getStyleSheet().getContext(g, null);
top.paintBeforeAfter(g.getClipBounds(), cx);
ImageIO.write(img, "jpg", outfile);
doc.removeAllChildren();
cx.reset();
g.dispose();

pdf.getReader().close();
outfile = null;

doc = null;
} catch (Exception e) {
}
}*/

public boolean convertPdfToJpeg(String input, String output){

boolean blnSuccess = false;
File outfile = new File(output);

PDF pdf = (PDF) Behavior.getInstance("AdobePDF", "AdobePDF", null,null, null);
File infile = new File(input);
pdf.setInput(infile);

Document doc = new Document("doc", null, null);
pdf.parse(doc);
doc.clear();

doc.putAttr(Document.ATTR_PAGE, Integer.toString(1));
pdf.parse(doc);

Node top = doc.childAt(0);
doc.formatBeforeAfter(200, 200, null);
int intImageWidth = top.bbox.width;
int intImageHeight = top.bbox.height;
BufferedImage theNewImage = new BufferedImage(intImageWidth, intImageHeight,BufferedImage.TYPE_INT_RGB);
Graphics2D loGraphics = theNewImage.createGraphics();
loGraphics.setClip(0, 0, intImageWidth, intImageWidth);
loGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
loGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
loGraphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
Context cx = doc.getStyleSheet().getContext(loGraphics, null);
top.paintBeforeAfter(loGraphics.getClipBounds(), cx);
try{
ImageIO.write(theNewImage, "jpg", outfile);
theNewImage = null;
blnSuccess = true;
}catch(ImageCreateException e){
theNewImage = null;
return(blnSuccess);
}

doc.removeAllChildren();
cx.reset();
loGraphics.dispose();

pdf.getReader().close();
outfile = null;

doc = null;
return(blnSuccess);
}

}