Welcome to My World (www.dgmayor.com)

소프트웨어/자바 GUI & C# 등...

49. printjob 예제 15

dgmayor 2022. 5. 13. 14:24
728x90
Example 1
Source Project: ApprovalTests.Java   Source File: PrintUtils.java    License: Apache License 2.0 6 votes  
public void print(boolean prompt)
{
  PrinterJob printJob = PrinterJob.getPrinterJob();
  PageFormat format = printJob.defaultPage();
  Paper paper = format.getPaper();
  paper.setImageableArea(18, 0, 180, 840);// Paper format for receipt printer
  format.setPaper(paper);
  printJob.setPrintable(this, format);
  if (!prompt || printJob.printDialog())
  {
    try
    {
      printJob.print();
    }
    catch (PrinterException pe)
    {
      SimpleLogger.variable("Error printing: " + pe);
    }
  }
}
 
Example 2
Source Project: spring-boot   Source File: PrintTest.java    License: Apache License 2.0 6 votes  
private void printTextAction()
{
    printStr = area.getText().trim();
    if(printStr != null && printStr.length() > 0)
    {
        PAGES = getPagesCount(printStr);
        PrinterJob myPrtJob = PrinterJob.getPrinterJob();
        PageFormat pageFormat = myPrtJob.defaultPage();
        myPrtJob.setPrintable(this, pageFormat);
        if(myPrtJob.printDialog())
            try
            {
                myPrtJob.print();
            }
            catch(PrinterException pe)
            {
                pe.printStackTrace();
            }
    } else
    {
        JOptionPane.showConfirmDialog(null, "Sorry, Printer Job is Empty, Print Cancelled!", "Empty", -1, 2);
    }
}
 
Example 3
Source Project: openjdk-jdk8u-backup   Source File: ImageableAreaTest.java    License: GNU General Public License v2.0 6 votes  
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);
        }
    }
}
 
Example 4
Source Project: openjdk-jdk8u-backup   Source File: PrintAttributeUpdateTest.java    License: GNU General Public License v2.0 6 votes  
public static void main(String args[]) throws Exception {
    String[] instructions
            = {
                "Select Pages Range From instead of All in print dialog. ",
                "Then select Print"
            };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null,
                instructions, "Instructions",
                JOptionPane.INFORMATION_MESSAGE);
    });
    HashPrintRequestAttributeSet as = new HashPrintRequestAttributeSet();
    PrinterJob j = PrinterJob.getPrinterJob();
    j.setPageable(new PrintAttributeUpdateTest());
    as.add(DialogTypeSelection.NATIVE);
    j.printDialog(as);
    if (as.containsKey(PageRanges.class) == false) {
        throw new RuntimeException("Print Dialog did not update "
                + " attribute set with page range");
    }
    Attribute attrs[] = as.toArray();
    for (int i = 0; i < attrs.length; i++) {
        System.out.println("attr " + attrs[i]);
    }
    j.print(as);
}
 
Example 5
Source Project: openjdk-jdk9   Source File: ImageableAreaTest.java    License: GNU General Public License v2.0 6 votes  
private static void printWithJavaPrintDialog() {
    final JTable table = createAuthorTable(50);
    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);
        }
    }
}
 
Example 6
Source Project: astor   Source File: ChartComposite.java    License: GNU General Public License v2.0 6 votes  
/**
 * Creates a print job for the chart.
 */
public void createChartPrintJob() {
    //FIXME try to replace swing print stuff by swt
    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) {
                MessageBox messageBox = new MessageBox(
                        this.canvas.getShell(), SWT.OK | SWT.ICON_ERROR);
                messageBox.setMessage(e.getMessage());
                messageBox.open();
            }
        }
    }
}
 
Example 7
Source Project: ECG-Viewer   Source File: ChartPanel.java    License: GNU General Public License v2.0 6 votes  
/**
 * 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);
            }
        }
    }
}
 
Example 8
Source Project: TencentKona-8   Source File: WPrinterJob.java    License: GNU General Public License v2.0 6 votes  
private void setPrinterNameAttrib(String printerName) {
    PrintService service = this.getPrintService();

    if (printerName == null) {
        return;
    }

    if (service != null && printerName.equals(service.getName())) {
        return;
    } else {
        PrintService []services = PrinterJob.lookupPrintServices();
        for (int i=0; i<services.length; i++) {
            if (printerName.equals(services[i].getName())) {

                try {
                    this.setPrintService(services[i]);
                } catch (PrinterException e) {
                }
                return;
            }
        }
    }
//** END Functions called by native code for querying/updating attributes

}
 
Example 9
Source Project: netbeans   Source File: Config.java    License: Apache License 2.0 6 votes  
public boolean showPageSetup() {
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat oldFormat = getPageFormat();
    PageFormat newFormat = job.pageDialog(oldFormat);

    if (oldFormat == newFormat) {
        return false;
    }
    myPageFormat = newFormat;

    // save
    set(PAGE_ORIENTATION, myPageFormat.getOrientation());
    Paper paper = myPageFormat.getPaper();

    set(PAPER_WIDTH, paper.getWidth());
    set(PAPER_HEIGHT, paper.getHeight());

    set(AREA_X, paper.getImageableX());
    set(AREA_Y, paper.getImageableY());

    set(AREA_WIDTH, paper.getImageableWidth());
    set(AREA_HEIGHT, paper.getImageableHeight());

    return true;
}
 
Example 10
Source Project: haxademic   Source File: PrintPageDirect.java    License: MIT License 5 votes  
protected void printPage(PrinterJob printJob) {
	try {
		printJob.print();
	} catch (Exception PrintException) {
		PrintException.printStackTrace();
	}
}
 
Example 11
Source Project: openjdk-jdk8u   Source File: bug8023392.java    License: GNU General Public License v2.0 5 votes  
public void actionPerformed(ActionEvent e) {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(this);
    if (job.printDialog()) {
        try {
            job.print();
        } catch (PrinterException ex) {
            ex.printStackTrace();
        }
    }
}
 
Example 12
Source Project: jdk8u_jdk   Source File: bug8023392.java    License: GNU General Public License v2.0 5 votes  
public void actionPerformed(ActionEvent e) {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(this);
    if (job.printDialog()) {
        try {
            job.print();
        } catch (PrinterException ex) {
            ex.printStackTrace();
        }
    }
}
 
Example 13
Source Project: openjdk-8-source   Source File: PathGraphics.java    License: GNU General Public License v2.0 5 votes  
protected PathGraphics(Graphics2D graphics, PrinterJob printerJob,
                       Printable painter, PageFormat pageFormat,
                       int pageIndex, boolean canRedraw) {
    super(graphics, printerJob);

    mPainter = painter;
    mPageFormat = pageFormat;
    mPageIndex = pageIndex;
    mCanRedraw = canRedraw;
}
 
Example 14
Source Project: megan-ce   Source File: PageSetupCommand.java    License: GNU General Public License v3.0 5 votes  
/**
 * parses the given command and executes it
 *
 * @param np
 * @throws java.io.IOException
 */
@Override
public void apply(NexusStreamParser np) throws Exception {
    np.matchIgnoreCase(getSyntax());
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pageFormat = job.pageDialog(new PageFormat());
    ProgramProperties.setPageFormat(pageFormat);

}
 
Example 15
Source Project: jdk8u-jdk   Source File: bug8023392.java    License: GNU General Public License v2.0 5 votes  
public void actionPerformed(ActionEvent e) {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(this);
    if (job.printDialog()) {
        try {
            job.print();
        } catch (PrinterException ex) {
            ex.printStackTrace();
        }
    }
}
 
Example 16
Source Project: TencentKona-8   Source File: PrintLatinCJKTest.java    License: GNU General Public License v2.0 5 votes  
public void actionPerformed(ActionEvent e) {
    try {
        PrinterJob job = PrinterJob.getPrinterJob();
        job.setPrintable(testInstance);
        if (job.printDialog()) {
            job.print();
        }
    } catch (PrinterException ex) {
        ex.printStackTrace();
    }
}
 
Example 17
Source Project: jdk8u-jdk   Source File: SetPrintServiceTest.java    License: GNU General Public License v2.0 5 votes  
public static void main(String[] args) {
    PrintServiceStub service = new PrintServiceStub("CustomPrintService");
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    try {
        printerJob.setPrintService(service);
        System.out.println("Test Passed");
    } catch (PrinterException e) {
        throw new RuntimeException("Test FAILED", e);
    }
}
 
Example 18
Source Project: jdk8u-dev-jdk   Source File: bug8023392.java    License: GNU General Public License v2.0 5 votes  
public void actionPerformed(ActionEvent e) {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(this);
    if (job.printDialog()) {
        try {
            job.print();
        } catch (PrinterException ex) {
            ex.printStackTrace();
        }
    }
}
 
Example 19
Source Project: openjdk-jdk8u   Source File: Win32PrintService.java    License: GNU General Public License v2.0 5 votes  
public PrintRequestAttributeSet
    showDocumentProperties(PrinterJob job,
                           Window owner,
                           PrintService service,
                           PrintRequestAttributeSet aset) {

    if (!(job instanceof WPrinterJob)) {
        return null;
    }
    WPrinterJob wJob = (WPrinterJob)job;
    return wJob.showDocumentProperties(owner, service, aset);
}
 
Example 20
Source Project: TencentKona-8   Source File: PageDlgStackOverflowTest.java    License: GNU General Public License v2.0 5 votes  
public static void main(String args[]) {
    PrinterJob job = PrinterJob.getPrinterJob();
    if (job == null) {
        return;
    }
    PrintRequestAttributeSet pSet =
         new HashPrintRequestAttributeSet();
    pSet.add(DialogTypeSelection.NATIVE);
    job.printDialog(pSet);
    try {
        job.pageDialog(pSet);
    } catch (StackOverflowError e) {
        throw new RuntimeException("StackOverflowError is thrown");
    }
}
 
Example 21
Source Project: hottub   Source File: SetPrintServiceTest.java    License: GNU General Public License v2.0 5 votes  
public static void main(String[] args) {
    PrintServiceStub service = new PrintServiceStub("CustomPrintService");
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    try {
        printerJob.setPrintService(service);
        System.out.println("Test Passed");
    } catch (PrinterException e) {
        throw new RuntimeException("Test FAILED", e);
    }
}
 
Example 22
Source Project: openjdk-jdk8u   Source File: TexturePaintPrintingTest.java    License: GNU General Public License v2.0 5 votes  
private static void printTexture() {
    f = new JFrame("Texture Printing Test");
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    final TexturePaintPrintingTest gpt = new TexturePaintPrintingTest();
    Container c = f.getContentPane();
    c.add(BorderLayout.CENTER, gpt);

    final JButton print = new JButton("Print");
    print.addActionListener(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            PrinterJob job = PrinterJob.getPrinterJob();
            job.setPrintable(gpt);
            final boolean doPrint = job.printDialog();
            if (doPrint) {
                try {
                    job.print();
                } catch (PrinterException ex) {
                    throw new RuntimeException(ex);
                }
            }
        }
    });
    c.add(print, BorderLayout.SOUTH);

    f.pack();
    f.setVisible(true);
}
 
Example 23
Source Project: jdk8u-jdk   Source File: SetPrintServiceTest.java    License: GNU General Public License v2.0 5 votes  
public static void main(String[] args) {
    PrintServiceStub service = new PrintServiceStub("CustomPrintService");
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    try {
        printerJob.setPrintService(service);
        System.out.println("Test Passed");
    } catch (PrinterException e) {
        throw new RuntimeException("Test FAILED", e);
    }
}
 
Example 24
Source Project: openjdk-8-source   Source File: Win32PrintService.java    License: GNU General Public License v2.0 5 votes  
public PrintRequestAttributeSet
    showDocumentProperties(PrinterJob job,
                           Window owner,
                           PrintService service,
                           PrintRequestAttributeSet aset) {

    if (!(job instanceof WPrinterJob)) {
        return null;
    }
    WPrinterJob wJob = (WPrinterJob)job;
    return wJob.showDocumentProperties(owner, service, aset);
}
 
Example 25
Source Project: nordpos   Source File: JRPrinterAWT.java    License: GNU General Public License v3.0 5 votes  
/**
 * Fix for bug ID 6255588 from Sun bug database
 * @param job print job that the fix applies to
 */
public static void initPrinterJobFields(PrinterJob job)
{
	try
	{
		job.setPrintService(job.getPrintService());
	}
	catch (PrinterException e)
	{
	}
}
 
Example 26
Source Project: chipster   Source File: ImageExportUtils.java    License: MIT License 5 votes  
public static void printComponent(Printable component) throws PrinterException {
	PrinterJob job = PrinterJob.getPrinterJob();
	job.setPrintable(component);
	
	boolean doPrint = job.printDialog();
	if (doPrint) {
		job.print();
	}
}
 
Example 27
Source Project: jdk8u-dev-jdk   Source File: PrintLatinCJKTest.java    License: GNU General Public License v2.0 5 votes  
public void actionPerformed(ActionEvent e) {
    try {
        PrinterJob job = PrinterJob.getPrinterJob();
        job.setPrintable(testInstance);
        if (job.printDialog()) {
            job.print();
        }
    } catch (PrinterException ex) {
        ex.printStackTrace();
    }
}
 
Example 28
Source Project: jdk8u-jdk   Source File: PrintCrashTest.java    License: GNU General Public License v2.0 5 votes  
public static void main(String[] args) throws Exception {
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable((graphics, pageFormat, pageIndex) -> {
        if (pageIndex != 0) {
            return Printable.NO_SUCH_PAGE;
        } else {
            Shape shape = new Rectangle(110, 110, 10, 10);
            Rectangle rect = shape.getBounds();

            BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
                    .getDefaultConfiguration().createCompatibleImage(rect.width, rect.height, Transparency.BITMASK);
            graphics.drawImage(image, rect.x, rect.y, rect.width, rect.height, null);

            return Printable.PAGE_EXISTS;
        }
    });

    File file = null;
    try {
        HashPrintRequestAttributeSet hashPrintRequestAttributeSet = new HashPrintRequestAttributeSet();
        file = File.createTempFile("out", "ps");
        file.deleteOnExit();
        Destination destination = new Destination(file.toURI());
        hashPrintRequestAttributeSet.add(destination);
        printerJob.print(hashPrintRequestAttributeSet);
    } finally {
        if (file != null) {
            file.delete();
        }
    }
}
 
Example 29
Source Project: TencentKona-8   Source File: PathGraphics.java    License: GNU General Public License v2.0 5 votes  
protected PathGraphics(Graphics2D graphics, PrinterJob printerJob,
                       Printable painter, PageFormat pageFormat,
                       int pageIndex, boolean canRedraw) {
    super(graphics, printerJob);

    mPainter = painter;
    mPageFormat = pageFormat;
    mPageIndex = pageIndex;
    mCanRedraw = canRedraw;
}
 
Example 30
Source Project: pentaho-reporting   Source File: MasterReport.java    License: GNU Lesser General Public License v2.1 5 votes  
private PageDefinition createDefaultPageDefinition() {
  final PageDefinition format;
  final ExtendedConfiguration config = ClassicEngineBoot.getInstance().getExtendedConfig();
  if ( config.getBoolProperty( ClassicEngineCoreModule.NO_PRINTER_AVAILABLE_KEY ) ) {
    format = new SimplePageDefinition( new PageFormat() );
  } else {
    format = new SimplePageDefinition( PrinterJob.getPrinterJob().defaultPage() );
  }
  return format;
}
 
728x90