当前位置: 首页>>代码示例>>Java>>正文


Java PDFPage.getHeight方法代码示例

本文整理汇总了Java中com.sun.pdfview.PDFPage.getHeight方法的典型用法代码示例。如果您正苦于以下问题:Java PDFPage.getHeight方法的具体用法?Java PDFPage.getHeight怎么用?Java PDFPage.getHeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.pdfview.PDFPage的用法示例。


在下文中一共展示了PDFPage.getHeight方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);

}
 
开发者ID:synergynet,项目名称:synergynet3.1,代码行数:71,代码来源:PDFViewerItem.java

示例2: print

import com.sun.pdfview.PDFPage; //导入方法依赖的package包/类
/**
 * Prints the PDF for the given printing context, moving it according to what was set with {@link #setCalX(int)} and {@link #setCalY(int)}.
 * <p>
 * Generally don't resize the PDF to fit to the page format. The jasper was made to have a particular size.<br>
 * However, as we always scaled to the page format in the past and some jaspers might rely on it, we do scale *down* if the PDF is bigger than the page format. Note that we only scale if both the
 * page format's height *and* width are smaller.
 * <p>
 * Originally taken from http://www.javaworld.com/javaworld/jw-06-2008/jw-06-opensourcejava-pdf-renderer.html?page=5
 */
@Override
public int print(final Graphics g, final PageFormat format, final int index) throws PrinterException
{
	final int pagenum = index + 1;
	if (pagenum < 1 || pagenum > pdfFile.getNumPages())
	{
		return NO_SUCH_PAGE;
	}

	final PDFPage pdfPage = pdfFile.getPage(pagenum);

	// task 08618: generally don't resize the PDF to fit to the page format. The jasper was made to have a particular size.
	//
	// However, as we always scaled to the page format and some jaspers might rely on it,
	// we do scale *down* if the PDF is bigger than the page format.
	// note that we only scale if both the page format's height *and* width are smaller
	final Dimension scaledToPageFormat = pdfPage.getUnstretchedSize(
			(int)format.getImageableWidth(),
			(int)format.getImageableHeight(),
			pdfPage.getPageBox());

	final int widthToUse;
	final int heightToUse;
	if (scaledToPageFormat.getWidth() <= pdfPage.getWidth()
			&& scaledToPageFormat.getHeight() <= pdfPage.getHeight())
	{
		// scale down to fit the page format
		widthToUse = (int)scaledToPageFormat.getWidth();
		heightToUse = (int)scaledToPageFormat.getHeight();
	}
	else
	{
		// *don't* scale up to fit the page format
		widthToUse = (int)pdfPage.getWidth();
		heightToUse = (int)pdfPage.getHeight();
	}

	final Rectangle bounds = new Rectangle(
			(int)format.getImageableX() + calX,
			(int)format.getImageableY() + calY,
			widthToUse,
			heightToUse);

	final Graphics2D g2d = (Graphics2D)g;

	final PDFRenderer pdfRenderer = new PDFRenderer(
			pdfPage,
			g2d,
			bounds,
			null, // Rectangle2D clip
			null // Color bgColor
	);

	try
	{
		pdfPage.waitForFinish();
		pdfRenderer.run();
	}
	catch (final InterruptedException ie)
	{
		throw new RuntimeException(ie);
	}

	// debugging: print a rectangle around the whole thing
	// g2d.draw(new Rectangle2D.Double(
	// format.getImageableX(),
	// format.getImageableY(),
	// format.getImageableWidth(),
	// format.getImageableHeight()));

	return PAGE_EXISTS;
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:82,代码来源:PrintablePDF.java


注:本文中的com.sun.pdfview.PDFPage.getHeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。