本文整理汇总了Java中com.sun.pdfview.PDFPage类的典型用法代码示例。如果您正苦于以下问题:Java PDFPage类的具体用法?Java PDFPage怎么用?Java PDFPage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PDFPage类属于com.sun.pdfview包,在下文中一共展示了PDFPage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: print
import com.sun.pdfview.PDFPage; //导入依赖的package包/类
@Override
public int print(Graphics g, PageFormat format, int index) throws PrinterException {
int pagenum = index + 1;
if ((pagenum >= 1) && (pagenum <= file.getNumPages())) {
Graphics2D g2 = (Graphics2D) g;
PDFPage page = file.getPage(pagenum);
Rectangle imageArea = new Rectangle((int) format.getImageableX(), (int) format.getImageableY(),
(int) format.getImageableWidth() , (int) format.getImageableHeight());
g2.translate(0, 0);
PDFRenderer pgs = new PDFRenderer(page, g2, imageArea, null, null);
try {
page.waitForFinish();
pgs.run();
} catch (InterruptedException ie) {
System.out.println(ie.toString());
}
return PAGE_EXISTS;
} else {
return NO_SUCH_PAGE;
}
}
示例2: print
import com.sun.pdfview.PDFPage; //导入依赖的package包/类
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
throws PrinterException {
// Check for a page
if(pageIndex >= pdf.getNumPages())
return NO_SUCH_PAGE;
// is this necessary?
graphics.translate(0, 0);
PDFPage page = pdf.getPage(pageIndex + 1);
PDFRenderer renderer = new PDFRenderer(page, (Graphics2D) graphics,
getImageableRectangle(pageFormat), null, Color.white);
try {
// umm... wait for finish what? Apparently this is required and not well documented!
page.waitForFinish();
renderer.run();
} catch (InterruptedException e) {
e.printStackTrace();
}
return PAGE_EXISTS;
}
示例3: toImage
import com.sun.pdfview.PDFPage; //导入依赖的package包/类
@Override
public Image toImage(byte[] input, int pageNumber) throws IOException {
File file = File.createTempFile("pdf2img", "pdf");
try{
copy(input,file);
PDFFile pdffile = toPDFFile(file);
// draw a single page to an image
PDFPage page = pdffile.getPage(pageNumber);
return toImage(page,(int)page.getBBox().getWidth(),(int)page.getBBox().getHeight(),false);
}
finally{
deleteEL(file);
}
}
示例4: writeImage
import com.sun.pdfview.PDFPage; //导入依赖的package包/类
private static void writeImage(PDFFile pdf, int pageNumber, Resource destination,String format, int scale,
boolean overwrite, boolean goodQuality, boolean transparent) throws PageException, IOException {
PDFPage page = pdf.getPage(pageNumber);
if(scale<1) throw new ExpressionException("scale ["+scale+"] should be at least 1");
int width = (int)page.getBBox().getWidth();
int height = (int)page.getBBox().getHeight();
if(scale!=100){
double s=(scale)/100d;
width= (int)((width)*s);
height= (int)((height)*s);
}
Image img=toImage(page, width, height,transparent);
img.writeOut(destination,format, overwrite, 1f);
}
示例5: 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);
}
}
}
示例6: 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;
}
}
示例7: 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));
}
示例8: 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);
}
示例9: 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;
}
示例10: PDFGlyph
import com.sun.pdfview.PDFPage; //导入依赖的package包/类
/** Creates a new instance of PDFGlyph based on a page */
public PDFGlyph(char src, String name, PDFPage page, Point2D advance) {
this.page = page;
this.advance = advance;
this.src = src;
this.name = name;
}
示例11: addCommands
import com.sun.pdfview.PDFPage; //导入依赖的package包/类
/** Add commands for this glyph to a page */
public Point2D addCommands(PDFPage cmds, AffineTransform transform, int mode) {
if (shape != null) {
GeneralPath outline= (GeneralPath) shape.createTransformedShape(transform);
cmds.addCommand(new PDFShapeCmd(outline, mode));
} else if (page != null) {
cmds.addCommands(page, transform);
}
return advance;
}
示例12: getGlyph
import com.sun.pdfview.PDFPage; //导入依赖的package包/类
/**
* Get the glyph for a given character code and name
*
* The preferred method of getting the glyph should be by name. If the
* name is null or not valid, then the character code should be used.
* If the both the code and the name are invalid, the undefined glyph
* should be returned.
*
* Note this method must *always* return a glyph.
*
* @param src the character code of this glyph
* @param name the name of this glyph or null if unknown
* @return a glyph for this character
*/
protected PDFGlyph getGlyph(char src, String name) {
if (name == null) {
throw new IllegalArgumentException("Glyph name required for Type3 font!" +
"Source character: " + (int) src);
}
PDFObject pageObj = (PDFObject) charProcs.get(name);
if (pageObj == null) {
// glyph not found. Return an empty glyph...
return new PDFGlyph(src, name, new GeneralPath(), new Point2D.Float(0, 0));
}
try {
PDFPage page = new PDFPage(bbox, 0);
page.addXform(at);
PDFParser prc = new PDFParser(page, pageObj.getStream(), rsrc);
prc.go(true);
float width = widths[src - firstChar];
Point2D advance = new Point2D.Float(width, 0);
advance = at.transform(advance, null);
return new PDFGlyph(src, name, page, advance);
} catch (IOException ioe) {
// help!
System.out.println("IOException in Type3 font: " + ioe);
ioe.printStackTrace();
return null;
}
}
示例13: forceGotoPage
import com.sun.pdfview.PDFPage; //导入依赖的package包/类
/**
* Changes the displayed page.
*
* @param pagenum
* the page to display
*/
public void forceGotoPage(int pagenum) {
if (pagenum <= 0) {
pagenum = 0;
} else if (pagenum >= curFile.getNumPages()) {
pagenum = curFile.getNumPages() - 1;
}
curpage = pagenum;
// update the page text field
pageField.setText(String.valueOf(curpage + 1));
// fetch the page and show it in the appropriate place
PDFPage pg = curFile.getPage(pagenum + 1);
if (fspp != null) {
fspp.showPage(pg);
fspp.requestFocus();
} else {
page.showPage(pg);
page.requestFocus();
}
// update the thumb panel
if (doThumb) {
thumbs.pageShown(pagenum);
}
// stop any previous page prepper, and start a new one
if (pagePrep != null) {
pagePrep.quit();
}
pagePrep = new PagePreparer(pagenum);
pagePrep.start();
setEnabling();
}
示例14: 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;
}
示例15: 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;
}