Java Code Examples for net.sf.jasperreports.engine.JasperPrint#setName()

The following examples show how to use net.sf.jasperreports.engine.JasperPrint#setName() . 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: BaseElementsTests.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected String elementToXml(JRPrintElement element)
{
	JRBasePrintPage page = new JRBasePrintPage();
	page.addElement(element);
	JasperPrint jasperPrint = new JasperPrint();
	jasperPrint.addPage(page);
	jasperPrint.setName("test");
	
	StringWriter writer = new StringWriter();
	JRXmlExporter exporter = new JRXmlExporter();
	exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
	SimpleXmlExporterOutput output = new SimpleXmlExporterOutput(writer);
	output.setEmbeddingImages(true);
	exporter.setExporterOutput(output);
	try
	{
		exporter.exportReport();
	}
	catch (JRException e)
	{
		throw new RuntimeException(e);
	}
	return writer.toString();
}
 
Example 2
Source File: ReportConverter.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
protected void convert(boolean ignoreContent)
{
	jasperPrint = new JasperPrint();
	
	jasperPrint.setFormatFactoryClass(report.getFormatFactoryClass());
	//FIXME locale and timezone settings jasperprint object
	//jasperPrint.setLocaleCode(JRDataUtils.getLocaleCode(Locale.getDefault()));
	//jasperPrint.setTimeZoneId(JRDataUtils.getTimeZoneId(TimeZone.getDefault()));
	//FIXMEFONT the locale is important for font
	//jasperPrint.setLocaleCode(report.getProperty(JRPropertiesUtil.PROPERTY_PREFIX + "locale"));
	//JRStyledTextAttributeSelector.setLocale(locale);
	jasperPrint.setName(report.getName());
	jasperPrint.setOrientation(report.getOrientationValue());
	jasperPrint.setPageWidth(report.getPageWidth());
	jasperPrint.setPageHeight(report.getPageHeight());
	jasperPrint.setTopMargin(report.getTopMargin());
	jasperPrint.setLeftMargin(report.getLeftMargin());
	jasperPrint.setBottomMargin(report.getBottomMargin());
	jasperPrint.setRightMargin(report.getRightMargin());
	
	JRPropertiesUtil.getInstance(jasperReportsContext).transferProperties(report, jasperPrint, JasperPrint.PROPERTIES_PRINT_TRANSFER_PREFIX);

	setStyles(report);

	if (!ignoreContent)
	{
		pageWidth = report.getPageWidth();
		page = new JRBasePrintPage();
		
		offsetY = report.getTopMargin();

		addBand(report.getBackground());
		addBand(report.getTitle());
		addBand(report.getPageHeader());
		upColumnHeader = offsetY;
		addBand(report.getColumnHeader(), true);
		downColumnHeader = offsetY;

		boolean isColumnGroupBands = report.getPrintOrderValue() == PrintOrderEnum.VERTICAL;
		
		JRGroup[] groups = report.getGroups();
		if (groups != null)
		{
			for (int i = 0; i < groups.length ; i++)
			{
				addSection(groups[i].getGroupHeaderSection(), isColumnGroupBands);
			}
		}
		
		upDetails = offsetY;
		addSection(report.getDetailSection(), true);
		downDetails = offsetY;

		if (groups != null)
		{
			for (int i = 0; i < groups.length ; i++)
			{
				addSection(groups[i].getGroupFooterSection(), isColumnGroupBands);
			}
		}
		
		upColumnFooter = offsetY;
		addBand(report.getColumnFooter(), true);
		downColumnFooter = offsetY;
		addBand(report.getPageFooter());
		addBand(report.getLastPageFooter());
		addBand(report.getSummary());
		addBand(report.getNoData());
		
		jasperPrint.setPageHeight(offsetY + report.getBottomMargin());
		
		// column dotted delimitation 
		int colX = report.getLeftMargin();
		for(int i = 0; i < report.getColumnCount(); i++)
		{
			addColumnSeparator(colX);
			colX += report.getColumnWidth();
			addColumnSeparator(colX);
			colX += report.getColumnSpacing();
		}

		// page dotted contour line
		addHorizontalGridLine(0, report.getTopMargin(), pageWidth);
		addHorizontalGridLine(0, offsetY, pageWidth);
		addVerticalGridLine(report.getLeftMargin(), 0, jasperPrint.getPageHeight());
		addVerticalGridLine(pageWidth - report.getRightMargin(), 0, jasperPrint.getPageHeight());

		page.setElements(pageElements);
		jasperPrint.addPage(page);
	}
}
 
Example 3
Source File: JasperPrintFactory.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Object createObject(Attributes atts)
{
	JasperPrint jasperPrint = new JasperPrint();
	
	jasperPrint.setName(atts.getValue(JRXmlConstants.ATTRIBUTE_name));

	String pageWidth = atts.getValue(JRXmlConstants.ATTRIBUTE_pageWidth);
	if (pageWidth != null && pageWidth.length() > 0)
	{
		jasperPrint.setPageWidth(Integer.parseInt(pageWidth));
	}

	String pageHeight = atts.getValue(JRXmlConstants.ATTRIBUTE_pageHeight);
	if (pageHeight != null && pageHeight.length() > 0)
	{
		jasperPrint.setPageHeight(Integer.parseInt(pageHeight));
	}

	String topMargin = atts.getValue(JRXmlConstants.ATTRIBUTE_topMargin);
	if (topMargin != null && topMargin.length() > 0)
	{
		jasperPrint.setTopMargin(Integer.valueOf(topMargin));
	}

	String leftMargin = atts.getValue(JRXmlConstants.ATTRIBUTE_leftMargin);
	if (leftMargin != null && leftMargin.length() > 0)
	{
		jasperPrint.setLeftMargin(Integer.valueOf(leftMargin));
	}

	String bottomMargin = atts.getValue(JRXmlConstants.ATTRIBUTE_bottomMargin);
	if (bottomMargin != null && bottomMargin.length() > 0)
	{
		jasperPrint.setBottomMargin(Integer.valueOf(bottomMargin));
	}

	String rightMargin = atts.getValue(JRXmlConstants.ATTRIBUTE_rightMargin);
	if (rightMargin != null && rightMargin.length() > 0)
	{
		jasperPrint.setRightMargin(Integer.valueOf(rightMargin));
	}

	OrientationEnum orientation = OrientationEnum.getByName(atts.getValue(JRXmlConstants.ATTRIBUTE_orientation));
	if (orientation != null)
	{
		jasperPrint.setOrientation(orientation);
	}
	
	String formatFactoryClass = atts.getValue(JRXmlConstants.ATTRIBUTE_formatFactoryClass);
	if (formatFactoryClass != null)
	{
		jasperPrint.setFormatFactoryClass(formatFactoryClass);
	}
	
	String locale = atts.getValue(JRXmlConstants.ATTRIBUTE_locale);
	if (locale != null)
	{
		jasperPrint.setLocaleCode(locale);
	}
	
	String timezone = atts.getValue(JRXmlConstants.ATTRIBUTE_timezone);
	if (timezone != null)
	{
		jasperPrint.setTimeZoneId(timezone);
	}

	return jasperPrint;
}