本文整理汇总了Java中java.awt.print.PageFormat.setPaper方法的典型用法代码示例。如果您正苦于以下问题:Java PageFormat.setPaper方法的具体用法?Java PageFormat.setPaper怎么用?Java PageFormat.setPaper使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.print.PageFormat
的用法示例。
在下文中一共展示了PageFormat.setPaper方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPageFormat
import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
* Get an instance of {@link java.awt.print.PageFormat}.
* @param pj {@link java.awt.print.PrinterJob} which is
* associated with the default printer.
* @return an instance of <code>PageFormat</code> that describes the size and
* orientation of a page to be printed.
*/
public static PageFormat getPageFormat(PrinterJob pj) {
PageFormat pageFormat = null;
pageFormat = pj.defaultPage();
Paper p = pageFormat.getPaper();
int pageOrientation = getPreferences().getInt(PROP_PAGE_ORIENTATION, pageFormat.getOrientation());
double paperWidth = getPreferences().getDouble(PROP_PAGE_WIDTH, p.getWidth());
double paperHeight = getPreferences().getDouble(PROP_PAGE_HEIGHT, p.getHeight());
double iaWidth = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_WIDTH, p.getImageableWidth());
double iaHeight = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_HEIGHT, p.getImageableHeight());
double iaX = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_X, p.getImageableX());
double iaY = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_Y, p.getImageableY());
pageFormat.setOrientation(pageOrientation);
p.setSize(paperWidth, paperHeight);
p.setImageableArea(iaX, iaY, iaWidth, iaHeight);
pageFormat.setPaper(p);
return pageFormat;
}
示例2: actionPerformed
import java.awt.print.PageFormat; //导入方法依赖的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);
}
}
}
}
示例3: printTest
import java.awt.print.PageFormat; //导入方法依赖的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);
}
}
}
示例4: testGetPageFormat
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public void testGetPageFormat() {
PrinterJob pj = PrinterJob.getPrinterJob();
PageFormat expResult = PrintPreferences.getPageFormat(pj);
PrintPreferences.setPageFormat(expResult);
PageFormat result = PrintPreferences.getPageFormat(pj);
assertEquals(expResult.getHeight(), result.getHeight());
assertEquals(expResult.getWidth(), result.getWidth());
assertEquals(expResult.getOrientation(), result.getOrientation());
assertEquals(expResult.getPaper().getHeight(), result.getPaper().getHeight());
assertEquals(expResult.getPaper().getWidth(), result.getPaper().getWidth());
assertEquals(expResult.getPaper().getImageableHeight(), result.getPaper().getImageableHeight());
assertEquals(expResult.getPaper().getImageableWidth(), result.getPaper().getImageableWidth());
assertEquals(expResult.getPaper().getImageableX(), result.getPaper().getImageableX());
assertEquals(expResult.getPaper().getImageableY(), result.getPaper().getImageableY());
double w = expResult.getPaper().getWidth() + 10;
double h = expResult.getPaper().getHeight() + 10;
Paper p = expResult.getPaper();
double ix = p.getImageableX() + 10;
double iy = p.getImageableY() + 10;
double iw = p.getImageableWidth() + 10;
double ih = p.getImageableHeight() + 10;
p.setImageableArea(ix, iy, iw, ih);
p.setSize(w, h);
expResult.setPaper(p);
PrintPreferences.setPageFormat(expResult);
assertEquals(h, PrintPreferences.getPageFormat(pj).getHeight());
assertEquals(w, PrintPreferences.getPageFormat(pj).getWidth());
assertEquals(ix, PrintPreferences.getPageFormat(pj).getPaper().getImageableX());
assertEquals(iy, PrintPreferences.getPageFormat(pj).getPaper().getImageableY());
assertEquals(iw, PrintPreferences.getPageFormat(pj).getPaper().getImageableWidth());
assertEquals(ih, PrintPreferences.getPageFormat(pj).getPaper().getImageableHeight());
expResult.setOrientation(PageFormat.REVERSE_LANDSCAPE);
PrintPreferences.setPageFormat(expResult);
assertEquals(PageFormat.REVERSE_LANDSCAPE, PrintPreferences.getPageFormat(pj).getOrientation());
}
示例5: EPSPrinter
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public EPSPrinter(Printable printable, String title,
PrintStream stream,
int x, int y, int wid, int hgt) {
this.printable = printable;
this.epsTitle = title;
this.stream = stream;
llx = x;
lly = y;
urx = llx+wid;
ury = lly+hgt;
// construct a PageFormat with zero margins representing the
// exact bounds of the applet. ie construct a theoretical
// paper which happens to exactly match applet panel size.
Paper p = new Paper();
p.setSize((double)wid, (double)hgt);
p.setImageableArea(0.0,0.0, (double)wid, (double)hgt);
pf = new PageFormat();
pf.setPaper(p);
}
示例6: actionPerformed
import java.awt.print.PageFormat; //导入方法依赖的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);
}
}
}
}
示例7: doTest
import java.awt.print.PageFormat; //导入方法依赖的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: validatePage
import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
* The passed in PageFormat is cloned and altered to be usable on
* the PrinterJob's current printer.
*/
public PageFormat validatePage(PageFormat page) {
PageFormat newPage = (PageFormat)page.clone();
Paper newPaper = new Paper();
validatePaper(newPage.getPaper(), newPaper);
newPage.setPaper(newPaper);
return newPage;
}
示例9: validatePage
import java.awt.print.PageFormat; //导入方法依赖的package包/类
/**
* The passed in PageFormat is cloned and altered to be usable on
* the PrinterJob's current printer.
*/
private PageFormat validatePage(PageFormat page) {
PageFormat newPage = (PageFormat)page.clone();
Paper newPaper = new Paper();
validatePaper(newPage.getPaper(), newPaper);
newPage.setPaper(newPaper);
return newPage;
}
示例10: printableJob
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public void printableJob(Printable printable) throws PrintException {
try {
synchronized(this) {
if (job != null) { // shouldn't happen
throw new PrintException("already printing");
} else {
job = new PSPrinterJob();
}
}
job.setPrintService(getPrintService());
job.setCopies(copies);
job.setJobName(jobName);
PageFormat pf = new PageFormat();
if (mediaSize != null) {
Paper p = new Paper();
p.setSize(mediaSize.getX(MediaSize.INCH)*72.0,
mediaSize.getY(MediaSize.INCH)*72.0);
p.setImageableArea(72.0, 72.0, p.getWidth()-144.0,
p.getHeight()-144.0);
pf.setPaper(p);
}
if (orient == OrientationRequested.REVERSE_LANDSCAPE) {
pf.setOrientation(PageFormat.REVERSE_LANDSCAPE);
} else if (orient == OrientationRequested.LANDSCAPE) {
pf.setOrientation(PageFormat.LANDSCAPE);
}
job.setPrintable(printable, pf);
job.print(reqAttrSet);
notifyEvent(PrintJobEvent.DATA_TRANSFER_COMPLETE);
return;
} catch (PrinterException pe) {
notifyEvent(PrintJobEvent.JOB_FAILED);
throw new PrintException(pe);
} finally {
printReturned = true;
notifyEvent(PrintJobEvent.NO_MORE_EVENTS);
}
}
示例11: PolylinePrintingTest
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public PolylinePrintingTest() throws PrinterException {
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
Paper p = pf.getPaper();
p.setImageableArea(0,0,p.getWidth(), p.getHeight());
pf.setPaper(p);
job.setPrintable(this, pf);
if (job.printDialog()) {
job.print();
}
}
示例12: initialize
import java.awt.print.PageFormat; //导入方法依赖的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);
}
}
示例13: getPageFormat
import java.awt.print.PageFormat; //导入方法依赖的package包/类
public static PageFormat getPageFormat(String name, PageFormat pageFormat) {
Properties properties = getProperties(name);
if (properties == null)
return pageFormat;
final String orientation = properties.getProperty(ORIENTATION);
if (LANDSCAPE.equals(orientation))
pageFormat.setOrientation(PageFormat.LANDSCAPE);
else if (PORTRAIT.equals(orientation))
pageFormat.setOrientation(PageFormat.PORTRAIT);
else if (REVERSE_LANDSCAPE.equals(orientation))
pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
String s = properties.getProperty(PAPER_IMAGEABLE_HEIGHT);
if (s == null)
return pageFormat;
double iHeight = Double.parseDouble(s);
s = properties.getProperty(PAPER_IMAGEABLE_WIDTH);
if (s == null)
return pageFormat;
double iWidth = Double.parseDouble(s);
s = properties.getProperty(PAPER_HEIGHT);
if (s == null)
return pageFormat;
double height = Double.parseDouble(s);
s = properties.getProperty(PAPER_WIDTH);
if (s == null)
return pageFormat;
double width = Double.parseDouble(s);
s = properties.getProperty(PAPER_IMAGEABLE_X);
if (s == null)
return pageFormat;
final double x = Double.parseDouble(s);
s = properties.getProperty(PAPER_IMAGEABLE_Y);
if (s == null)
return pageFormat;
final double y = Double.parseDouble(s);
final Paper paper = pageFormat.getPaper();
paper.setImageableArea(x, y, iWidth, iHeight);
paper.setSize(width, height);
pageFormat.setPaper(paper);
return pageFormat;
}
示例14: patchMedia
import java.awt.print.PageFormat; //导入方法依赖的package包/类
private Pageable patchMedia( Pageable pageable ){
/* OpenBook is used internally only when app uses Printable.
* This is the case when we use the values from the attribute set.
*/
Media media = (Media)reqAttrSet.get(Media.class);
OrientationRequested orientReq = (OrientationRequested)reqAttrSet.get(OrientationRequested.class);
MediaPrintableArea mpa = (MediaPrintableArea)reqAttrSet.get(MediaPrintableArea.class);
if ((orientReq != null || media != null || mpa != null) && pageable instanceof OpenBook) {
/* We could almost(!) use PrinterJob.getPageFormat() except
* here we need to start with the PageFormat from the OpenBook :
*/
Printable printable = pageable.getPrintable(0);
PageFormat pf = (PageFormat)pageable.getPageFormat(0).clone();
Paper paper = pf.getPaper();
/* If there's a media but no media printable area, we can try
* to retrieve the default value for mpa and use that.
*/
if (mpa == null && media != null && service.isAttributeCategorySupported(MediaPrintableArea.class)) {
Object mpaVals = service. getSupportedAttributeValues(MediaPrintableArea.class, null, reqAttrSet);
if (mpaVals instanceof MediaPrintableArea[] && ((MediaPrintableArea[])mpaVals).length > 0) {
mpa = ((MediaPrintableArea[])mpaVals)[0];
}
}
if (isSupportedValue(orientReq, reqAttrSet) || (!fidelity && orientReq != null)) {
int orient;
if (orientReq.equals(OrientationRequested.REVERSE_LANDSCAPE)) {
orient = PageFormat.REVERSE_LANDSCAPE;
} else if (orientReq.equals(OrientationRequested.LANDSCAPE)) {
orient = PageFormat.LANDSCAPE;
} else {
orient = PageFormat.PORTRAIT;
}
pf.setOrientation(orient);
}
if (isSupportedValue(media, reqAttrSet) || (!fidelity && media != null)) {
if (media instanceof MediaSizeName) {
MediaSizeName msn = (MediaSizeName)media;
MediaSize msz = MediaSize.getMediaSizeForName(msn);
if (msz != null) {
float paperWid = msz.getX(MediaSize.INCH) * 72.0f;
float paperHgt = msz.getY(MediaSize.INCH) * 72.0f;
paper.setSize(paperWid, paperHgt);
if (mpa == null) {
paper.setImageableArea(72.0, 72.0, paperWid-144.0, paperHgt-144.0);
}
}
}
}
if (isSupportedValue(mpa, reqAttrSet) || (!fidelity && mpa != null)) {
float [] printableArea = mpa.getPrintableArea(MediaPrintableArea.INCH);
for (int i=0; i < printableArea.length; i++) {
printableArea[i] = printableArea[i]*72.0f;
}
paper.setImageableArea(printableArea[0], printableArea[1], printableArea[2], printableArea[3]);
}
pf.setPaper(paper);
pf = validatePage(pf);
return new OpenBook(pf, printable);
}
return pageable;
}