本文整理汇总了Java中org.icepdf.core.pobjects.PDimension类的典型用法代码示例。如果您正苦于以下问题:Java PDimension类的具体用法?Java PDimension怎么用?Java PDimension使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PDimension类属于org.icepdf.core.pobjects包,在下文中一共展示了PDimension类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toBufferedImage
import org.icepdf.core.pobjects.PDimension; //导入依赖的package包/类
private static BufferedImage toBufferedImage(Document document, int pageNumber,float scale,boolean transparent) {
System.getProperties().put("org.icepdf.core.screen.background", "VALUE_DRAW_NO_BACKGROUND");
Catalog cat = document.getCatalog();
Page page = cat.getPageTree().getPage(pageNumber-1, document);
PDimension sz = page.getSize(Page.BOUNDARY_CROPBOX, 0f, scale);
int pageWidth = (int) sz.getWidth();
int pageHeight = (int) sz.getHeight();
BufferedImage image = new BufferedImage(pageWidth,
pageHeight,
transparent?BufferedImage.TYPE_INT_ARGB:BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
if (!transparent) {
PRectangle pageBoundary = page.getPageBoundary(Page.BOUNDARY_CROPBOX);
float x = 0 - pageBoundary.x;
float y = 0 - (pageBoundary.y - pageBoundary.height);
g.setColor(Color.WHITE);
g.fillRect((int) (0 - x),
(int) (0 - y),
(int) pageBoundary.width,
(int) pageBoundary.height);
}
page.paint(g, GraphicsRenderingHints.SCREEN,
Page.BOUNDARY_CROPBOX, 0f, scale);
g.dispose();
cat.getPageTree().releasePage(page, document);
return image;
}
示例2: call
import org.icepdf.core.pobjects.PDimension; //导入依赖的package包/类
public Void call() {
Page page = document.getPageTree().getPage(pageNumber);
// assign a metrics page loading listener
page.addPageProcessingListener(new MetricsPageLoadingListener(
document.getNumberOfPages()));
page.init();
PDimension sz = page.getSize(Page.BOUNDARY_CROPBOX, rotation, scale);
int pageWidth = (int) sz.getWidth();
int pageHeight = (int) sz.getHeight();
BufferedImage image = new BufferedImage(pageWidth,
pageHeight,
BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
page.paint(g, GraphicsRenderingHints.PRINT,
Page.BOUNDARY_CROPBOX, rotation, scale);
g.dispose();
// capture the page image to file
// try {
// System.out.println("Capturing page " + pageNumber);
// File file = new File("imageCapture_" + pageNumber + ".png");
// ImageIO.write(image, "png", file);
//
// } catch (Throwable e) {
// e.printStackTrace();
// }
image.flush();
return null;
}
示例3: call
import org.icepdf.core.pobjects.PDimension; //导入依赖的package包/类
public Void call() {
Page page = document.getPageTree().getPage(pageNumber);
page.init();
PDimension sz = page.getSize(Page.BOUNDARY_CROPBOX, rotation, scale);
int pageWidth = (int) sz.getWidth();
int pageHeight = (int) sz.getHeight();
BufferedImage image = new BufferedImage(pageWidth,
pageHeight,
BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
page.paint(g, GraphicsRenderingHints.PRINT,
Page.BOUNDARY_CROPBOX, rotation, scale);
g.dispose();
// capture the page image to file
try {
System.out.println("Capturing page " + pageNumber);
File file = new File("imageCapture_" + pageNumber + ".png");
ImageIO.write(image, "png", file);
} catch (Throwable e) {
e.printStackTrace();
}
image.flush();
return null;
}
示例4: createSVG
import org.icepdf.core.pobjects.PDimension; //导入依赖的package包/类
/**
* Creates a SVG character stream for the given <code>Document</code> and
* <code>PageNumber</code>.
*
* @param pdfDocument Document containing the PDF data
* @param pageNumber page number of PDF content that will be rendered to SVG.
* Zero-based index
* @param out character stream that the SVG data will be written to
*/
public static void createSVG(Document pdfDocument, int pageNumber, Writer out) {
try {
if (pdfDocument != null &&
(pageNumber >= 0 && pageNumber < pdfDocument.getNumberOfPages())) {
// Get a DOMImplementation
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document
org.w3c.dom.Document document = domImpl.createDocument(null, "svg",
null);
// Create an instance of the SVG Generator
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
// Ask the test to render into the SVG Graphics2D implementation
float userRotation = 0;
float userZoom = 1;
PDimension pdfDimension = pdfDocument.getPageDimension(pageNumber, userRotation, userZoom);
svgGenerator.setSVGCanvasSize(pdfDimension.toDimension());
pdfDocument.paintPage(pageNumber, svgGenerator,
GraphicsRenderingHints.PRINT,
Page.BOUNDARY_CROPBOX,
userRotation, userZoom);
// Finally, stream out SVG to the standard output using UTF-8
// character to byte encoding
boolean useCSS = true; // we want to use CSS style attribute
// File f=new File("a.svg");
// Writer out = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
svgGenerator.stream(out, useCSS);
}
} catch (org.apache.batik.svggen.SVGGraphics2DIOException e) {
logger.log(Level.SEVERE, "Error creating svg document.", e);
}
}