Java Code Examples for net.sf.jasperreports.engine.PrintPageFormat#getPageWidth()

The following examples show how to use net.sf.jasperreports.engine.PrintPageFormat#getPageWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OoxmlUtils.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static PaperSizeEnum getSuitablePaperSize(PrintPageFormat pageFormat)
{
	if (pageFormat != null && pageFormat.getPageWidth() != 0 && pageFormat.getPageHeight() != 0)
	{
		long mmPageWidth = Math.round(((double)pageFormat.getPageWidth() / 72d) * 25.4);
		long mmPageHeight = Math.round(((double)pageFormat.getPageHeight() / 72d) * 25.4);

		for (PaperSizeEnum paperSize : PaperSizeEnum.values())
		{
			if (
				((paperSize.getWidth() == mmPageWidth) && (paperSize.getHeight() == mmPageHeight)) 
				|| ((paperSize.getHeight() == mmPageWidth) && (paperSize.getWidth() == mmPageHeight))
				)
			{
				return paperSize;
			}
		}
	}
	return PaperSizeEnum.UNDEFINED;
}
 
Example 2
Source File: JRViewerPanel.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected Image getPageErrorImage()
{
	PrintPageFormat pageFormat = viewerContext.getPageFormat();
	Image image = new BufferedImage(
			(int) (pageFormat.getPageWidth() * realZoom) + 1,
			(int) (pageFormat.getPageHeight() * realZoom) + 1,
			BufferedImage.TYPE_INT_RGB
			);
	
	AffineTransform transform = new AffineTransform();
	transform.scale(realZoom, realZoom);

	Graphics2D grx = (Graphics2D) image.getGraphics();
	try
	{
		grx.transform(transform);

		drawPageError(grx);
	}
	finally
	{
		grx.dispose();
	}
	
	return image;
}
 
Example 3
Source File: JRViewer.java    From nordpos with GNU General Public License v3.0 6 votes vote down vote up
protected Image getPageErrorImage()
{
	PrintPageFormat pageFormat = getPageFormat();
	Image image = new BufferedImage(
			(int) (pageFormat.getPageWidth() * realZoom) + 1,
			(int) (pageFormat.getPageHeight() * realZoom) + 1,
			BufferedImage.TYPE_INT_RGB
			);
	
	Graphics2D grx = (Graphics2D) image.getGraphics();
	AffineTransform transform = new AffineTransform();
	transform.scale(realZoom, realZoom);
	grx.transform(transform);

	drawPageError(grx);
	
	return image;
}
 
Example 4
Source File: JRPrinterAWT.java    From nordpos with GNU General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public Image printPageToImage(int pageIndex, float zoom) throws JRException
{
	PrintPageFormat pageFormat = jasperPrint.getPageFormat(pageIndex);
	
	Image pageImage = new BufferedImage(
		(int)(pageFormat.getPageWidth() * zoom) + 1,
		(int)(pageFormat.getPageHeight() * zoom) + 1,
		BufferedImage.TYPE_INT_RGB
		);

	JRGraphics2DExporter exporter = new JRGraphics2DExporter(jasperReportsContext);
	exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
	SimpleGraphics2DExporterOutput output = new SimpleGraphics2DExporterOutput();
	output.setGraphics2D((Graphics2D)pageImage.getGraphics());
	exporter.setExporterOutput(output);
	SimpleGraphics2DReportConfiguration configuration = new SimpleGraphics2DReportConfiguration();
	configuration.setPageIndex(pageIndex);
	configuration.setZoomRatio(zoom);
	exporter.setConfiguration(configuration);
	exporter.exportReport();
	
	return pageImage;
}
 
Example 5
Source File: JROdtExporter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
protected void exportPage(JRPrintPage page) throws JRException, IOException
{
	startPage = true;

	ReportExportConfiguration configuration = getCurrentItemConfiguration();
	
	PrintPageFormat pageFormat = jasperPrint.getPageFormat(pageIndex);
	
	JRGridLayout layout =
		new JRGridLayout(
			nature,
			page.getElements(),
			pageFormat.getPageWidth(),
			pageFormat.getPageHeight(),
			configuration.getOffsetX() == null ? 0 : configuration.getOffsetX(), 
			configuration.getOffsetY() == null ? 0 : configuration.getOffsetY(),
			null //address
			);

	exportGrid(layout, null);

	JRExportProgressMonitor progressMonitor = configuration.getProgressMonitor();
	if (progressMonitor != null)
	{
		progressMonitor.afterPageExport();
	}
}
 
Example 6
Source File: JRViewerPanel.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void fitPage()
{
	PrintPageFormat pageFormat = viewerContext.getPageFormat();
	float heightRatio = getPageCanvasHeight() / pageFormat.getPageHeight();
	float widthRatio = getPageCanvasWidth() / pageFormat.getPageWidth();
	setRealZoomRatio(heightRatio < widthRatio ? heightRatio : widthRatio);
}
 
Example 7
Source File: JRViewer.java    From nordpos with GNU General Public License v3.0 5 votes vote down vote up
/**
 *
*/
private void fitPage(){
	PrintPageFormat pageFormat = getPageFormat();
	float heightRatio = ((float)pnlInScroll.getVisibleRect().getHeight() - 20f) / pageFormat.getPageHeight();
	float widthRatio = ((float)pnlInScroll.getVisibleRect().getWidth() - 20f) / pageFormat.getPageWidth();
	setRealZoomRatio(heightRatio < widthRatio ? heightRatio : widthRatio);
}
 
Example 8
Source File: JRViewerPanel.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void refreshPage()
{
	if (!viewerContext.hasPages())
	{
		pnlPage.setVisible(false);
		
		if (viewerContext.getJasperPrint() != null)
		{
			JOptionPane.showMessageDialog(this, viewerContext.getBundleString("no.pages"));
		}

		return;
	}

	pnlPage.setVisible(true);

	PrintPageFormat pageFormat = viewerContext.getPageFormat();
	Dimension dim = new Dimension(
		(int)(pageFormat.getPageWidth() * realZoom) + 8, // 2 from border, 5 from shadow and 1 extra pixel for image
		(int)(pageFormat.getPageHeight() * realZoom) + 8
		);
	pnlPage.setMaximumSize(dim);
	pnlPage.setMinimumSize(dim);
	pnlPage.setPreferredSize(dim);

	long maxImageSize = JRPropertiesUtil.getInstance(viewerContext.getJasperReportsContext()).getLongProperty(JRViewer.VIEWER_RENDER_BUFFER_MAX_SIZE);
	boolean renderImage;
	if (maxImageSize <= 0)
	{
		renderImage = false;
	}
	else
	{
		long imageSize = ((int) (pageFormat.getPageWidth() * realZoom) + 1) * ((int) (pageFormat.getPageHeight() * realZoom) + 1);
		renderImage = imageSize <= maxImageSize;
	}

	lblPage.setRenderImage(renderImage);

	if (renderImage)
	{
		setPageImage();
	}

	pnlLinks.removeAll();
	linksMap = new HashMap<JPanel, JRPrintHyperlink>();

	createHyperlinks();

	if (!renderImage)
	{
		lblPage.setIcon(null);

		validate();
		repaint();
	}
}
 
Example 9
Source File: JRViewer.java    From nordpos with GNU General Public License v3.0 4 votes vote down vote up
/**
*/
protected void refreshPage()
{
	if (
		jasperPrint == null ||
		jasperPrint.getPages() == null ||
		jasperPrint.getPages().size() == 0
		)
	{
		pnlPage.setVisible(false);
		btnSave.setEnabled(false);
		btnPrint.setEnabled(false);
		btnActualSize.setEnabled(false);
		btnFitPage.setEnabled(false);
		btnFitWidth.setEnabled(false);
		btnZoomIn.setEnabled(false);
		btnZoomOut.setEnabled(false);
		cmbZoom.setEnabled(false);

		if (jasperPrint != null)
		{
			JOptionPane.showMessageDialog(this, getBundleString("no.pages"));
		}

		return;
	}

	pnlPage.setVisible(true);
	btnSave.setEnabled(true);
	btnPrint.setEnabled(true);
	btnActualSize.setEnabled(true);
	btnFitPage.setEnabled(true);
	btnFitWidth.setEnabled(true);
	btnZoomIn.setEnabled(zoom < MAX_ZOOM);
	btnZoomOut.setEnabled(zoom > MIN_ZOOM);
	cmbZoom.setEnabled(true);

	PrintPageFormat pageFormat = getPageFormat();
	
	Dimension dim = new Dimension(
		(int)(pageFormat.getPageWidth() * realZoom) + 8, // 2 from border, 5 from shadow and 1 extra pixel for image
		(int)(pageFormat.getPageHeight() * realZoom) + 8
		);
	pnlPage.setMaximumSize(dim);
	pnlPage.setMinimumSize(dim);
	pnlPage.setPreferredSize(dim);

	long maxImageSize = JRPropertiesUtil.getInstance(jasperReportsContext).getLongProperty(VIEWER_RENDER_BUFFER_MAX_SIZE);
	boolean renderImage;
	if (maxImageSize <= 0)
	{
		renderImage = false;
	}
	else
	{
		long imageSize = ((int) (pageFormat.getPageWidth() * realZoom) + 1) * ((int) (pageFormat.getPageHeight() * realZoom) + 1);
		renderImage = imageSize <= maxImageSize;
	}

	((PageRenderer)lblPage).setRenderImage(renderImage);

	if (renderImage)
	{
		setPageImage();
	}

	pnlLinks.removeAll();
	linksMap = new HashMap<JPanel,JRPrintHyperlink>();

	createHyperlinks();

	if (!renderImage)
	{
		lblPage.setIcon(null);

		pnlMain.validate();
		pnlMain.repaint();
	}
}