本文整理汇总了Java中java.awt.print.Book类的典型用法代码示例。如果您正苦于以下问题:Java Book类的具体用法?Java Book怎么用?Java Book使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Book类属于java.awt.print包,在下文中一共展示了Book类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: print
import java.awt.print.Book; //导入依赖的package包/类
/**
* 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);
}
}
}
示例2: initialize
import java.awt.print.Book; //导入依赖的package包/类
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);
}
}
示例3: doPrint
import java.awt.print.Book; //导入依赖的package包/类
/**
* 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();
}
}
示例4: printFile
import java.awt.print.Book; //导入依赖的package包/类
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(); }
}
}
示例5: actionPerformed
import java.awt.print.Book; //导入依赖的package包/类
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);
}
}
}
示例6: printPopG
import java.awt.print.Book; //导入依赖的package包/类
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();
}
}
}
示例7: print
import java.awt.print.Book; //导入依赖的package包/类
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);
}
}
}
示例8: print
import java.awt.print.Book; //导入依赖的package包/类
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);
}
}
示例9: print
import java.awt.print.Book; //导入依赖的package包/类
/**
* 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();
}
}
示例10: createBook
import java.awt.print.Book; //导入依赖的package包/类
/** 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;
}
示例11: doPrint
import java.awt.print.Book; //导入依赖的package包/类
/**
* 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();
}
}
示例12: print
import java.awt.print.Book; //导入依赖的package包/类
/**
* 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());
}
}
}
示例13: printPages
import java.awt.print.Book; //导入依赖的package包/类
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();
}
}
});
}
示例14: main
import java.awt.print.Book; //导入依赖的package包/类
public static void main(String args[]) {
new Book().getNumberOfPages();
}
示例15: printInfo
import java.awt.print.Book; //导入依赖的package包/类
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();
}