本文整理汇总了Java中java.awt.print.PrinterJob.print方法的典型用法代码示例。如果您正苦于以下问题:Java PrinterJob.print方法的具体用法?Java PrinterJob.print怎么用?Java PrinterJob.print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.print.PrinterJob
的用法示例。
在下文中一共展示了PrinterJob.print方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: thirdPartyPrintLogic
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
static void thirdPartyPrintLogic(String printerName) throws Exception {
PrinterJob printerjob = PrinterJob.getPrinterJob();
printerjob.setCopies(2);
printerjob.setJobName("myJobName");
printerjob.setPrintable(new DummyPrintable());
for (PrintService printService : PrinterJob.lookupPrintServices()) {
System.out.println("check printer name of service " + printService);
if (printerName.equals(printService.getName())) {
System.out.println("correct printer service do print...");
printerjob.setPrintService(printService);
printerjob.print();
break;
}
}
}
示例2: printDocument
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public static void printDocument() throws IOException, PrinterException
{
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(Sides.TWO_SIDED_SHORT_EDGE);
PDDocument input = PDDocument.load(new File("Karteikarten.pdf"));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPageable(new PDFPageable(input));
if (job.printDialog(pras)) {
job.print(pras);
}
}
示例3: actionPerformed
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
/**
*
*/
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof mxGraphComponent) {
mxGraphComponent graphComponent = (mxGraphComponent) e.getSource();
PrinterJob pj = PrinterJob.getPrinterJob();
if (pj.printDialog()) {
PageFormat pf = graphComponent.getPageFormat();
Paper paper = new Paper();
double margin = 36;
paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2,
paper.getHeight() - margin * 2);
pf.setPaper(paper);
pj.setPrintable(graphComponent, pf);
try {
pj.print();
} catch (PrinterException e2) {
System.out.println(e2);
}
}
}
}
示例4: printTest
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printTest() {
PrinterJob pj = PrinterJob.getPrinterJob();
PageFormat pf = pj.defaultPage();
Paper paper = new Paper();
double margin = 36; // half inch
paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2,
paper.getHeight() - margin * 2);
pf.setPaper(paper);
pj.setPrintable(new PrintTestLexmarkIQ(), pf);
if (pj.printDialog()) {
try {
pj.print();
} catch (PrinterException e) {
System.out.println(e);
}
}
}
示例5: printTest
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printTest() {
MediaTray tray = null;
//tray = getMediaTray( prservices, "Bypass Tray" );
tray = getMediaTray( prservices, "Tray 4" );
PrintRequestAttributeSet atrset = new HashPrintRequestAttributeSet();
//atrset.add( MediaSizeName.ISO_A4 );
atrset.add(tray);
PrinterJob pjob = PrinterJob.getPrinterJob();
pjob.setPrintable(new TestMediaTraySelection());
try {
pjob.print(atrset);
} catch (PrinterException e) {
e.printStackTrace();
fail();
}
}
示例6: createChartPrintJob
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
/**
* Creates a print job for the chart.
*/
@Override
public void createChartPrintJob() {
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
PageFormat pf2 = job.pageDialog(pf);
if (pf2 != pf) {
job.setPrintable(this, pf2);
if (job.printDialog()) {
try {
job.print();
} catch (PrinterException e) {
JOptionPane.showMessageDialog(this, e);
}
}
}
}
示例7: doTest
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void doTest() {
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(Chromaticity.MONOCHROME);
MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
Paper paper = new Paper();
paper.setSize(size[0] * 72.0, size[1] * 72.0);
paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
PageFormat pf = new PageFormat();
pf.setPaper(paper);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
if (job.printDialog()) {
try {
job.print(aset);
} catch (PrinterException pe) {
throw new RuntimeException(pe);
}
}
}
示例8: actionPerformed
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent event) {
if (event.getSource() == _fillButton) {
fillPlot();
}
else if (event.getSource() == _printButton) {
PrinterJob job = PrinterJob.getPrinterJob();
// [email protected]: Get the Page Format and use it.
PageFormat format = job.pageDialog( job.defaultPage() );
job.setPrintable(PlotBox.this, format);
if (job.printDialog()) {
try {
job.print();
} catch (Exception ex) {
Component ancestor = getTopLevelAncestor();
JOptionPane.showMessageDialog(ancestor,
"Printing failed:\n" + ex.toString(),
"Print Error", JOptionPane.WARNING_MESSAGE);
}
}
}
else if (event.getSource() == _resetButton) {
resetAxes();
}
else if (event.getSource() == _formatButton) {
PlotFormatter fmt = new PlotFormatter(PlotBox.this);
fmt.openModal();
}
}
示例9: printDifferentRowHeight
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printDifferentRowHeight() {
final JTable table = createAuthorTable(50);
table.setRowHeight(15, table.getRowHeight(15)+10);
Printable printable = table.getPrintable(
JTable.PrintMode.NORMAL,
new MessageFormat("Author Table"),
new MessageFormat("Page - {0}"));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(printable);
boolean printAccepted = job.printDialog();
if (printAccepted) {
try {
job.print();
closeFrame();
} catch (PrinterException e) {
throw new RuntimeException(e);
}
}
}
示例10: createChartPrintJob
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
/**
* Creates a print job for the chart.
*/
public void createChartPrintJob() {
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
PageFormat pf2 = job.pageDialog(pf);
if (pf2 != pf) {
job.setPrintable(this, pf2);
if (job.printDialog()) {
try {
job.print();
}
catch (PrinterException e) {
JOptionPane.showMessageDialog(this, e);
}
}
}
}
示例11: printWithJavaPrintDialog
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printWithJavaPrintDialog() {
final JTable table = createAuthorTable(42);
Printable printable = table.getPrintable(
JTable.PrintMode.NORMAL,
new MessageFormat("Author Table"),
new MessageFormat("Page - {0}"));
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(printable);
boolean printAccepted = job.printDialog();
if (printAccepted) {
try {
job.print();
closeFrame();
} catch (PrinterException e) {
throw new RuntimeException(e);
}
}
}
示例12: printWorksheet
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public void printWorksheet() {
PrinterJob print = PrinterJob.getPrinterJob();
print.setPrintable(desktop.getSelectedFrame());
if(print.printDialog(new HashPrintRequestAttributeSet()))
try { print.print(); }
catch(PrinterException e) {}
}
示例13: printWorks
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public void printWorks(String[] args)
{
PrinterJob job=PrinterJob.getPrinterJob();
job.setPrintable(this);
PrintRequestAttributeSet settings=new HashPrintRequestAttributeSet();
PrinterResolution pr = new PrinterResolution(300, 300, ResolutionSyntax.DPI);
if (args.length > 0 && (args[0].compareTo("600") == 0)) {
pr = new PrinterResolution(600, 600, ResolutionSyntax.DPI);
System.out.println("Adding 600 Dpi attribute");
} else {
System.out.println("Adding 300 Dpi attribute");
}
PrintService ps = job.getPrintService();
boolean resolutionSupported = ps.isAttributeValueSupported(pr, null, null);
System.out.println("Is "+pr+" supported by "+ps+"? "+resolutionSupported);
if (resolutionSupported) {
System.out.println("Resolution is supported.\nTest is not applicable, PASSED");
}
settings.add(pr);
if (args.length > 0 && (args[0].equalsIgnoreCase("fidelity"))) {
settings.add(Fidelity.FIDELITY_TRUE);
System.out.println("Adding Fidelity.FIDELITY_TRUE attribute");
}
if (job.printDialog(settings))
{
try {
job.print(settings);
} catch (PrinterException e) {
e.printStackTrace();
}
}
}
示例14: printWithCustomImageareaSize
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
private static void printWithCustomImageareaSize() {
final JTable table = createAuthorTable(18);
PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
printAttributes.add(DialogTypeSelection.NATIVE);
printAttributes.add(new Copies(1));
printAttributes.add(new MediaPrintableArea(
0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
Printable printable = table.getPrintable(
JTable.PrintMode.NORMAL,
new MessageFormat("Author Table"),
new MessageFormat("Page - {0}")
);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(printable);
boolean printAccepted = job.printDialog(printAttributes);
if (printAccepted) {
try {
job.print(printAttributes);
closeFrame();
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException("User cancels the printer job!");
}
}
示例15: actionPerformed
import java.awt.print.PrinterJob; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
if (job.printDialog()) {
try {
job.print();
} catch (PrinterException ex) {
ex.printStackTrace();
}
}
}