本文整理汇总了Java中com.sun.pdfview.PDFPage.getImage方法的典型用法代码示例。如果您正苦于以下问题:Java PDFPage.getImage方法的具体用法?Java PDFPage.getImage怎么用?Java PDFPage.getImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.pdfview.PDFPage
的用法示例。
在下文中一共展示了PDFPage.getImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
@Override
public void run() {
Dimension size = null;
Rectangle2D clip = null;
if (fspp != null) {
fspp.waitForCurrentPage();
size = fspp.getCurSize();
clip = fspp.getCurClip();
} else if (page != null) {
page.waitForCurrentPage();
size = page.getCurSize();
clip = page.getCurClip();
}
if (waitforPage == curpage) {
PDFPage pdfPage = curFile.getPage(prepPage + 1, true);
if (pdfPage != null && waitforPage == curpage) {
pdfPage.getImage(size.width, size.height, clip, null, true, true);
}
}
}
示例2: readPDF
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
public static Image readPDF(File f) {
try {
RandomAccessFile raf = new RandomAccessFile(f, "r");
FileChannel channel = raf.getChannel();
ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
PDFFile pdf = new PDFFile(buf);
PDFPage page = pdf.getPage(0);
Rectangle rect = new Rectangle(0, 0, (int) page.getBBox().getWidth(), (int) page.getBBox().getHeight());
Image image = page.getImage(rect.width, rect.height, rect, null, true, true);
raf.close();
return image;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例3: showCurrentPage
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
private void showCurrentPage() {
this.posLabel.setText(this.currentPage + " / " + this.pdfFile.getNumPages());
final PDFPage page = this.pdfFile.getPage(this.currentPage);
final Rectangle2D r2d = page.getBBox();
double width = r2d.getWidth();
double height = r2d.getHeight();
width /= 72.0;
height /= 72.0;
final int res = Toolkit.getDefaultToolkit().getScreenResolution();
width *= res;
height *= res;
final Image image = page.getImage((int) width, (int) height, r2d, null, true, true);
final ImageIcon icon = new ImageIcon(image);
this.contentLabel.setIcon(icon);
this.validate();
this.contentLabel.scrollRectToVisible(
new Rectangle(icon.getIconWidth() / 4, icon.getIconHeight() / 4, 1, 1));
}
示例4: getPageFromDisk
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
/**
* create the image to load
**/
private Image getPageFromDisk(int pageNum) {
PDFPage page = pdfFile.getPage(pageNum + 1);
Rectangle2D r2d = page.getBBox();
imageWidth = r2d.getWidth();
imageHeight = r2d.getHeight();
imageWidth /= PAGE_DIMENSION_RATIO;
imageHeight /= PAGE_DIMENSION_RATIO;
int res = Toolkit.getDefaultToolkit().getScreenResolution();
imageWidth *= res;
imageHeight *= res;
return page.getImage((int) imageWidth, (int) imageHeight, r2d, null,
true, true);
}
示例5: readPage
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
private static BufferedImage readPage(PDFFile pdf, int pageNumber) {
double scale = 2.5; // because otherwise the image comes out really tiny
PDFPage page = pdf.getPage(pageNumber);
Rectangle rect = new Rectangle(0, 0, (int) page.getBBox().getWidth(), (int) page.getBBox().getHeight());
BufferedImage bufferedImage = new BufferedImage((int)(rect.width * scale), (int)(rect.height * scale), BufferedImage.TYPE_INT_RGB);
Image image = page.getImage((int)(rect.width * scale), (int)(rect.height * scale), rect, null, true, true);
Graphics2D bufImageGraphics = bufferedImage.createGraphics();
bufImageGraphics.drawImage(image, 0, 0, null);
return bufferedImage;
}
示例6: createCacheVersion
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
public File createCacheVersion(Document d) throws Exception {
String docdownload = oscar.OscarProperties.getInstance().getProperty("DOCUMENT_DIR");
File documentDir = new File(docdownload);
File documentCacheDir = getDocumentCacheDir(docdownload);
log.debug("Document Dir is a dir" + documentDir.isDirectory());
File file = new File(documentDir, d.getDocfilename());
RandomAccessFile 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);
if(raf != null) raf.close();
if(channel != null) channel.close();
// long readfile = System.currentTimeMillis() - start;
// draw the first page to an image
PDFPage ppage = pdffile.getPage(0);
log.debug("WIDTH " + (int) ppage.getBBox().getWidth() + " height " + (int) ppage.getBBox().getHeight());
// get the width and height for the doc at the default zoom
Rectangle rect = new Rectangle(0, 0, (int) ppage.getBBox().getWidth(), (int) ppage.getBBox().getHeight());
log.debug("generate the image");
Image img = ppage.getImage(rect.width, rect.height, // width & height
rect, // clip rect
null, // null for the ImageObserver
true, // fill background with white
true // block until drawing is done
);
log.debug("about to Print to stream");
File outfile = new File(documentCacheDir, d.getDocfilename() + ".png");
OutputStream outs = null;
try {
outs = new FileOutputStream(outfile);
RenderedImage rendImage = (RenderedImage) img;
ImageIO.write(rendImage, "png", outs);
outs.flush();
} finally {
if (outs != null) outs.close();
}
return outfile;
}
示例7: view2
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
public ActionForward view2(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
if(!securityInfoManager.hasPrivilege(LoggedInInfo.getLoggedInInfoFromSession(request), "_edoc", "r", null)) {
throw new SecurityException("missing required security object (_edoc)");
}
String doc_no = request.getParameter("doc_no");
log.debug("Document No :" + doc_no);
LogAction.addLog((String) request.getSession().getAttribute("user"), LogConst.READ, LogConst.CON_DOCUMENT, doc_no, request.getRemoteAddr());
String docdownload = oscar.OscarProperties.getInstance().getProperty("DOCUMENT_DIR");
File documentDir = new File(docdownload);
log.debug("Document Dir is a dir" + documentDir.isDirectory());
Document d = documentDao.getDocument(doc_no);
log.debug("Document Name :" + d.getDocfilename());
// TODO: Right now this assumes it's a pdf which it shouldn't
response.setContentType("image/png");
// response.setHeader("Content-Disposition", "attachment;filename=\"" + filename+ "\"");
// read the file name.
File file = new File(documentDir, d.getDocfilename());
RandomAccessFile 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);
// long readfile = System.currentTimeMillis() - start;
// draw the first page to an image
PDFPage ppage = pdffile.getPage(0);
log.debug("WIDTH " + (int) ppage.getBBox().getWidth() + " height " + (int) ppage.getBBox().getHeight());
// get the width and height for the doc at the default zoom
Rectangle rect = new Rectangle(0, 0, (int) ppage.getBBox().getWidth(), (int) ppage.getBBox().getHeight());
log.debug("generate the image");
Image img = ppage.getImage(rect.width, rect.height, // width & height
rect, // clip rect
null, // null for the ImageObserver
true, // fill background with white
true // block until drawing is done
);
log.debug("about to Print to stream");
ServletOutputStream outs = response.getOutputStream();
RenderedImage rendImage = (RenderedImage) img;
ImageIO.write(rendImage, "png", outs);
outs.flush();
outs.close();
return null;
}
示例8: generateImages
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
/**
* Generate images.
*
* @param file
* the file
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private void generateImages(File file) throws IOException
{
contentFactory = stage.getContentFactory();
// load a pdf from a byte buffer
RandomAccessFile 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);
int numPgs = pdffile.getNumPages();
ArrayList<IImage> images = new ArrayList<IImage>();
for (int i = 0; i < numPgs; i++)
{
String pdfName = file.getName();
String imageName = pdfName + i;
if (convertedPages.containsKey(imageName))
{
images.add(generateImage(imageName, convertedPages.get(imageName), (int) pdfSizes.get(pdfName).getX(), (int) pdfSizes.get(pdfName).getY()));
pdfDimensions = pdfSizes.get(pdfName);
}
else
{
// draw the page to an image
PDFPage page = pdffile.getPage(i);
// get the width and height for the doc at the default zoom
Rectangle rect = new Rectangle(0, 0, (int) page.getBBox().getWidth(), (int) page.getBBox().getHeight());
double pw = page.getWidth() * 2;
double ph = page.getHeight() * 2;
// generate the image
Image img = page.getImage((int) pw, (int) ph, rect, null, true, true);
if (!pdfSizes.containsKey(pdfName))
{
Vector2f dimensions = new Vector2f((int) pw, (int) ph);
pdfDimensions = dimensions;
pdfSizes.put(pdfName, dimensions);
}
// save it as a file
BufferedImage bImg = toBufferedImage(img, (int) pw, (int) ph);
File imageFile = File.createTempFile(imageName, ".png");
imageFile.deleteOnExit();
ImageIO.write(bImg, "png", imageFile);
images.add(generateImage(imageName, imageFile, (int) pw, (int) ph));
}
}
raf.close();
generatePDFViewer(file.getName(), images);
}
示例9: convertToIMG
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
public static void convertToIMG(String pathpdf,String output,int s) {
File file = new File(pathpdf);
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(output+(i+1)+".png"));
s=2;
}
}
catch (FileNotFoundException e1) {
System.err.println(e1.getLocalizedMessage());
} catch (IOException e) {
System.err.println(e.getLocalizedMessage());
}
if(s==1||s==2){
JOptionPane.showMessageDialog(null,"Converted Successfully");
//JOptionPane.showMessageDialog(null, "Finished\nFile save in :\n"+output.substring(0,output.lastIndexOf("\\")));
}
//if(s==2){
//JOptionPane.showMessageDialog(null, "Finished\nFile save in :\n"+output.substring(0,output.lastIndexOf("\\")));
//}
}
示例10: convertToIMG
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
public void convertToIMG(String pathpdf,String output,int s) {
File file = new File(pathpdf);
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(output+(i+1)+".png"));
}
}
catch (FileNotFoundException e1) {
System.err.println(e1.getLocalizedMessage());
} catch (IOException e) {
System.err.println(e.getLocalizedMessage());
}
}
示例11: PdfToIMG
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
public void PdfToIMG(String pathpdf,String output) {
File file = new File(pathpdf);
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(output+(i+1)+".png"));
}
}
catch (FileNotFoundException e1) {
System.err.println(e1.getLocalizedMessage());
} catch (IOException e) {
System.err.println(e.getLocalizedMessage());
}
}
示例12: extract
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
public byte[] extract() throws IOException {
this.extracted = false;
this.preview = null;
File file = new File(this.filename);
RandomAccessFile 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);
// getPage is zero-based
PDFPage page = pdffile.getPage(this.page - 1);
// Get get the width and height for the doc at the default zoom
Rectangle r = new Rectangle(0, 0,
(int) page.getBBox().getWidth(),
(int) page.getBBox().getHeight());
this.width = r.width;
this.height = r.height;
// Generate the preview (using the original size)
Image img = page.getImage(this.width, this.height, r, null, true, true);
// Output generate preview to byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOException throwEx = null;
try {
ImageIO.write((RenderedImage)img, "png", baos);
baos.flush();
this.preview = baos.toByteArray();
this.extracted = true;
} catch (IOException ex) {
this.preview = null;
this.extracted = false;
throwEx = ex;
} finally {
baos.close();
if (throwEx != null) {
throw throwEx;
}
}
return this.preview;
}
示例13: run
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
/**
* Renders each of the pages in the PDFFile into a thumbnail. Preferentially
* works on the needdrawn thumbnail, otherwise, go in order.
*/
@Override
public void run() {
int workingon = 0; // the thumbnail we'll be rendering next.
while (anim == Thread.currentThread()) {
if (needdrawn >= 0) {
workingon = needdrawn;
needdrawn = -1;
}
// find an unfinished page
int loop;
for (loop = images.length; loop > 0; loop--) {
if (images[workingon] == null) {
break;
}
workingon++;
if (workingon >= images.length) {
workingon = 0;
}
}
if (loop == 0) {
// done all pages.
break;
}
// build the page
try {
int pagetoread = workingon + 1;
PDFPage p = file.getPage(pagetoread, true);
int wid = (int) Math.ceil((lineheight - border) * p.getAspectRatio());
int pagetowrite = workingon;
Image i = p.getImage(wid, lineheight - border, null, this, true, true);
images[pagetowrite] = i;
if (defaultNotSet) {
defaultNotSet = false;
setDefaultWidth(wid);
}
repaint();
} catch (Exception e) {
logger.log(Level.ERROR, e);
int size = lineheight - border;
images[workingon] = new BufferedImage(size, size, BufferedImage.TYPE_BYTE_BINARY);
}
}
}
示例14: showPage
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
/**
* Stop the generation of any previous page, and draw the new one.
*
* @param page
* the PDFPage to draw.
*/
public synchronized void showPage(PDFPage page) {
// stop drawing the previous page
if (currentPage != null && prevSize != null) {
currentPage.stop(prevSize.width, prevSize.height, prevClip);
}
// set up the new page
currentPage = page;
if (page == null) {
// no page
currentImage = null;
clip = null;
currentXform = null;
repaint();
} else {
// start drawing -- clear the flag to indicate we're in progress.
flag.clear();
Dimension sz = getSize();
if (sz.width + sz.height == 0) {
// no image to draw.
return;
}
// calculate the clipping rectangle in page space from the
// desired clip in screen space.
Rectangle2D useClip = clip;
if (clip != null && currentXform != null) {
useClip = currentXform.createTransformedShape(clip).getBounds2D();
}
Dimension pageSize = page.getUnstretchedSize(sz.width, sz.height, useClip);
// get the new image
currentImage = page.getImage(pageSize.width, pageSize.height, useClip, this);
// calculate the transform from screen to page space
currentXform = page.getInitialTransform(pageSize.width, pageSize.height, useClip);
try {
currentXform = currentXform.createInverse();
} catch (NoninvertibleTransformException nte) {
logger.log(Level.ERROR, nte);
}
prevClip = useClip;
prevSize = pageSize;
repaint();
}
}
示例15: createCacheVersion
import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
public File createCacheVersion(Document d, int pageNum) throws Exception{
File documentCacheDir = new File(EDocUtil.getCacheDirectory());
File file = new File(EDocUtil.getDocumentPath(d.getDocfilename()));
RandomAccessFile 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);
if(raf != null) raf.close();
if(channel != null) channel.close();
// draw the first page to an image
PDFPage ppage = pdffile.getPage(pageNum);
log.debug("WIDTH " + (int) ppage.getBBox().getWidth() + " height " + (int) ppage.getBBox().getHeight());
// get the width and height for the doc at the default zoom
Rectangle rect = new Rectangle(0, 0, (int) ppage.getBBox().getWidth(), (int) ppage.getBBox().getHeight());
log.debug("generate the image");
Image img = ppage.getImage(rect.width, rect.height, // width & height
rect, // clip rect
null, // null for the ImageObserver
true, // fill background with white
true // block until drawing is done
);
log.debug("about to Print to stream");
File outfile = new File(documentCacheDir, d.getDocfilename() + "_" + pageNum + ".png");
OutputStream outs = null;
try {
outs = new FileOutputStream(outfile);
RenderedImage rendImage = (RenderedImage) img;
ImageIO.write(rendImage, "png", outs);
outs.flush();
} finally {
if (outs != null) outs.close();
}
return outfile;
}