Java 类java.awt.print.Book 实例源码

项目:PhET    文件:PNode.java   
/**
 * Constructs a new PrinterJob, allows the user to select which printer to
 * print to, And then prints the node.
 */
public void print() {
    final PrinterJob printJob = PrinterJob.getPrinterJob();
    final PageFormat pageFormat = printJob.defaultPage();
    final Book book = new Book();
    book.append(this, pageFormat);
    printJob.setPageable(book);

    if (printJob.printDialog()) {
        try {
            printJob.print();
        }
        catch (final PrinterException e) {
            throw new RuntimeException("Error Printing", e);
        }
    }
}
项目:NICON    文件:PrintPdf.java   
private void initialize(byte[] pdfContent, String jobName,String nomeImpressora) throws IOException, PrinterException {
    ByteBuffer bb = ByteBuffer.wrap(pdfContent);

    PDFFile pdfFile = new PDFFile(bb);
    PDFPrintPage pages = new PDFPrintPage(pdfFile);

    PrintService[] pservices = PrinterJob.lookupPrintServices();

    System.out.println(pservices.length);
    if (pservices.length > 0) {
        for (PrintService ps : pservices) {
            System.out.println("Impressora Encontrada: " + ps.getName());

            if (ps.getName().contains(nomeImpressora)) {
                System.out.println("Impressora Selecionada: " + nomeImpressora);
                impressora = ps;
                break;
            }
        }
    }
    if (impressora != null) {
        pjob = PrinterJob.getPrinterJob();
        pjob.setPrintService(impressora);

        PageFormat pf = PrinterJob.getPrinterJob().defaultPage();

        pjob.setJobName(jobName);
        Book book = new Book();
        book.append(pages, pf, pdfFile.getNumPages());
        pjob.setPageable(book);


        Paper paper = new Paper();
        paper.setSize(getWidth, getHeight);
        paper.setImageableArea(margin, (int) margin / 4, getWidth - margin * 2, getHeight - margin * 2);
        //paper.setImageableArea(margin,margin, paper.getWidth()-margin*2,paper.getHeight()-margin*2);
        pf.setOrientation(orientacao);
        pf.setPaper(paper);
    }
}
项目:willow-browser    文件:PDFViewer.java   
/**
 * Print the current document.
 */
public void doPrint() {
    PrinterJob pjob = PrinterJob.getPrinterJob();
    pjob.setJobName(docName);
    Book book = new Book();
    PDFPrintPage pages = new PDFPrintPage(curFile);
    book.append(pages, pformat, curFile.getNumPages());

    pjob.setPageable(book);
    if (pjob.printDialog()) {
        new PrintThread(pages, pjob).start();
    }
}
项目:Java_Paint    文件:Paint_GUI.java   
public void printFile() {
    PrinterJob print = PrinterJob.getPrinterJob();
    PageFormat format = print.pageDialog(new PageFormat());
    if (print.printDialog()) {
        Book b = new Book();
        b.append((Printable)this.bufferGraphics, format);
        print.setPageable(b);
        try { print.print(); }
            catch(PrinterException ex) { ex.printStackTrace(); }
    }
}
项目:NICON    文件:PrintPdf.java   
private void initialize(byte[] pdfContent, String jobName,String nomeImpressora) throws IOException, PrinterException {
    ByteBuffer bb = ByteBuffer.wrap(pdfContent);

    PDFFile pdfFile = new PDFFile(bb);
    PDFPrintPage pages = new PDFPrintPage(pdfFile);

    PrintService[] pservices = PrinterJob.lookupPrintServices();

    System.out.println(pservices.length);
    if (pservices.length > 0) {
        for (PrintService ps : pservices) {
            System.out.println("Impressora Encontrada: " + ps.getName());

            if (ps.getName().contains(nomeImpressora)) {
                System.out.println("Impressora Selecionada: " + nomeImpressora);
                impressora = ps;
                break;
            }
        }
    }
    if (impressora != null) {
        pjob = PrinterJob.getPrinterJob();
        pjob.setPrintService(impressora);

        PageFormat pf = PrinterJob.getPrinterJob().defaultPage();

        pjob.setJobName(jobName);
        Book book = new Book();
        book.append(pages, pf, pdfFile.getNumPages());
        pjob.setPageable(book);


        Paper paper = new Paper();
        paper.setSize(getWidth, getHeight);
        paper.setImageableArea(margin, (int) margin / 4, getWidth - margin * 2, getHeight - margin * 2);
        //paper.setImageableArea(margin,margin, paper.getWidth()-margin*2,paper.getHeight()-margin*2);
        pf.setOrientation(orientacao);
        pf.setPaper(paper);
    }
}
项目:ArasuiteIta    文件:TProjectPrintAction.java   
public void actionPerformed(ActionEvent e) {

    // Get the print manager
    PrinterJob printJob = PrinterJob.getPrinterJob();
    Book book = new Book();
    int pages = getEditor().getBoardContainerCount();
    for (int i = 0; i < pages; i++) {
        TBoardContainer boardContainer = getEditor().getBoardContainer(i);
        // Clear selection
        boardContainer.getBoard().clearSelection();
        Dimension boardSize = TBoardConstants.getSize(boardContainer.getBoard().getAttributes(null));
        PageFormat page = printJob.defaultPage();
        if (boardSize.getWidth() > boardSize.getHeight())
            page.setOrientation(PageFormat.LANDSCAPE);
        else
            page.setOrientation(PageFormat.PORTRAIT);
        book.append(boardContainer, page);
    }
    // Set the component to print
    printJob.setPageable(book);
    if (printJob.printDialog()) {
        try {
            printJob.print();
        } catch (Exception ex) {
            // If the print fails show an error message
            JOptionPane.showMessageDialog(null,
                    TLanguage.getString("TProjectPrintAction.PRINT_ERROR"),
                    TLanguage.getString("TProjectPrintAction.ERROR") + "!",
                    JOptionPane.ERROR_MESSAGE);
        }
    }
}
项目:mars-sim    文件:PopGUserInterface.java   
public void printPopG() {
    PrinterJob pj = PrinterJob.getPrinterJob(); 
    Book book = new Book();
    PageFormat documentPageFormat = new PageFormat();
    documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
    book.append(new Document(), documentPageFormat);
    pj.setPageable(book);
    if (pj.printDialog()) {
        try {
            pj.print();
        } catch (Exception PrintException) {
            PrintException.printStackTrace();
        }
      }
}
项目:universal-java-matrix-package    文件:PrintPreviewPanel.java   
public void print() {
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    Book book = new Book();
    book.append(new PrintPage(), pageFormat);
    printerJob.setPageable(book);
    boolean doPrint = printerJob.printDialog();
    if (doPrint) {
        try {
            printerJob.print();
        } catch (PrinterException exception) {
            System.err.println("Printing error: " + exception);
        }
    }
}
项目:metasfresh    文件:PrintingEngine.java   
private void print(final PrintPackageRequest request) throws PrinterException
{
    logger.log(Level.FINE, "Printing request {}", request);

    // Create Print Job
    final PrinterJob pjob = PrinterJob.getPrinterJob();
    pjob.setJobName(request.getPrintJobName());

    final PageFormat pf = pjob.defaultPage();
    final Paper paper = pjob.defaultPage().getPaper();
    final MediaSize size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A4);

    paper.setSize(size.getSize(Size2DSyntax.INCH)[0] * 72, size.getSize(Size2DSyntax.INCH)[1] * 72);
    paper.setImageableArea(0, 0, size.getSize(Size2DSyntax.INCH)[0] * 72, size.getSize(Size2DSyntax.INCH)[1] * 72);
    pf.setPaper(paper);

    final Book book = new Book();// java.awt.print.Book
    book.append(request.getPrintable(), pf, request.getNumPages());
    pjob.setPageable(book);

    pjob.setPrintService(request.getPrintService());
    pjob.print(request.getAttributes());

    // task 09618: allow us to configure the client to return an error even if everything went OK, so we can test
    final String alwaysReturnError = Context.getContext().getProperty(Context.CTX_Testing_AlwaysReturnError, Context.DEFAULT_AlwaysReturnError);
    if (Boolean.parseBoolean(alwaysReturnError))
    {
        logger.log(Level.INFO, "{} is true, so we report an error, despite the print was OK", Context.CTX_Testing_AlwaysReturnError);

        final String errorMsg = Context.getContext().getProperty(Context.CTX_Testing_ErrorMessage, Context.DEFAULT_ErrorMessage);
        throw new PrinterException(errorMsg);
    }
}
项目:piccolo2d.java    文件:PNode.java   
/**
 * Constructs a new PrinterJob, allows the user to select which printer to
 * print to, And then prints the node.
 * @throws PrinterException if print fails
 */
public void print() throws PrinterException {
    final PrinterJob printJob = PrinterJob.getPrinterJob();
    final PageFormat pageFormat = printJob.defaultPage();
    final Book book = new Book();
    book.append(this, pageFormat);
    printJob.setPageable(book);

    if (printJob.printDialog()) {
        printJob.print();
    }
}
项目:MathEOS    文件:Formatter.java   
/** Méthode qui formatte le contenu de l'éditeur en pages, rangées dans un Book.
 * Cette méthode modifie les variables book et pages.
 **/
public Book createBook() {
    book = new Book();
    pages = decouperEnPages();
    book.append(this, page, pages.size());
    return book;
}
项目:LoboEvolution    文件:PdfDialog.java   
/**
 * Print the current document.
 */
public void doPrint() {
    PrinterJob pjob = PrinterJob.getPrinterJob();
    pjob.setJobName(docName);
    Book book = new Book();
    PDFPrintPage pages = new PDFPrintPage(curFile);
    book.append(pages, pformat, curFile.getNumPages());
    pjob.setPageable(book);
    if (pjob.printDialog()) {
        new PrintThread(pages, pjob).start();
    }
}
项目:JLS    文件:JLSStart.java   
/**
 * Print circuit currently being edited, plus any state machines.
 * 
 * @param all True to print the entire circuit, false to print just what's visible.
 */
public void print(boolean all) {

    // get the currently selected editor, return if none
    Editor ed = (Editor)(edits.getSelectedComponent());
    if (ed == null)
        return;

    // set up printer job
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat format = job.defaultPage();
    format.setOrientation(PageFormat.LANDSCAPE);
    Book book = new Book();

    // find all unique sub-circuits (and their state machines)
    if (all) {
        ed.getCircuit().addToBook(book,format);
    }
    else {
        book.append(ed.getCircuit(),format);
    }

    // finish up book
    job.setPageable(book);

    // show dialog, and if ok, print
    if (job.printDialog()) {
        try {
            job.print();
        }
        catch (PrinterException ex) {
            System.out.println("printing error: " + ex.getMessage());
        }
    }
}
项目:neoeedit    文件:U.java   
void printPages() {

            U.startThread(new Thread() {
                @Override
                public void run() {
                    try {
                        PrinterJob job = PrinterJob.getPrinterJob();
                        PageFormat pf = job.pageDialog(job.defaultPage());
                        totalPage = getTotalPage(pf);
                        if (totalPage <= 0) {
                            return;
                        }
                        dim = new Dimension((int) pf.getImageableWidth(), (int) pf.getImageableHeight());
                        Book bk = new Book();
                        bk.append(Print.this, pf, totalPage);
                        job.setPageable(bk);
                        if (job.printDialog()) {
                            ui.message("printing...");
                            uiComp.repaint();
                            job.print();
                            ui.message("print ok");
                            uiComp.repaint();
                        }
                    } catch (Exception e) {
                        ui.message("err:" + e);
                        uiComp.repaint();
                        e.printStackTrace();
                    }
                }
            });
        }
项目:openjdk-jdk10    文件:HeadlessBook.java   
public static void main(String args[]) {
    new Book().getNumberOfPages();
}
项目:openjdk9    文件:HeadlessBook.java   
public static void main(String args[]) {
    new Book().getNumberOfPages();
}
项目:xqres    文件:PrinterInfo.java   
public void printInfo() throws Exception{
//      int height = 225+15*foodInfos.size();
        int height = getHeight();

        Book book = new Book();
        //设置成竖打 
        PageFormat pf = new PageFormat();
        pf.setOrientation(PageFormat.PORTRAIT);

        //通过Paper设置页面的空白边距和可打印区域。必须与实际打印纸张大小相符。  

        Paper p = new Paper();
//      p.setSize(590, 840);
        p.setSize(163,height);//纸张大小
        //A4(595 X 842)设置打印区域,其实0,0应该是72,72,因为A4纸的默认X,Y边距是72
//      p.setImageableArea(10,10, 590,840);
        p.setImageableArea(start_x, -20, 163, height + 20);
        pf.setPaper(p);

        //把 PageFormat 和 Printable 添加到书中,组成一个页面 
        book.append(this, pf);

        //获取打印机服务对象, 默认打印机
        PrinterJob job = PrinterJob.getPrinterJob();
        logger.info("#printInfo. jobName: "+job.getJobName()+", userName; "+job.getUserName());
        logger.info("#printInfo. 打印机名称: "+job.getPrintService().getName());

        //日志输出打印机的各项属性  
        AttributeSet attrs = job.getPrintService().getAttributes();
        logger.info("****************************************************");
        for (Attribute attr : attrs.toArray()) {
            String attributeName = attr.getName();
            String attributeValue = attrs.get(attr.getClass()).toString();
            logger.info("*"+attributeName + " : " + attributeValue);
        }
        logger.info("****************************************************");

        //设置打印类
        job.setPageable(book);

        //可以用printDialog显示打印对话框,在用户确认后打印;也可以直接打印 
        /*boolean a=job.printDialog();
        logger.info("#print. a="+a);*/

        job.print();

    }
项目:LoboEvolution    文件:PDFPrintPage.java   
/**
 * An example method to print a file.
 *
 * @param filename
 *            The path of the PDF file to print.
 * @param setupPaper
 *            true to post a page setup dialog
 * @throws java.io.IOException
 */
public void printFile(String filename, boolean setupPaper) throws IOException {
    FileInputStream fis = null;
    try {
        File file = new File(filename);
        fis = new FileInputStream(file);
        FileChannel fc = fis.getChannel();
        ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
        PDFFile pdfFile = new PDFFile(bb); // Create PDF Print Page

        PDFPrintPage pages = new PDFPrintPage(pdfFile);

        // Create Print Job.
        // We set the margins to 0, on the default 8.5 x 11 paper

        PrinterJob pjob = PrinterJob.getPrinterJob();
        PageFormat pfDefault = PrinterJob.getPrinterJob().defaultPage();
        Paper defaultPaper = new Paper();
        defaultPaper.setImageableArea(0, 0, defaultPaper.getWidth(), defaultPaper.getHeight());
        pfDefault.setPaper(defaultPaper);
        if (setupPaper) {
            pfDefault = PrinterJob.getPrinterJob().pageDialog(pfDefault);
        }
        pjob.setJobName(file.getName());
        if (pjob.printDialog()) {
            // validate the page against the chosen printer to correct
            // paper settings and margins
            pfDefault = pjob.validatePage(pfDefault);
            Book book = new Book();

            book.append(pages, pfDefault, pdfFile.getNumPages());
            pjob.setPageable(book);

            try {
                pjob.print();
            } catch (PrinterException exc) {
                logger.log(Level.ERROR, exc);
            }
        }
    } finally {
        if (fis != null) {
            fis.close();
        }
    }
}
项目:OpenJSharp    文件:RasterPrinterJob.java   
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
项目:jdk8u-jdk    文件:RasterPrinterJob.java   
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
项目:openjdk-jdk10    文件:RasterPrinterJob.java   
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
项目:openjdk9    文件:RasterPrinterJob.java   
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
项目:jdk8u_jdk    文件:RasterPrinterJob.java   
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
项目:lookaside_java-1.8.0-openjdk    文件:RasterPrinterJob.java   
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
项目:infobip-open-jdk-8    文件:RasterPrinterJob.java   
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
项目:jdk8u-dev-jdk    文件:RasterPrinterJob.java   
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
项目:jdk7-jdk    文件:RasterPrinterJob.java   
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
项目:openjdk-source-code-learn    文件:RasterPrinterJob.java   
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
项目:OLD-OpenJDK8    文件:RasterPrinterJob.java   
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
项目:openjdk-jdk7u-jdk    文件:RasterPrinterJob.java   
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
项目:openjdk-icedtea7    文件:RasterPrinterJob.java   
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
项目:elexis-3-base    文件:Printer.java   
/**
  * Constructor: Print prescription
  * <p>
  *  
  */
 public Printer(Physician ph, Rezept rp, String presID, String QRCode) {


   //Create a printerJob object
   PrinterJob printJob = PrinterJob.getPrinterJob();
   //Create printerJob to simulate the required number of pages
   PrinterJob printJobSimulation = PrinterJob.getPrinterJob();


   //Set the name of the PrinterJob
   printJob.setJobName(presID);

   //Define the page format including margins
   PageFormat pf = printJob.defaultPage();  
   Paper paper = new Paper();  

   double marginHeight = paper.getHeight()*HMARGINRATIO;   
   double marginWidth = paper.getWidth()*WMARGINRATIO;   

   paper.setImageableArea(marginWidth, marginHeight, paper.getWidth() - marginWidth * 2, paper.getHeight()  
       - marginHeight * 2);  

   pf.setPaper(paper);  

//Determine the number of pages and the last product of each page based on the strings to be printed
   Book bkSimulation = new Book(); 
   Pagecounter pcounter = new Pagecounter(ph,rp,presID,QRCode);
   bkSimulation.append(pcounter,pf);

   printJobSimulation.setPageable(bkSimulation);

   //Do the simulation
   try {

    printJobSimulation.print();

} catch (PrinterException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}


   //Get the indices (last item per page) from the simulation
   List<Integer> pageIndices = pcounter.getIndices();

   //Create a book with the determined number of pages
   Book bk = new Book(); 

   //Create now the pages of the book (new instances of PrintPage for each page)
   //Specify, which of the listed products is the first and the last on this page

   for(int i = 0; i < pageIndices.size()-1; i = i+1) {    

       bk.append(new Page(ph,rp,presID,QRCode,pageIndices.get(i)+1, pageIndices.get(i+1)),pf);

   }

   //Assign the pages
   printJob.setPageable(bk);  

   //Show print dialog and start printing if "yes"
   if (printJob.printDialog()) {

     try {

      printJob.print();

     } catch (Exception PrintException) {
       PrintException.printStackTrace();
     }
   }

 }