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

The following examples show how to use net.sf.jasperreports.engine.PrintPageFormat#getPageHeight() . 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: DocxDocumentHelper.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
	 *
	 */
	public void exportSection(PrintPageFormat pageFormat, JRGridLayout pageGridLayout, boolean lastPage)
	{
		if (!lastPage)
		{
			write("    <w:p>\n");
			write("    <w:pPr>\n");
		}
		write("  <w:sectPr>\n");
		write("   <w:pgSz w:w=\"" + LengthUtil.twip(pageFormat.getPageWidth()) + "\" w:h=\"" + LengthUtil.twip(pageFormat.getPageHeight()) + "\"");
		write(" w:orient=\"" + (pageFormat.getOrientation() == OrientationEnum.LANDSCAPE ? "landscape" : "portrait") + "\"");
		
		if(OoxmlUtils.getSuitablePaperSize(pageFormat) == PaperSizeEnum.UNDEFINED)
		{
			// unique identifier for the paper size
			write(" w:code=\""+ (1000 + pageFormat.getPageWidth() + pageFormat.getPageHeight()) +"\"");
		}
		write("/>\n");
		
		CutsInfo xCuts = pageGridLayout.getXCuts();
		
		Cut leftCut = xCuts.getCut(0);
		int gridLeftPadding = leftCut.isCutNotEmpty() ? 0 : pageGridLayout.getColumnWidth(0);
		int leftMargin = Math.min(gridLeftPadding, pageFormat.getLeftMargin());

		Cut rightCut = xCuts.getCut(xCuts.size() - 2);
		int gridRightPadding = rightCut.isCutNotEmpty() ? 0 : pageGridLayout.getColumnWidth(xCuts.size() - 2);
		int rightMargin = Math.min(gridRightPadding, pageFormat.getRightMargin());

		CutsInfo yCuts = pageGridLayout.getYCuts();
		
		int topMargin = pageFormat.getTopMargin();
		if (yCuts.size() > 1)
		{
			Cut topCut = yCuts.getCut(0);
			int gridTopPadding = topCut.isCutNotEmpty() ? 0 : pageGridLayout.getRowHeight(0);
			topMargin = Math.min(gridTopPadding, pageFormat.getTopMargin());
		}

		//last y cut is from bottom element, not page height
		int gridBottomPadding = pageFormat.getPageHeight() - yCuts.getLastCutOffset();
		int bottomMargin = LengthUtil.twip(Math.min(gridBottomPadding, pageFormat.getBottomMargin())) - DEFAULT_LINE_PITCH;
		bottomMargin = bottomMargin < 0 ? 0 : bottomMargin;

		write("   <w:pgMar w:top=\""
				+ LengthUtil.twip(topMargin)
				+ "\" w:right=\""
				+ LengthUtil.twip(rightMargin)
				+ "\" w:bottom=\""
				+ bottomMargin
				+ "\" w:left=\""
				+ LengthUtil.twip(leftMargin)
				+ "\" w:header=\"0\" w:footer=\"0\" w:gutter=\"0\" />\n");
//		write("   <w:cols w:space=\"720\" />\n");
		write("   <w:docGrid w:linePitch=\"" + DEFAULT_LINE_PITCH + "\" />\n");
		write("  </w:sectPr>\n");
		if (!lastPage)
		{
			write("    </w:pPr>\n");
			write("    </w:p>\n");
		}
	}
 
Example 9
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 10
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();
	}
}