List of usage examples for javax.print.attribute.standard OrientationRequested LANDSCAPE
OrientationRequested LANDSCAPE
To view the source code for javax.print.attribute.standard OrientationRequested LANDSCAPE.
Click Source Link
From source file:Print.java
public static void main(String[] args) throws IOException { // These are values we'll set from the command-line arguments boolean query = false; String printerName = null;//from w w w . j a v a 2s .c o m String inputFileName = null; String outputFileName = null; String outputFileType = null; PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); // Loop through the arguments for (int i = 0; i < args.length; i++) { if (args[i].equals("-q")) query = true; // Is this is query? else if (args[i].equals("-p")) // Specific printer name printerName = args[++i]; else if (args[i].equals("-i")) // The file to print inputFileName = args[++i]; else if (args[i].equals("-ps")) { // Print it to this file // Sun's Java 1.4 implementation only supports PostScript // output. Other implementations might offer PDF, for example. outputFileName = args[++i]; outputFileType = "application/postscript"; } // The rest of the arguments represent common printing attributes else if (args[i].equals("-color")) // Request a color printer attributes.add(Chromaticity.COLOR); else if (args[i].equals("-landscape")) // Request landscape mode attributes.add(OrientationRequested.LANDSCAPE); else if (args[i].equals("-letter")) // US Letter-size paper attributes.add(MediaSizeName.NA_LETTER); else if (args[i].equals("-a4")) // European A4 paper attributes.add(MediaSizeName.ISO_A4); else if (args[i].equals("-staple")) // Request stapling attributes.add(Finishings.STAPLE); else if (args[i].equals("-collate")) // Collate multiple copies attributes.add(SheetCollate.COLLATED); else if (args[i].equals("-duplex")) // Request 2-sided attributes.add(Sides.DUPLEX); else if (args[i].equals("-2")) // 2 pages to a sheet attributes.add(new NumberUp(2)); else if (args[i].equals("-copies")) // how many copies attributes.add(new Copies(Integer.parseInt(args[++i]))); else { System.out.println("Unknown argument: " + args[i]); System.exit(1); } } if (query) { // If the -q argument was specified, but no printer was named, // then list all available printers that can support the attributes if (printerName == null) queryServices(attributes); // Otherwise, look for a named printer that can support the // attributes and print its status else queryPrinter(printerName, attributes); } else if (outputFileName != null) // If this is not a query and we have a filename, print to a file printToFile(outputFileName, outputFileType, inputFileName, attributes); else // Otherwise, print to the named printer, or to the default // printer otherwise. print(printerName, inputFileName, attributes); // The main() method ends here, but there may be a printing thread // operating in the background. So the program may not terminate // until printing completes. }
From source file:com.eyeq.pivot4j.export.poi.FopExporterIT.java
@Test public void testExportPdf() throws IOException { OutputStream out = null;/*from www . j a v a2 s . c o m*/ File file = File.createTempFile("pivot4j-", ".pdf"); if (deleteTestFile) { file.deleteOnExit(); } try { out = new FileOutputStream(file); FopExporter exporter = new FopExporter(out); exporter.setShowParentMembers(true); exporter.setShowDimensionTitle(true); exporter.setHideSpans(false); exporter.setOrientation(OrientationRequested.LANDSCAPE); exporter.render(getPivotModel()); } finally { out.flush(); IOUtils.closeQuietly(out); } }
From source file:JuliaSet3.java
public void print() { // Get a list of all printers that can handle Printable objects. DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null); // Set some define printing attributes PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet(); printAttributes.add(OrientationRequested.LANDSCAPE); // landscape mode printAttributes.add(Chromaticity.MONOCHROME); // print in mono // Display a dialog that allows the user to select one of the // available printers and to edit the default attributes PrintService service = ServiceUI.printDialog(null, 100, 100, services, null, null, printAttributes); // If the user canceled, don't do anything if (service == null) return;/*from w ww . j a v a 2s .co m*/ // Now call a method defined below to finish the printing printToService(service, printAttributes); }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java
public static PageFormat extractPageFormat(final PrintRequestAttributeSet attributeSet) { final Media media = (Media) attributeSet.get(Media.class); final MediaPrintableArea printableArea = (MediaPrintableArea) attributeSet.get(MediaPrintableArea.class); final OrientationRequested orientationRequested = (OrientationRequested) attributeSet .get(OrientationRequested.class); final MediaSize mediaSize = lookupMediaSize(media); if (mediaSize == null) { logger.warn("Unknown media encountered, unable to compute page sizes."); }//ww w .jav a 2s. c o m final PageFormat pageFormat = new PageFormat(); pageFormat.setPaper(createPaper(mediaSize, printableArea)); if (OrientationRequested.PORTRAIT.equals(orientationRequested)) { pageFormat.setOrientation(PageFormat.PORTRAIT); } else if (OrientationRequested.LANDSCAPE.equals(orientationRequested)) { pageFormat.setOrientation(PageFormat.LANDSCAPE); } else if (OrientationRequested.REVERSE_LANDSCAPE.equals(orientationRequested)) { pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE); } else if (OrientationRequested.REVERSE_PORTRAIT.equals(orientationRequested)) { pageFormat.setOrientation(PageFormat.PORTRAIT); } return pageFormat; }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java
private static OrientationRequested mapOrientation(final int orientation) { switch (orientation) { case PageFormat.LANDSCAPE: return OrientationRequested.LANDSCAPE; case PageFormat.REVERSE_LANDSCAPE: return OrientationRequested.REVERSE_LANDSCAPE; case PageFormat.PORTRAIT: return OrientationRequested.PORTRAIT; default://from w w w.j a va 2 s .co m throw new IllegalArgumentException("The given value is no valid PageFormat orientation."); } }
From source file:org.pivot4j.ui.fop.FopExporterIT.java
@Test public void testExportPdf() throws IOException { OutputStream out = null;/*from w ww . ja v a 2 s . co m*/ File file = File.createTempFile("pivot4j-", ".pdf"); if (deleteTestFile) { file.deleteOnExit(); } try { out = new FileOutputStream(file); TableRenderer renderer = new TableRenderer(); renderer.setShowParentMembers(true); renderer.setShowDimensionTitle(true); renderer.setHideSpans(false); FopExporter exporter = new FopExporter(out); exporter.setOrientation(OrientationRequested.LANDSCAPE); renderer.render(getPivotModel(), exporter); } finally { out.flush(); IOUtils.closeQuietly(out); } }