当前位置: 首页>>代码示例>>Java>>正文


Java PrinterJob类代码示例

本文整理汇总了Java中javafx.print.PrinterJob的典型用法代码示例。如果您正苦于以下问题:Java PrinterJob类的具体用法?Java PrinterJob怎么用?Java PrinterJob使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PrinterJob类属于javafx.print包,在下文中一共展示了PrinterJob类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: acaoImprimir

import javafx.print.PrinterJob; //导入依赖的package包/类
public void acaoImprimir() {
    PageLayout paisagem = Printer.getDefaultPrinter().createPageLayout(Paper.A4, PageOrientation.LANDSCAPE, Printer.MarginType.HARDWARE_MINIMUM);
    Double largura = paisagem.getPrintableWidth()-50;
    Double altura = paisagem.getPrintableHeight()-50;
    PrinterJob trabalho = PrinterJob.createPrinterJob();
    if(trabalho != null){
        if(trabalho.showPrintDialog(Kernel.palco)){
            Tooltip aguarde = Janela.showTooltip(Status.ADVERTENCIA, idioma.getMensagem("aguarde_impressao"));
            tabela.getChildren().remove(barraSuperior);
            trabalho.getJobSettings().setPageLayout(paisagem);
            tabela.setMaxSize(largura, altura);
            ObservableList itens = listaExtrato.getItems();
            for(int i=0; i<itens.size();i+=18){
                int end = (i+18<itens.size()) ? i+18 : itens.size();
                listaExtrato.setItems(FXCollections.observableList(itens.subList(i, end)));
                trabalho.printPage(tabela);
            }
            tabela.add(barraSuperior, 0, 0);
            tabela.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
            listaExtrato.setItems(itens);
            aguarde.hide();
        }
        trabalho.endJob();
    }
}
 
开发者ID:badernageral,项目名称:bgfinancas,代码行数:26,代码来源:RelatoriosControlador.java

示例2: print

import javafx.print.PrinterJob; //导入依赖的package包/类
public void print()
{
	Printer printer = Printer.getDefaultPrinter();
       Stage stage = new Stage(StageStyle.DECORATED);            
       PrinterJob job = PrinterJob.createPrinterJob(printer);
           if (job != null) {                    
               boolean showDialog = job.showPageSetupDialog(stage);
               if (showDialog) {                        
               	myPrint.setScaleX(0.46);
               	myPrint.setScaleY(0.46);
               	myPrint.setTranslateX(-252);
               	myPrint.setTranslateY(-110);
               boolean success = job.printPage(myPrint);
                   if (success) {
                        job.endJob(); 
                   } 
                   myPrint.setTranslateX(0);
                   myPrint.setTranslateY(0);               
                   myPrint.setScaleX(1.0);
                   myPrint.setScaleY(1.0); 
               }
           }
}
 
开发者ID:mikemacharia39,项目名称:gatepass,代码行数:24,代码来源:DailyGenerated.java

示例3: handlePrintButton

import javafx.print.PrinterJob; //导入依赖的package包/类
@FXML
private void handlePrintButton(ActionEvent event) {
    Printer printer = Printer.getDefaultPrinter();
    printer.createPageLayout(Paper.A4, PageOrientation.PORTRAIT, Printer.MarginType.EQUAL);
    PrinterJob job = PrinterJob.createPrinterJob(printer);
    job.showPrintDialog(owner);
    if (job != null) {
        engine.print(job);
        job.endJob();
    }
}
 
开发者ID:kmrifat,项目名称:Dr-Assistant,代码行数:12,代码来源:ViewTemplateController.java

示例4: handlePrintButton

import javafx.print.PrinterJob; //导入依赖的package包/类
@FXML
private void handlePrintButton(ActionEvent event) {
    Printer printer = Printer.getDefaultPrinter();
    printer.createPageLayout(Paper.A4, PageOrientation.PORTRAIT, Printer.MarginType.EQUAL);
    PrinterJob job = PrinterJob.createPrinterJob(printer);
    job.showPrintDialog(owner);
    
    if (job != null) {
        engine.print(job);
        job.endJob();
    }
}
 
开发者ID:kmrifat,项目名称:Dr-Assistant,代码行数:13,代码来源:ViewPrescriptionController.java

示例5: print

import javafx.print.PrinterJob; //导入依赖的package包/类
public void print() {
    PrinterJob job = PrinterJob.createPrinterJob();
    boolean proceed = dialogService.showPrintDialog(job);
    if (!proceed) {
        return;
    }

    BackgroundTask.wrap(() -> {
        job.getJobSettings().setJobName(bibEntry.flatMap(BibEntry::getCiteKeyOptional).orElse("NO ENTRY"));
        previewView.getEngine().print(job);
        job.endJob();
        return null;
    })
            .onFailure(exception -> dialogService.showErrorDialogAndWait(Localization.lang("Could not print preview"), exception))
            .executeWith(Globals.TASK_EXECUTOR);
}
 
开发者ID:JabRef,项目名称:jabref,代码行数:17,代码来源:PreviewPanel.java

示例6: printImage

import javafx.print.PrinterJob; //导入依赖的package包/类
/**
 * Print image.
 */
@FXML
public void printImage() {
    PrinterJob printerJob = PrinterJob.createPrinterJob();
    printerJob.showPrintDialog(printNode.getScene().getWindow());
    if (printerJob != null) {
        boolean success = printerJob.printPage(printNode);
        if (success) {
            printerJob.endJob();
        }
    }
}
 
开发者ID:RudyB,项目名称:Optics-Simulator,代码行数:15,代码来源:MenuBarController.java

示例7: printActiveFile

import javafx.print.PrinterJob; //导入依赖的package包/类
@Override
public void printActiveFile()
{
	CodeEditor activeEditor = getActiveCodeEditor();
	if (activeEditor == null)
	{
		Dialogues.showActionFailedDialogue("No file is open!");
		return;
	}
	
	PrinterJob printAction = PrinterJob.createPrinterJob();
	if (printAction == null)
	{
		Dialogues.showActionFailedDialogue("Unable to access system print utilities");
		return;
	}
	
	boolean notCancelled = printAction.showPrintDialog(stage);
	if (notCancelled)
	{
		boolean success = printAction.printPage(activeEditor);
		if (success)
			printAction.endJob();
		else
			Dialogues.showActionFailedDialogue("Print may have failed");
	}
}
 
开发者ID:dhawal9035,项目名称:WebPLP,代码行数:28,代码来源:Main.java

示例8: printURL

import javafx.print.PrinterJob; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void printURL(String url)
{
    Platform.runLater(new Runnable() {
        @Override public void run() {
            try {
                WebView view = new WebView();
                WebEngine engine = view.getEngine();
                engine.getLoadWorker().stateProperty().addListener((ChangeListener) (obsValue, oldState, newState) -> {
                   if (newState == State.SUCCEEDED) {
                       Document doc = engine.getDocument();
                       // don't know why, but this was necessary to get the font-size smaller for results, prints fine under Chrome but not WebView
                       Element extrastyle = doc.createElement("style");
                       extrastyle.appendChild(doc.createTextNode(".container-fluid { font-size: 0.65rem !important; } table td span { white-space: nowrap; }"));
                       doc.getDocumentElement().getElementsByTagName("head").item(0).appendChild(extrastyle);

                       PrinterJob job = PrinterJob.createPrinterJob();
                       if (job == null) {
                           log.warning("Unable to create a print job.  Opening in a browser instead.");
                           openURL(url);
                           return;
                       }

                       if (job.showPrintDialog(null)) {
                           engine.print(job);
                           job.endJob();
                       }
                   }
                });
                engine.load(url);
            } catch (Exception e) {
                log.log(Level.SEVERE, "\bCould not print:" + e, e);
            }
        }
    });
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:37,代码来源:BrowserControl.java

示例9: printJob

import javafx.print.PrinterJob; //导入依赖的package包/类
/********************************
 * 작성일 : 2016. 6. 29. 작성자 : KYJ
 *
 * print 처리.
 *
 * @param window
 * @param target
 ********************************/
public static void printJob(Window window, Node target) {
	Printer printer = Printer.getDefaultPrinter();
	// PrinterAttributes printerAttributes = printer.getPrinterAttributes();
	//
	Paper a4 = Paper.A4;

	// Paper a4 = PrintHelper.createPaper("Rotate A4", Paper.A4.getHeight(),
	// Paper.A4.getWidth(), Units.MM);
	PageLayout pageLayout = printer.createPageLayout(a4, PageOrientation.REVERSE_PORTRAIT, MarginType.DEFAULT);

	PrinterJob printerJob = PrinterJob.createPrinterJob();

	// JobSettings jobSettings = printerJob.getJobSettings();
	// jobSettings.setPrintSides(PrintSides.TUMBLE);
	ImageView imageView = new ImageView();
	// 화면 사이즈에 맞게 크기 조절.
	Callback<SnapshotResult, Void> callback = param -> {
		final WritableImage image = param.getImage();
		imageView.setImage(image);

		final double scaleX = pageLayout.getPrintableWidth() / imageView.getBoundsInParent().getWidth();
		final double scaleY = pageLayout.getPrintableHeight() / imageView.getBoundsInParent().getHeight();
		imageView.getTransforms().add(new Scale(scaleX, scaleY));

		return null;
	};

	target.snapshot(callback, null, null);

	if (printerJob.showPrintDialog(window) && printerJob.printPage(pageLayout, imageView))
		printerJob.endJob();
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:41,代码来源:FxUtil.java

示例10: print

import javafx.print.PrinterJob; //导入依赖的package包/类
/** Scales the node based on the standard letter, portrait paper to be printed.
 * @param node The scene node to be printed.
 */
public void print() {
	PrinterJob job = PrinterJob.createPrinterJob();
	if (job != null) {
		agenda.print(job);
		job.endJob();
	}
}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:11,代码来源:AgendaSample1.java

示例11: showPrintDialog

import javafx.print.PrinterJob; //导入依赖的package包/类
@Override
public boolean showPrintDialog(PrinterJob job) {
    return job.showPrintDialog(null);
}
 
开发者ID:JabRef,项目名称:jabref,代码行数:5,代码来源:FXDialogService.java

示例12: print

import javafx.print.PrinterJob; //导入依赖的package包/类
public void print (){
    Stage stage=(Stage) lCambio.getScene().getWindow();
    Node node = text;
    PrinterJob job = PrinterJob.createPrinterJob();
    //job.showPageSetupDialog(stage);
    if (job != null) {
        boolean success = job.printPage(node);
        if (success) {
            job.endJob();
        }
    }
}
 
开发者ID:antoniotorres,项目名称:CAPOS,代码行数:13,代码来源:imprimirController.java

示例13: main

import javafx.print.PrinterJob; //导入依赖的package包/类
public static void main(String[] args) {

        Printer pdfPrinter = null;

        // Windows: Instal PDF24 from http://en.pdf24.org
        // Linux: Install cups-pdf http://www.cups-pdf.de

        // Optionally PDF24 could be configured for silent mode from
        // "C:\Program Files (x86)\PDF24\pdf24-SettingsUITool.exe" from the Menu "PDF Printer"
        // Set "Automatically save..." checkbox to true

        Iterator<Printer> iter = Printer.getAllPrinters().iterator();
        while (iter.hasNext()) {
            Printer printer = iter.next();
            if (printer.getName().endsWith("PDF")) {
                pdfPrinter = printer;
            }
        }

        String url = PDFPrinting.class.getResource("/sample-page.html").toExternalForm();

        Page page = BrowserFactory
            .getWebKit()
            .navigate(url);

        WebEngine engine = (WebEngine) page.getEngine();

        // Note: Optionally -webkit-print-color-adjust: exact; could be used for fix background-color problem
        // @see http://stackoverflow.com/questions/14987496/background-color-not-showing-in-print-preview

        PrinterJob job = null;
        try {
            page.show();
            // clear margins
            PageLayout layout = pdfPrinter.createPageLayout(Paper.A4, PageOrientation.PORTRAIT, MarginType.HARDWARE_MINIMUM);

            job = PrinterJob.createPrinterJob(pdfPrinter);
            job.getJobSettings().setPageLayout(layout);
            job.getJobSettings().setJobName("Sample Printing Job");

            engine.print(job);
            job.endJob();
        } finally {
            if (job != null) {
                job.endJob();
            }
            page.close();
        }
    }
 
开发者ID:webfolderio,项目名称:ui4j,代码行数:50,代码来源:PDFPrinting.java

示例14: showPrintDialog

import javafx.print.PrinterJob; //导入依赖的package包/类
/**
 * Displays a Print Dialog. Allow the user to update job state such as printer and settings. These changes will be
 * available in the appropriate properties after the print dialog has returned. The print dialog is also used to
 * confirm the user wants to proceed with printing.
 *
 * @param job the print job to customize
 * @return false if the user opts to cancel printing
 */
boolean showPrintDialog(PrinterJob job);
 
开发者ID:JabRef,项目名称:jabref,代码行数:10,代码来源:DialogService.java


注:本文中的javafx.print.PrinterJob类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。